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

quiet in pyproject.toml not respected when isort run from code #1461

Closed
czerus opened this issue Sep 4, 2020 · 7 comments · Fixed by #1464, hypothesis/viahtml#107 or wwade/jobrunner#63
Closed
Labels
bug Something isn't working question Further information is requested
Milestone

Comments

@czerus
Copy link

czerus commented Sep 4, 2020

Hi

I have an isort settings in pyproject.toml that looks like follow:

[tool.isort]
sections = "FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER"
line_length = 120
known_first_party = "libName"
case_sensitive = true
quiet = true

and using isort in python script (together with autopep) to format the code: isort.file(path_to_file). When isort finds that something needs to be reformatted in a file it prints: "Fixing path_to_file". So it does not respect the configuration from toml. In order to fix that I need to pass the custom Config instance to file method but this overwrites all the settings from toml. Wha is strange is that isort run from command line properly handles this quiet in toml and does not prints "Fixing...."

I am using python 3.6.8 and isort 5.5.0

@timothycrosley
Copy link
Member

timothycrosley commented Sep 4, 2020

Hi @czerus,

Thank you for the report, and I am sorry you are encountering this issue!

My initial hunch is that the most likely thing is that when you call it from the API it's not finding your configuration file. You can manually specify the file or path:

isort.file("my_file.py", settings_file="full/path/to/pyproject.toml")

Additionally, you can always override single settings just by passing them in, similar to how the CLI allows overriding similar settings:

isort.file("my_file.py", quiet=True)

Let me know if these suggestions help resolve your issue!

Thanks!

~Timothy

@timothycrosley
Copy link
Member

timothycrosley commented Sep 4, 2020

Also, if you are doing this on more than one file in your script, I recommend reusing the configuration to help improve performance:

import isort

isort_config = isort.Config(settings_file=".isort.cfg", quiet=True)

for file in files:
    isort.file(file, config=isort_config)

@timothycrosley timothycrosley added the question Further information is requested label Sep 4, 2020
@czerus
Copy link
Author

czerus commented Sep 4, 2020

Thank you for such fast reply 👍
I have used

isort.file(file, settings_file="tests/pyproject.toml")

and made sure that in debugger quiet is set to True (and any other option set in toml is visible) but the "Fixing ..." keeps appearing. So I tried this one:

isort_config = isort.Config(settings_file="tests/pyproject.toml")

and debugger shows that config.quiet is True. But when I have set the same path in isort.file() then quiet (in api.py) is False.

What works is providing the whole config that is earlier read from toml:

isort_config = isort.Config(settings_file="tests/pyproject.toml")
is_fixed_isort = isort.file(file, config=isort_config)

@timothycrosley timothycrosley added the bug Something isn't working label Sep 5, 2020
@timothycrosley timothycrosley added this to the 5.6.0 milestone Sep 5, 2020
timothycrosley added a commit that referenced this issue Sep 5, 2020
Fixed #1461: Quiet config option not respected by file API in some ci…
@timothycrosley
Copy link
Member

@czerus Thanks for all the information! I was able to isolate the cause of quiet not being skipped unless the config was predefined, and I’ve fixed it in develop. This will go out with the 5.6.0 release of isort.

Thanks!

~Timothy

@czerus
Copy link
Author

czerus commented Sep 7, 2020

Super! Glad I could help. @timothycrosley when can we expect this 5.6.0 release?

@timothycrosley
Copy link
Member

The expected release date is on or before October 1st

@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