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

ImportError: cannot import name 'LegacyVersion' from 'packaging.version' #3171

Closed
soimkim opened this issue Dec 8, 2022 · 14 comments · Fixed by fosslight/fosslight_source_scanner#103
Labels

Comments

@soimkim
Copy link
Contributor

soimkim commented Dec 8, 2022

Description

Please leave a brief description of the bug or feature request:

  • packaging 22.0 released.
  • As a result, the following error occurs when importing ScanCode.
========================================================================
ERROR: UNABLE TO IMPORT SCANCODE PLUGINS.
Check your installation configuration (setup.py) or re-install/re-configure ScanCode.
The following plugin(s) are referenced and cannot be loaded/imported:
cannot import name 'LegacyVersion' from 'packaging.version' (/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/packaging/version.py)
========================================================================
File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/fosslight_source/run_scancode.py", line 11, in <module>
    from scancode import cli
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/scancode/cli.py", line 126, in <module>
    raise e
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/scancode/cli.py", line 113, in <module>
    plugin_classes, plugin_options = PluginManager.load_plugins()
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/plugincode/__init__.py", line 196, in load_plugins
    mgr_setup = manager.setup()
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/plugincode/__init__.py", line 222, in setup
    raise e
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/plugincode/__init__.py", line 220, in setup
    self.manager.load_setuptools_entrypoints(entrypoint)
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/packagedcode/__init__.py", line 23, in <module>
    from packagedcode import conda
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/packagedcode/conda.py", line 16, in <module>
    from packagedcode.pypi import BaseDependencyFileHandler
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/packagedcode/pypi.py", line 28, in <module>
    import pip_requirements_parser
  File "/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/pip_requirements_parser.py", line 73, in <module>
    from packaging.version import LegacyVersion
ImportError: cannot import name 'LegacyVersion' from 'packaging.version' (/home/worker/git/fosslight_source_scanner/.tox/release/lib/python3.8/site-packages/packaging/version.py)
release: exit 1 (0.80 seconds) /home/worker/git/fosslight_source_scanner> fosslight_source -h pid=1095
.pkg: _exit> python /home/worker/venv38/lib/python3.8/site-packages/pyproject_api/_backend.py True setuptools.build_meta __legacy__
  release: FAIL code 1 (2.30=setup[1.50]+cmd[0.80] seconds)
  evaluation failed :( (2.35 seconds)
 

How To Reproduce

Tell us how to reproduce the issue.

  • Install ScanCode with packaging version 22.0 (latest version).

System configuration

For bug reports, it really helps us to know:

  • What OS are you running on? Ubuntu
  • What version of scancode-toolkit was used to generate the scan file? 31.2.1
  • What installation method was used to install/run scancode? pip
@pombredanne
Copy link
Member

pombredanne commented Dec 8, 2022

@soimkim Thanks for the report.... This likely the same as nexB/pip-requirements-parser#10 which is breaking many other tools that reuse our requirements parser and is because of the pypa core packaging library new release 22.0

@danielthieleog
Copy link

The change in packaging: pypa/packaging#407

@pombredanne
Copy link
Member

I pushed an emergency v32.0 of pip-requirements-parser to PyPI with nexB/pip-requirements-parser#12 .... @soimkim @danielthieleog can you test this in your context? this would be super helpful!
Thank you!

@danielthieleog
Copy link

@pombredanne , thank you, the error disappeared

@Jeeppler
Copy link

I am having the same issue. I am unable to install Scancode 31.2.1 via pip.

  • How to apply a fix for this issue?
  • Will there be a new Scancode version which includes the fix?

@pombredanne
Copy link
Member

@Jeeppler I will push a new emergency fix. Breaking API changes in the core packaging library are the culprit. I guess we should vendor it.

@Jeeppler
Copy link

@pombredanne thanks for taking care of it.

@pombredanne
Copy link
Member

@AyanSinhaMahapatra and I pushed a new version of pip-requirements-parser that solves this issue. It works with the "packaging" v21 and v22 equally well, by vendoring the LegacyVersion.
Thank you all for your patience!

@pombredanne
Copy link
Member

Testing mucho welcomed before we close this!

pombredanne added a commit that referenced this issue Dec 21, 2022
Reference: #3177
Reference: #3171
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
pombredanne added a commit that referenced this issue Dec 21, 2022
Reference: #3177
Reference: #3171
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne
Copy link
Member

This packaging issue never stops on giving :]
The automated release script also fails, because it somehow depends on legacyversion indirectly (because some of versions of packages on PyPI are legacyversion) https://github.com/nexB/scancode-toolkit/actions/runs/3752945050/jobs/6375800388
I will need to push yet another dot release tomorrow

@pombredanne
Copy link
Member

For info the upstream issue is at pypa/packaging#530
I am ending with a fork of packaging at https://github.com/nexB/packaging2 and https://pypi.org/project/packaging2/ for now.

@pombredanne
Copy link
Member

@0xc0170 FYI

pombredanne added a commit that referenced this issue Dec 23, 2022
* Switch to using packvers fork of packaging
* Bump pip requirements parser, but it still using packaging.
* Bump dparse2 which is using packvers
* Pin SPDX tools for cope with breaking APIs
* Update release script to build one release wheel for each Python
  version that each contain a pickle of the License index
* Streamline the app build
* Bump version and use correct SPDX version

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
pombredanne added a commit that referenced this issue Dec 23, 2022
* Switch to using packvers fork of packaging
* Bump pip requirements parser, but it still using packaging.
* Bump dparse2 which is using packvers
* Pin SPDX tools for cope with breaking APIs
* Update release script to build one release wheel for each Python
  version that each contain a pickle of the License index
* Streamline the app build
* Bump version and use correct SPDX version

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@AyanSinhaMahapatra
Copy link
Member

@soimkim this should be fixed in scancode-toolkit 31.2.3 which was released, please give it a try!

@soimkim
Copy link
Contributor Author

soimkim commented Dec 23, 2022

@AyanSinhaMahapatra , fixed in version 31.2.3.
@AyanSinhaMahapatra , @pombredanne , thanks for the quick fix! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants