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

Relative paths for --black-config setting #13

Open
peterjc opened this issue Aug 6, 2019 · 2 comments
Open

Relative paths for --black-config setting #13

peterjc opened this issue Aug 6, 2019 · 2 comments
Labels
bug Something isn't working question Further information is requested

Comments

@peterjc
Copy link
Owner

peterjc commented Aug 6, 2019

Consider we have a user's "global" black configuration in ~/repositories/black.toml and multiple projects under this folder, where ~/repositories/project/.flake8 contains:

[flake8]
black_config=../black.toml

Then, you might run:

cd ~/repositories/project/
flake8 tests/
cd tests/
flake8 .

Both the above should find the ~/repositories/project/.flake8 file, which will load ../black.toml as the location of the black configuration file, which should be converted relative to ~/repositories/project/.flake8 giving ~/repositories/black.toml.

However, now suppose the users does the following, where the command line setting will override any values set via the flake8 configuration files (see https://gitlab.com/pycqa/flake8/issues/560 for clarifying this):

cd ~/repositories/project/
flake8 --black-config ../black.toml tests/
cd tests/
flake8 --black-config ../../black.toml .

Here the relative paths ../black.toml and ../../black.toml should both be interpreted relative to the current directory, and both give ~/repositories/black.toml.

However, if the plugin just gets a string ../black.toml or ../../black.toml, how is it to infer the starting path (a config file location or the present directory)? i.e. How was the setting given (which config file, or was it the command line)?

Cross reference https://gitlab.com/pycqa/flake8/issues/561

If we can't tell, we could be pragmatic and just try both, and maybe give an error if both interpretations exist but are different paths?

@peterjc peterjc added bug Something isn't working question Further information is requested labels Aug 6, 2019
@peterjc
Copy link
Owner Author

peterjc commented Aug 8, 2019

There seems to be a problem with the expected flake8 solution of using normalize_paths=True https://gitlab.com/pycqa/flake8/issues/562

@peterjc
Copy link
Owner Author

peterjc commented May 18, 2020

Flake8 v3.8 changed the behaviour and a unit test now fails with:

$ flake8 --select BLK without_pyproject_toml/*.py --config=flake8_config/flake8
...
ValueError: Plugin flake8-black could not find specified black config file: --black-config ../with_pyproject_toml/pyproject.toml

The file contains black-config = ../with_pyproject_toml/pyproject.toml which is valid if resolved relative to the configuration file, but fails if resolved relative to the CWD which seems to be the new deliberate behaviour: https://gitlab.com/pycqa/flake8/-/merge_requests/363

peterjc added a commit that referenced this issue May 18, 2020
This test case seemed to work prior to flake8 v3.8,
after which paths are now resolved relative to CWD
making this test case futile:

https://gitlab.com/pycqa/flake8/-/merge_requests/363

See my issue #13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant