Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --exclude-base-dir, defaults to the pyproject.toml directory #631

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ideasman42
Copy link

@ideasman42 ideasman42 commented Apr 20, 2022

Add --exclude-base-dir which defaults to the location of pyproject.toml so that
exclude paths are always made relative to this path.


For some context:

Currently there is a problem where the exclude directories listed in pyproject.toml are compared against paths which depend on the command line input given.

I ran into this when attempting to use autopep8 to format all source files in a project and noticed that:

autopep8 .

Worked, while:

autopep8 $PWD

Failed to exclude directories.

This isn't a problem when executing from the command line however IDE's may pass in full paths which then fail to match the paths in the exclude list. Checking vscode, it's passing full paths to autopep8 by default (for example).

The problem is that when the full directory is passed in, this then expands to an absolute path that doesn't match the paths in the pyproject.toml which are relative to that file

This PR sets exclude-base-dir to the base directory of the pyproject.toml, so exclude checks first make paths relative to this directory before matching. The "." is added at the beginning of paths not to break compatibility with anyone already depending on the current behavior of autopep8 ..

Note that I'm not so keen on exposing --exclude-base-dir as a user visible argument, this could be a global instead.

@ideasman42 ideasman42 force-pushed the pr-pyproject-relative-exclude branch 4 times, most recently from 7a7a757 to 44fb5a0 Compare April 20, 2022 10:24
@ideasman42 ideasman42 force-pushed the pr-pyproject-relative-exclude branch from 44fb5a0 to a157e64 Compare April 20, 2022 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant