Skip to content

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 requested a review from ssbarnea as a code owner October 24, 2021 16:17
@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

@ziegenberg ziegenberg force-pushed the use-importlib_metadata branch from b58faee to 08cc9d5 Compare October 28, 2021 16:02
@ziegenberg ziegenberg force-pushed the use-importlib_metadata branch from 08cc9d5 to df55d5f Compare October 28, 2021 16:02
@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.

@ziegenberg ziegenberg requested a review from ssbarnea October 28, 2021 16:08
@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.

@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