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

Get rid of setuptools as a runtime dependency #21

Open
flying-sheep opened this issue Oct 26, 2022 · 1 comment
Open

Get rid of setuptools as a runtime dependency #21

flying-sheep opened this issue Oct 26, 2022 · 1 comment

Comments

@flying-sheep
Copy link

pkg_resources is provided by setuptools:

__version__ = pkg_resources.require("altgraph")[0].version

The stdlib’s replacement for this line would be

from importlib.metadata import version

 __version__ = version("altgraph")

If you want to be compatible with Python <3.8, you could do:

try:
    from importlib.metadata import version
except ImportError:  # Python <3.8
    from importlib_metadata import version

 __version__ = version("altgraph")

which would use this conditional dependency: importlib-metadata; python_version < '3.8'

You could also just do #12 instead. Flit sources the metadata version from a version string in __init__.py so this would just become __version__ = '0.17.4'

@tobylightheart
Copy link

This usage of pkg_resources is breaking for me in Windows. I haven't done exhaustive testing, but L144 in __init__.py was throwing "distribution was not found" errors in a clean venv in Python 3.11.8 (Windows).

Using the importlib approach resolved the error.

Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import altgraph
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Toby\_code\venv\altgraph\Lib\site-packages\altgraph\__init__.py", line 144, in <module>
    __version__ = pkg_resources.require("altgraph")[0].version
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Toby\_code\venv\altgraph\Lib\site-packages\pkg_resources\__init__.py", line 909, in require
    needed = self.resolve(parse_requirements(requirements))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Toby\_code\venv\altgraph\Lib\site-packages\pkg_resources\__init__.py", line 795, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application

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

No branches or pull requests

2 participants