diff options
author | Luca Di Sera <disera.luca@gmail.com> | 2020-08-22 13:04:56 +0200 |
---|---|---|
committer | Luca Di Sera <disera.luca@gmail.com> | 2020-08-22 13:04:56 +0200 |
commit | 3c62f89437af6d696173e6a05d5ec828bbf6ebc0 (patch) | |
tree | f03b729856c5973d61b9dff31089b57d4be5b7e9 /README.md | |
parent | ec63f343666ca18fd8efa9fad07438f996da2cf6 (diff) | |
download | isort-3c62f89437af6d696173e6a05d5ec828bbf6ebc0.tar.gz |
Extends git_hook to allow for a user-specified configuration file.
The behavior of the `git_hook` function was to search for a configuration file
by starting from the directory containing the first staged file and moving
upwards until a configuration file was found or a certain number of directories
were checked.
If the project configuration file is not stored in a directory that is a parent
to each python file in the codebase, the `git_hook` function was unable to
retrieve the file.
For example, this might happen with a configuration such as the following:
```
git-root/
config/
.isort.cfg
src/
...
```
To allow for the `git_hook` function to support those project structures without
breaking backwards compatibility, an optional argument, `settings_file`, was
added to it.
When `settings_file` is the empty string the function behaves as before.
Otherwise, `settings_file` is considered a path to a valid configuration file
that will be used for the hook's run.
A test in `tests/test_hooks.py` was added to cover for this case.
`README.md#Git hook` was modified to mention the new interface.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -556,7 +556,7 @@ include the following in `.git/hooks/pre-commit`: import sys from isort.hooks import git_hook -sys.exit(git_hook(strict=True, modify=True, lazy=True)) +sys.exit(git_hook(strict=True, modify=True, lazy=True, settings_file="")) ``` If you just want to display warnings, but allow the commit to happen @@ -569,6 +569,15 @@ Set it to `True` to ensure all tracked files are properly isorted, leave it out or set it to `False` to check only files added to your index. +If you want to use a specific configuration file for the hook, you can pass its +path to settings_file. If no path is specifically requested, `git_hook` will +search for the configuration file starting at the directory containing the first +staged file, as per `git diff-index` ordering, and going upward in the directory +structure until a valid configuration file is found or +[`MAX_CONFIG_SEARCH_DEPTH`](src/config.py:35) directories are checked. +The settings_file parameter is used to support users who keep their configuration +file in a directory that might not be a parent of all the other files. + ## Setuptools integration Upon installation, isort enables a `setuptools` command that checks |