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

Error on Ubuntu with Python 3.7 #229

Closed
Tracked by #271
ajyoon opened this issue Jul 27, 2022 · 13 comments · Fixed by #231
Closed
Tracked by #271

Error on Ubuntu with Python 3.7 #229

ajyoon opened this issue Jul 27, 2022 · 13 comments · Fixed by #231
Assignees
Labels
bug Something isn't working changelog Changes should be written to the changelog file.
Milestone

Comments

@ajyoon
Copy link

ajyoon commented Jul 27, 2022

I recently changed my project's CI from using Python 3.10 to 3.7 and unimport started failing with this error:

Traceback (most recent call last):
  File "/home/runner/work/neoscore/neoscore/.venv/bin/unimport", line 8, in <module>
    sys.exit(main())
  File "/home/runner/work/neoscore/neoscore/.venv/lib/python3.7/site-packages/unimport/main.py", line 60, in main
    utils.get_used_packages(Import.imports, unused_imports)
  File "/home/runner/work/neoscore/neoscore/.venv/lib/python3.7/site-packages/unimport/utils.py", line 102, in get_used_packages
    name = package_name_from_metadata(package)
  File "/home/runner/work/neoscore/neoscore/.venv/lib/python3.7/site-packages/unimport/utils.py", line 90, in package_name_from_metadata
    return metadata(package)["Name"]
  File "/home/runner/work/neoscore/neoscore/.venv/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 1005, in metadata
    return Distribution.from_name(distribution_name).metadata
  File "/home/runner/work/neoscore/neoscore/.venv/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 562, in from_name
    raise ValueError("A distribution name is required.")
ValueError: A distribution name is required.

I can't reproduce this on my local machine (Arch Linux with Python 3.7.13), but you can see detailed environment info on the build here.

ajyoon added a commit to DigiScore/neoscore that referenced this issue Jul 27, 2022
@ajyoon
Copy link
Author

ajyoon commented Jul 27, 2022

This is happening on unimport-0.9.6 btw, which is the same version that seems to work fine on 3.10 and in my environment.

@hakancelikdev hakancelikdev added bug Something isn't working changelog Changes should be written to the changelog file. labels Jul 28, 2022
@hakancelikdev
Copy link
Owner

Thanks for letting me know, I'll work on it as soon as possible.

@hakancelikdev
Copy link
Owner

For now, to solve your problem, I can recommend you to use pre-commit, where you can define all your linters in one place and run them with Github action.

https://pre-commit.com/
https://github.com/pre-commit/action

@ajyoon
Copy link
Author

ajyoon commented Jul 28, 2022

Thank you! I could also just put the linter check in its own action which uses 3.10, I might do that since it needs the fewest changes to my workflow.

@hakancelikdev
Copy link
Owner

I think no need, you found a nice bug, Unimport has never been used before with Github action, if you wait a few days I will fix this issue.

hakancelikdev added a commit that referenced this issue Jul 29, 2022
hakancelikdev added a commit that referenced this issue Jul 29, 2022
hakancelikdev added a commit that referenced this issue Jul 29, 2022
hakancelikdev added a commit that referenced this issue Jul 29, 2022
hakancelikdev added a commit that referenced this issue Jul 29, 2022
hakancelikdev added a commit that referenced this issue Jul 29, 2022
@hakancelikdev hakancelikdev linked a pull request Jul 29, 2022 that will close this issue
hakancelikdev added a commit that referenced this issue Jul 29, 2022
@hakancelikdev hakancelikdev reopened this Jul 29, 2022
@hakancelikdev
Copy link
Owner

I will test it.

@hakancelikdev
Copy link
Owner

Thanks for letting me know, I tested it, you can use it with GitHub action using version 0.10.0, or directly

unimport.yml

name: Unimport
on: [push, pull_request]
jobs:
   lint:
     runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v3
       - name: Set up Python3.7
          uses: actions/setup-python@v2.1.4
          with:
            python-version: '3.7'
            architecture: x64
       - name: Check unused imports
         uses: hakancelikdev/unimport@0.10.0
         with:
           extra_args: --include src/

Let's check -> https://unimport.hakancelik.dev/#use-with-github-action

@ajyoon
Copy link
Author

ajyoon commented Nov 28, 2022

Hey @hakancelikdev, in my project another user has report experiencing a similar issue locally on a Mac:

Annoyingly I cannot get pre-commit to work. I have reinstalled the poetry env for Python 3.7, 3.8, 3.9 & 3.10 and get the same error (below). This is on Mac MBP (not M1) OS12.6. Pycharm 2022.2.4.

File "/usr/local/Caskroom/miniconda/base/bin/unimport", line 10, in sys.exit(main())
File "/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/unimport/main.py", line 60, in main utils.get_used_packages(Import.imports, unused_imports)
File "/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/unimport/utils.py", line 102, in get_used_packages
name = package_name_from_metadata(package)
File "/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/unimport/utils.py", line 90, in package_name_from_metadata
return metadata(package)["Name"]
File "/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/importlib_metadata/init.py", line 1010, in metadata
return Distribution.from_name(distribution_name).metadata
File "/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/importlib_metadata/init.py", line 567, in from_name
raise ValueError("A distribution name is required.")
ValueError: A distribution name is required.

Do you think this is the same bug? Do you know of a workaround that could avoid this? Thank you!

@hakancelikdev
Copy link
Owner

@ajyoon Which version of unimport do you use?

@hakancelikdev hakancelikdev reopened this Nov 29, 2022
@ajyoon
Copy link
Author

ajyoon commented Nov 29, 2022

We're using a plain pip install unimport, so presumably this is happening on latest.

@ajyoon
Copy link
Author

ajyoon commented Nov 29, 2022

Yeah I just confirmed I'm running 0.12.2

@hakancelikdev
Copy link
Owner

@ajyoon
Copy link
Author

ajyoon commented Nov 30, 2022

Running through the pre-commit framework seems to have solved the issue for us. It's possible the the user was getting an old version of unimport from before this fix.

@hakancelikdev hakancelikdev added this to the 0.1.0 milestone Dec 5, 2022
@hakancelikdev hakancelikdev self-assigned this Dec 5, 2022
@hakancelikdev hakancelikdev mentioned this issue Dec 5, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog Changes should be written to the changelog file.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants