PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.47k stars 577 forks source link

isort crashes when attempting to scan setup.py from lutris #1522

Closed CartoonFan closed 4 years ago

CartoonFan commented 4 years ago

Hello! I recently ran into an issue where isort crashes while scanning setup.py from the lutris project. I didn't really understand what happened, so I figured that I would ask here. Restyler.io also runs into a similar error, so I don't think it's entirely due to my PC. Thank you and I appreciate your hard work!

My error:

$ isort setup.py
/usr/lib/python3.8/site-packages/isort/settings.py:368: UserWarning: `sections` setting includes FUTURE_LIBRARY, but no known_future_library is defined. The following known_SECTION config options are defined: .
  warn(
/usr/lib/python3.8/site-packages/isort/settings.py:368: UserWarning: `sections` setting includes DEPS, but no known_deps is defined. The following known_SECTION config options are defined: .
  warn(
Traceback (most recent call last):
  File "/usr/bin/isort", line 33, in <module>
    sys.exit(load_entry_point('isort==5.5.4', 'console_scripts', 'isort')())
  File "/usr/lib/python3.8/site-packages/isort/main.py", line 830, in main
    config = Config(**config_dict)
  File "/usr/lib/python3.8/site-packages/isort/settings.py", line 426, in __init__
    super().__init__(sources=tuple(sources), **combined_config)  # type: ignore
TypeError: __init__() got an unexpected keyword argument 'min-similarity-lines'

Restyler.io:

stdoutRestyling ["setup.py"] via "isort"
stderr/usr/local/lib/python3.8/site-packages/isort/settings.py:365: UserWarning: `sections` setting includes FUTURE_LIBRARY, but no known_future_library is defined. The following known_SECTION config options are defined: .
stderr  warn(
stderr/usr/local/lib/python3.8/site-packages/isort/settings.py:365: UserWarning: `sections` setting includes DEPS, but no known_deps is defined. The following known_SECTION config options are defined: .
stderr  warn(
stderrTraceback (most recent call last):
stderr  File "/usr/local/bin/isort", line 8, in <module>
stderr    sys.exit(main())
stderr  File "/usr/local/lib/python3.8/site-packages/isort/main.py", line 822, in main
stderr    config = Config(**config_dict)
stderr  File "/usr/local/lib/python3.8/site-packages/isort/settings.py", line 423, in __init__
stderr    super().__init__(sources=tuple(sources), **combined_config)  # type: ignore
stderrTypeError: __init__() got an unexpected keyword argument 'min-similarity-lines'
stdoutSetting status of error for de0df07
stderrWe had trouble with the isort restyler:
stderr
stderr  Exited non-zero (1) for the following paths, ["setup.py"].
stderr  Error information may be present in the stderr output above.
stderr
stderrPlease see https://github.com/timothycrosley/isort/
stderr
systemRestyler exited 20
sztamas commented 4 years ago

Hi @CartoonFan

Sorry for the confusion caused by the error message. @timothycrosley made a change in develop that will make these error messages more user-friendly, but it hasn't been released yet (https://github.com/PyCQA/isort/pull/1476).

Running the develop version of isort on lutris gives these error messages:

isort.exceptions.UnsupportedSettings: isort was provided settings that it doesn't support:

    - ignore-comments = yes  (source: '/home/sztamas/Work/lutris/.isort.cfg')
    - min-similarity-lines = 5  (source: '/home/sztamas/Work/lutris/.isort.cfg')
    - ignore-docstrings = yes  (source: '/home/sztamas/Work/lutris/.isort.cfg')
    - ignore-imports = yes  (source: '/home/sztamas/Work/lutris/.isort.cfg')

You can see a list of the configuration options isort doesn't recognize and also where these values are set. Hopefully, this improvement will make it easier to find these type of config errors in the future (when this improvement will be released).

In the meantime, you can use the error message above to fix those configuration options for lutris.

I hope this helps!

Tamas

CartoonFan commented 4 years ago

Thanks @sztamas! I was able to disable the unsupported settings and isort worked correctly. I'm kind of curious about these settings, though. Are they from an old version of isort or something?

sztamas commented 4 years ago

I was curious as well, so I tried to look them up in the isort 4 -> 5 migration guide but couldn't find them.

Me being unaware of them doesn't mean much though as I'm relatively new on the project.

Maybe @timothycrosley can share some historical info? If not then we'll probably never find out how they ended up in your codebase :)

CartoonFan commented 4 years ago

I see. When I made the pull request to remove the options from the lutris .isort.cfg file, the reviewer simply said that the options were "no longer supported on isort 5.x". I'm still curious about it, but I guess it's not a huge deal if nothing turns up. Thanks for responding to my comment, though, and I'll be listening if some new information comes up :smile: .

timothycrosley commented 4 years ago

Hi! I'm sorry you encountered these errors! The truth is isort never supported these options, however before isort 5 isort would quietly ignore them instead of alerting the user to the unsupported option. That combined with the very large number of options isort does support, and the fact they used to not be well documented in a central location, led to a lot of config files with options that never existed. I think we should probably add an additional note to the upgrade guide about this.

I hope this is helpful!

Thanks!

~Timothy

CartoonFan commented 4 years ago

Thanks for your response! I think this kind of "lore" is somewhat interesting, but I'm surprised that the options were never supported. I guess someone just decided to add it to the config file and isort just shrugged :shrug: and went along with it. Again, thanks for responding; I'm sure you're pretty busy, so I appreciate you taking the time out to answer something like this.

Jeremiah