Skip to content

Replace deprecated pkg_resources with importlib#11

Open
arthurbdiniz wants to merge 1 commit intow3c-social:masterfrom
arthurbdiniz:fix/replace-pkg-resources-with-importlib
Open

Replace deprecated pkg_resources with importlib#11
arthurbdiniz wants to merge 1 commit intow3c-social:masterfrom
arthurbdiniz:fix/replace-pkg-resources-with-importlib

Conversation

@arthurbdiniz
Copy link
Copy Markdown

Problem

pkg_resources has 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_filename with the modern standard library alternative importlib.resources.files, which is the recommended approach for accessing package resources.


Changes

  • Removed pkg_resources import
  • Added importlib.resources.files with fallback to importlib_resources for Python < 3.9
  • Updated resource file access to use the new API:
    • files('activipy').joinpath('activitystreams2-context.jsonld')
    • .read_text() instead of open().read()

Compatibility

  • Python 3.9+: Uses built-in importlib.resources
  • Python < 3.9: Falls back to importlib_resources package (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_resources as a dependency.

@arthurbdiniz arthurbdiniz force-pushed the fix/replace-pkg-resources-with-importlib branch 2 times, most recently from b839ce9 to 4e0cf23 Compare February 10, 2026 21:22
@arthurbdiniz arthurbdiniz changed the title Replace deprecated pkg_resources with importlib.resources Replace deprecated pkg_resources with importlib Feb 10, 2026
pkg_resources has been removed from Setuptools 72.0.0+.

Closes: w3c-social#12

Signed-off-by: Arthur Diniz <arthurbdiniz@gmail.com>
@arthurbdiniz arthurbdiniz force-pushed the fix/replace-pkg-resources-with-importlib branch from 4e0cf23 to c52c72f Compare February 10, 2026 21:29
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

Successfully merging this pull request may close these issues.

1 participant