From b83e742fd69de2e81ee4a7b2ef52a040c16d1e68 Mon Sep 17 00:00:00 2001 From: Aniruddha Date: Fri, 12 Nov 2021 11:54:20 +0530 Subject: [PATCH 1/2] Add documentation for multiple config file support --- docs/configuration/config_files.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/configuration/config_files.md b/docs/configuration/config_files.md index 8216a7aa0..0b83d3151 100644 --- a/docs/configuration/config_files.md +++ b/docs/configuration/config_files.md @@ -87,3 +87,25 @@ This can be useful, for instance, if you want to have one configuration for `.py !!! tip Custom config files should place their configuration options inside an `[isort]` section and never a generic `[settings]` section. This is because isort can't know for sure how other tools are utilizing the config file. + + +## Supporting multiple config files in single isort run + +If you have a directory structure where different sub-directories may have their separate configuration settings and you want isort to respect these configurations, not just apply the same global configuration for the entire directory then you can do so with the `--resolve-all-configs` flag. Using the `--resolve-all-configs` along with providing the directory root as `--config-root` argument(if the config-root is not explicitly defined, then isort will consider the current directory `.` where the shell is running), isort will traverse and parse all the config files defined under the `--config-root` and dynamically decide what configurations should be applied to a specific file by choosing the nearest config file in the file's path. For instance, if your directory structure is +` +directory_root + subdir1 + .isort.cfg + file1.py + + subdir2 + pyproject.toml + file2.py + + subdir3 + file3.py + + setup.cfg +` + +isort will sort `subdir1/file1` according to the configurations defined in `subdir1/.isort.cfg`, `subdir2/file2` with configurations from `subdir2/pyproject.toml` and `subdir3/file3.py` based on the `setup.cfg` settings. \ No newline at end of file From abfb25f06a3d7603b7c8a6ea4f71c854927acf1b Mon Sep 17 00:00:00 2001 From: Aniruddha Bhattacharjee Date: Fri, 12 Nov 2021 12:02:14 +0530 Subject: [PATCH 2/2] Minor changes in the multiple-config-support file documenation --- docs/configuration/config_files.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/configuration/config_files.md b/docs/configuration/config_files.md index 0b83d3151..a78616ff1 100644 --- a/docs/configuration/config_files.md +++ b/docs/configuration/config_files.md @@ -91,9 +91,11 @@ This can be useful, for instance, if you want to have one configuration for `.py ## Supporting multiple config files in single isort run -If you have a directory structure where different sub-directories may have their separate configuration settings and you want isort to respect these configurations, not just apply the same global configuration for the entire directory then you can do so with the `--resolve-all-configs` flag. Using the `--resolve-all-configs` along with providing the directory root as `--config-root` argument(if the config-root is not explicitly defined, then isort will consider the current directory `.` where the shell is running), isort will traverse and parse all the config files defined under the `--config-root` and dynamically decide what configurations should be applied to a specific file by choosing the nearest config file in the file's path. For instance, if your directory structure is -` +If you have a directory structure where different sub-directories may have their separate configuration settings and you want isort to respect these configurations, not just apply the same global configuration for the entire directory then you can do so with the `--resolve-all-configs` flag. Using the `--resolve-all-configs` along with providing the directory root as `--config-root` argument(if the config-root is not explicitly defined, then isort will consider the current directory `.` where the shell is running), isort will traverse and parse all the config files defined under the `--config-root` and dynamically decide what configurations should be applied to a specific file by choosing the nearest config file in the file's path. For instance, if your directory structure is + +``` directory_root + subdir1 .isort.cfg file1.py @@ -106,6 +108,9 @@ directory_root file3.py setup.cfg -` +``` + +isort will sort `subdir1/file1` according to the configurations defined in `subdir1/.isort.cfg`, `subdir2/file2` with configurations from `subdir2/pyproject.toml` and `subdir3/file3.py` based on the `setup.cfg` settings. -isort will sort `subdir1/file1` according to the configurations defined in `subdir1/.isort.cfg`, `subdir2/file2` with configurations from `subdir2/pyproject.toml` and `subdir3/file3.py` based on the `setup.cfg` settings. \ No newline at end of file +!!! tip +You can always confirm exactly what config file was used for a file by running isort with the `--verbose` flag.