Closed yajo closed 4 years ago
I think I found the problem, and it's not that there's some incompatibility.
It seems like isort doesn't properly seek for the config file in folders upper than the file passed. Check this terminal session, where I have a properly-placed .isort.cfg
file that indicates several settings (example: line_length=88
) but when I pass a direct path to a file to be reformatted, it doesn't detect that file (gets line_length=79
) unless I add --settings .
:
@Yajo isort seeks the .isort.cfg
seeks from the root directory of the file
and then the directory from where it was invoked and if both the file directory as the calling directory have a .isort.cfg
file then the cfg file in the file directory takes precedence.
Then it seems to have some kind of bug. Does it take into account a directory specifically called src
?
if "settings_path" not in arguments:
arguments["settings_path"] = (
os.path.abspath(file_names[0] if file_names else ".") or os.getcwd()
)
that's the portion of code that handles that
@Yajo I think its cool at least how I see it. But yeah I think better documentation would be good. @timothycrosley any thoughts?
Ah of course there's the problem. It should default to .
always IMHO.
Or at least that's a regression from v4, so if this is how it is now, it should get docummented in the migration guide, because previous pre-commit hooks wouldn't work as-is.
@Yajo,
I'm sorry this behaviour led to confusion. It is not a regression, but an intentional change in behaviour. I tried my best to outline this behaviour in the top of the configuration file documentation: https://pycqa.github.io/isort/docs/configuration/config_files/:
You can manually specify the settings file or path by setting --settings-path from the command-line. Otherwise, isort will traverse up to 25 parent directories until it finds a suitable config file. As soon as it finds a file, it stops looking. The config file search is done relative to the current directory if isort . or a file stream is passed in, or relative to the first path passed in if multiple paths are passed in. isort never merges config files together due to the confusion it can cause.
I also called out how this behaviour had changed in v5 and linked to that documentation from the migration guide: https://pycqa.github.io/isort/docs/upgrade_guides/5.0.0/#migrating-config-options.
Any advice on how I can better call it out? Perhaps a tip by the pre-commit section?
Thanks!
~Timothy
AFAICS I definitely did not find that but it is properly documented.
Any advice on how I can better call it out? Perhaps a tip by the pre-commit section?
Yes, and make it more relevant in the upgrading guide, like adding a header just about that.
I have this import:
Black 20.8b1 converts it to this, putting the
(
character exactly at length 88:Isort 5.5.2 converts it to this, putting the
\
character exactly at length 88:.isort.cfg: