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

Crashes if isort isn't installed #130

Closed
akaihola opened this issue May 3, 2021 · 6 comments · Fixed by #132
Closed

Crashes if isort isn't installed #130

akaihola opened this issue May 3, 2021 · 6 comments · Fixed by #132
Assignees
Labels
bug Something isn't working
Milestone

Comments

@akaihola
Copy link
Owner

akaihola commented May 3, 2021

conda-forge/darker-feedstock#1 fails with this error (in the Linux and OSX builds):

+ darker --help
Traceback (most recent call last):
  File "/home/conda/feedstock_root/build_artifacts/darker_1619998672207/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/bin/darker", line 7, in <module>
    from darker.__main__ import main
  File "/home/conda/feedstock_root/build_artifacts/darker_1619998672207/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/lib/python3.9/site-packages/darker/__main__.py", line 16, in <module>
    from darker.import_sorting import apply_isort, isort
  File "/home/conda/feedstock_root/build_artifacts/darker_1619998672207/_test_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold/lib/python3.9/site-packages/darker/import_sorting.py", line 22, in <module>
    isort_code = getattr(isort, "code")
AttributeError: 'NoneType' object has no attribute 'code'
@akaihola akaihola self-assigned this May 3, 2021
@akaihola akaihola added the bug Something isn't working label May 3, 2021
@akaihola
Copy link
Owner Author

akaihola commented May 3, 2021

@martinRenou, I'm taking a look at this now.

@akaihola
Copy link
Owner Author

akaihola commented May 3, 2021

This is reproducible in any environment:

$ pip uninstall -y isort
$ darker --help
Traceback (most recent call last):
  File "bin/darker", line 33, in <module>
    sys.exit(load_entry_point('darker', 'console_scripts', 'darker')())
  File "bin/darker", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "darker/__main__.py", line 16, in <module>
    from darker.import_sorting import apply_isort, isort
  File "darker/import_sorting.py", line 22, in <module>
    isort_code = getattr(isort, "code")
AttributeError: 'NoneType' object has no attribute 'code'

@akaihola akaihola changed the title Conda build for 1.2.3 fails Crash if isort isn't installed May 3, 2021
@martinRenou
Copy link
Collaborator

I am fixing the conda package by adding a dependency on isort: conda-forge/darker-feedstock#2

What do you think? Do you think we should do the same in your setup.py file so that pip picks it up as well?

@akaihola
Copy link
Owner Author

akaihola commented May 3, 2021

@martinRenou, isort is an optional dependency which is required only when darker --isort is used. You can install darker with isort by doing pip install 'darker[isort]' (or, from a local source tree, pip install '.[isort]'.

@martinRenou
Copy link
Collaborator

I see.

So having the isort dependency would temporarily fix the conda package for 1.2.3, but I guess we should remove it once the bug is fixed?

@akaihola akaihola changed the title Crash if isort isn't installed Crashes if isort isn't installed May 3, 2021
@akaihola akaihola added this to the 1.2.4 milestone May 3, 2021
@akaihola
Copy link
Owner Author

akaihola commented May 3, 2021

@martinRenou, when running the test suite, isort should always be installed.

There are specific tests which mock sys.modules and remove isort temporarily to check that all functionality (besides --isort) still would works if isort wasn't installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants