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

Insufficient feedback and documentation for the case custom config files are used, without config options in supported section #1433

Closed
nolar opened this issue Aug 30, 2020 · 4 comments
Labels
documentation Improvements or additions to documentation question Further information is requested
Milestone

Comments

@nolar
Copy link

nolar commented Aug 30, 2020

TL;DR: Settings file is not used with --settings, --settings-file CLI options, unless it is named .isort.cfg.

Steps to reproduce:

Create these settings files:

.isort.cfg:

[settings]
line_length = 100
multi_line_output = 0
balanced_wrapping = true
combine_as_imports = true
case_sensitive = true

known_first_party = kopf

filter_files = true
skip_glob = examples/*.py

.isort-examples.py:

[settings]
line_length = 100
multi_line_output = 0
balanced_wrapping = true
combine_as_imports = true
case_sensitive = true

known_third_party = kopf

filter_files = true
skip_glob = kopf/**

They are supposed to process the source code and examples slightly differently — with the delivered package being treated as a third-party library in examples.

Run as:

$ isort examples --settings-file=.isort-examples.cfg --check --show-config | grep skip
$ isort examples --settings-file=.isort-examples.cfg --check --show-config | grep third

Actual behavior:

No globs, no third-party section.

    "skip": [
    "skip_glob": [],
    "skip_gitignore": false,
            "skip": [
            "skip_glob": [],
            "skip_gitignore": false,
    "known_third_party": [],
            "known_third_party": [],

Expected behavior:

The specified file is indeed used, with all its options.


An observation: If you move the examples' config to a directory, e.g. examples/, and name it as .isort.cfg, and run it as:

isort examples --settings=examples --check 

Then it is used as expected. So, the settings directory does work, the settings file does not.

@timothycrosley timothycrosley added question Further information is requested documentation Improvements or additions to documentation labels Aug 30, 2020
@timothycrosley
Copy link
Member

timothycrosley commented Aug 30, 2020

Hi @nolar,

Thanks for the detailed bug report! This issue is a bit nuanced, after some investigation I can confirm isort is loading your specified configuration file, it just doesn't see any configuration options to pull. The reason for this, is the blanket [settings] section only works for .isort.cfg files, as these are the only files isort can be 100% certain only contain isort settings. For configuration files with any other name, isort will look for a section named isort, tool.isort or tool:isort and pull the settings from that section, that way they can safely live alongside other tool configurations.

So, for your example, if you changed .isort-example.cfg to:

[tool.isort]
line_length = 100
multi_line_output = 0
balanced_wrapping = true
combine_as_imports = true
case_sensitive = true

known_third_party = kopf

filter_files = true
skip_glob = kopf/**

Everything should work as expected.

I think the actionable items from this ticket, for the isort project are:

  • Document the usage of custom configuration files within isort's config file documentation page listing out the supported sections.
  • Ensure that if a custom settings file is set and no configuration is found in that file, a warning is raised that links to the new documentation.
  • [Optionally] Allow [settings] to be used as a heading for any config file that ends with .isort.cfg instead of requiring that be the full file name. This will allow the config files to easily be renamed as multiples are needed.

Let me know if there are other steps you think the project can / should take.

Thanks!

~Timothy

@timothycrosley timothycrosley changed the title Explicitly defined settings file is not used Insufficient feedback and documentation for the case custom config files are used, without config options in supported section Aug 30, 2020
@nolar
Copy link
Author

nolar commented Aug 30, 2020

Indeed! Tried with [isort] section — and it worked.

Though, I decided to stay with .isort.cfg in the sub-directory: I need per-directory setup, and isort examples --settings=examples looks somewhat cleaner than isort examples --settings=.isort-examples.cfg.

Thank you anyway for this hint and fast reaction! This is a nice tool to use!

@timothycrosley timothycrosley added this to the 5.6.0 milestone Sep 3, 2020
timothycrosley added a commit that referenced this issue Sep 5, 2020
@timothycrosley
Copy link
Member

This is now implemented in development, with the warning coming live in 5.6.0 and the documentation now live at https://pycqa.github.io/isort/docs/configuration/config_files/#custom-config-files.

Thanks!

~Timothy

@timothycrosley
Copy link
Member

Update: this has just been released to PyPI in 5.6.0 release of isort: https://pycqa.github.io/isort/CHANGELOG/#560-october-7-2020

Thanks!

~Timothy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants