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

Replace pkg_resources with importlib.metadata #144

Merged
merged 2 commits into from
Nov 2, 2021

Conversation

ziegenberg
Copy link
Collaborator

@ziegenberg ziegenberg commented Oct 24, 2021

The documentation of pkg_resources suggests that the use of pkg_resources is discouraged in favour of importlib.resources, importlib.metadata and their backports as pkg_resources is older and less efficient. See also: https://docs.python.org/3/library/importlib.metadata.html

Removes also one unused function attrs().

@ziegenberg ziegenberg added the bug This issue/PR relates to a bug. label Oct 28, 2021
@ziegenberg ziegenberg force-pushed the use-importlib_metadata branch 3 times, most recently from 1822a4e to b58faee Compare October 28, 2021 14:39
@ssbarnea ssbarnea changed the title drop less efficient pkg_resources in favour of importlib.metadata Replace pkg_resources with importlib.metadata Oct 28, 2021
Copy link
Member

@ssbarnea ssbarnea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed to update requirements for older version of python.

Almost for sure you are missing something like https://github.com/ansible-community/molecule/blob/main/setup.cfg#L68

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
@ziegenberg
Copy link
Collaborator Author

I've rebased onto the current main. And I changed the way importlib.metadata is imported:

if sys.version_info >= (3, 8):
    from importlib.metadata import version
else:
    from importlib_metadata import version

This should now work with the automated package discovery of setuptools.

@ssbarnea
Copy link
Member

I think you misunderstood, our package manifest does not list importlib-metadata as a dependency for older versions of python, something that is a bug, a bug introduced by this change.

Look at my link from initial comment, it is an example of how to define that conditional dependency.

Probably our test pipelines do not fail only by chance, as another packages already installed importlib_metadata. Still, if we import it from our code it must be listed as a direct dependency.

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
@ziegenberg
Copy link
Collaborator Author

Sorry, I mixed up automatic package discovery and dependencies management. Should be fixed now.

@ssbarnea ssbarnea merged commit 5c57b65 into pycontribs:main Nov 2, 2021
@ziegenberg ziegenberg deleted the use-importlib_metadata branch November 2, 2021 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants