Replace deprecated pkg_resources with importlib#11
Open
arthurbdiniz wants to merge 1 commit intow3c-social:masterfrom
Open
Replace deprecated pkg_resources with importlib#11arthurbdiniz wants to merge 1 commit intow3c-social:masterfrom
arthurbdiniz wants to merge 1 commit intow3c-social:masterfrom
Conversation
b839ce9 to
4e0cf23
Compare
pkg_resources has been removed from Setuptools 72.0.0+. Closes: w3c-social#12 Signed-off-by: Arthur Diniz <arthurbdiniz@gmail.com>
4e0cf23 to
c52c72f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pkg_resourceshas been removed from Setuptools 72.0.0+ (see setuptools#3085), causing import errors in environments with newer Setuptools versions.Solution
This PR replaces the deprecated
pkg_resources.resource_filenamewith the modern standard library alternativeimportlib.resources.files, which is the recommended approach for accessing package resources.Changes
pkg_resourcesimportimportlib.resources.fileswith fallback toimportlib_resourcesforPython < 3.9files('activipy').joinpath('activitystreams2-context.jsonld').read_text()instead ofopen().read()Compatibility
importlib.resourcesimportlib_resourcespackage (needs to be added as a dependency)Testing
Existing tests pass with the new implementation.
The change is a drop-in replacement with no functional differences.
Note
Projects using this library with Python < 3.9 will need to install
importlib_resourcesas a dependency.