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

Support for top-level user configuration #1899

Merged
merged 6 commits into from
Apr 1, 2021
Merged

Support for top-level user configuration #1899

merged 6 commits into from
Apr 1, 2021

Conversation

rharish101
Copy link
Contributor

@rharish101 rharish101 commented Jan 2, 2021

This should resolve #1577. At the user level, a TOML config can now be specified with the following paths (not directories, but paths to the TOML file):

  • Windows: ~\.black
  • Unix-like: $XDG_CONFIG_HOME/black (~/.config/black if XDG_CONFIG_HOME is not set)

These locations are searched only when no configuration in the current project directory is found. I chose these defaults because this is how flake8 and pycodestyle specify their user-level configs.

TODOs:

  • Fix existing tests: Running python -m unittest results in failed tests if there's a top-level user config, but all of them pass otherwise.
  • Fix black-primer: Same as above, but with black-primer.
  • Add new tests.
  • Add documentation: README, website, etc.

@rharish101
Copy link
Contributor Author

rharish101 commented Jan 22, 2021

Currently I've patched black-primer to use the work path as XDG_CONFIG_HOME, which basically switches off the top-level user config search. However, the Windows path cannot be configured. This means that black-primer will fail when run locally on Windows if the user has setup a top-level user config. Any advice on how I should go about fixing this?

Also, what's up with the Fuzz tests? Given that GitHub Actions wouldn't be having a top-level user config for Black, my changes shouldn't affect them. However, it seems that they're failing randomly.

@rharish101 rharish101 marked this pull request as ready for review January 22, 2021 11:13
@rharish101 rharish101 changed the title WIP: Support for top-level user configuration Support for top-level user configuration Jan 22, 2021
At the user level, a TOML config can be specified in the following locations:
* Windows: ~\.black
* Unix-like: $XDG_CONFIG_HOME/black (~/.config/black fallback)
Made those tests use the empty TOML config.
@rharish101
Copy link
Contributor Author

I've now cleaned up the git commit history for easy reviewing.

@ichard26 ichard26 self-requested a review February 16, 2021 20:52
Instead of changing env vars for the entire black-primer process, they
are now changed only for the black subprocess, using a tmpdir.
@rharish101
Copy link
Contributor Author

Currently I've patched black-primer to use the work path as XDG_CONFIG_HOME, which basically switches off the top-level user config search. However, the Windows path cannot be configured. This means that black-primer will fail when run locally on Windows if the user has setup a top-level user config. Any advice on how I should go about fixing this?

Solved this by overriding the USERPROFILE environment variable. Python (specifically os.path and pathlib) uses this to determine the home directory on Windows. Therefore, manipulating this helped me hide the actual home directory and thus a possible top-level user config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: configuration CLI and configuration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search for pyproject.toml to user root regardless of .git presence
3 participants