hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.
https://pypi.org/project/autopep8/
MIT License
4.56k stars 290 forks source link

Precedence of excluding vs. including files #246

Open tedmiston opened 8 years ago

tedmiston commented 8 years ago

In trying to help answer someone's question on Stack Overflow, I came across what may be a bug, or perhaps just something that's unclear to me.

The full details are here on SO, but I've copied below for your convenience.

Also here are the details requested in the contributor guidelines:

$ autopep8 --version
autopep8 1.2.4

$ pep8 --version
1.7.0

$ python --version
Python 2.7.11

$ uname -a
Darwin <my machine name> 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

To create this setup, I simply ran mktmpenv followed by pip install autopep8.

This style to avoid specific files works for me (using either single or double quotes):

autopep8 --diff --recursive --exclude="*.styl" .

This also works:

autopep8 --diff --exclude="*.styl" *.py

However this does not exclude .styl files:

autopep8 --diff --exclude="*.styl" *

In my opinion, it appears [OP has] identified a bug in autopep8.

However, perhaps it's not a bug, but rather an opinionated decision that star inclusion should take precedence over star exclusion.

In other words, is running this command intended to process (a) all files, or (b) no files?

autopep8 --diff --exclude="*" *
myint commented 8 years ago

I think I originally meant for --exclude to be used with --recursive only. But I see how this might be unintuitive. In any case, pep8/pycodestyle does things the way you and the Stack Overflow question expects. So I think it would make sense to fix this. At the very least, this would make our tools match in behavior.

Thanks

tedmiston commented 8 years ago

Thanks so much for the clarification. Admittedly an edge case, but I appreciate taking the time to address it. Thank you!

fpuga commented 7 years ago

I fall into this case also. Just for the record, to launch the tool only against .py files I execute the tool two times in this way:

autopep8 --diff --recursive **/*.py
autopep8 --diff --recursive *.py