Skip to content

pkg_resources is deprecated #3731

@luhn

Description

@luhn

As of setuptools v67.5.0, a deprecation warning is raised when importing pkg_resources:

DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

Apparently this has been replaced by importlib.resources and importlib.metadata, which is available since Python 3.7, as well as packaging.

This may be fairly tricky to remove, as src/pyramid/config/assets.py digs pretty deep into the pkg_resources API, namely it registers PackageOverrides with pkg_resources.register_loader_type. However I can't figure out why this call is necessary, I can't find where this loader would be used—Maybe something to do with AssetResolver?

The other issue is that pkg_resources would unzip the whole package into a tmp directory when calling resource_filename, whereas importlib just extracts that single file. pyramid.path.package_path depends on this behavior. Possible solutions:

  • Deprecate pyramid.path.package_path, and by extension pramid.path.caller_path, pyramid.asset.asset_spec_from_abspath, and pyramid.resource.resource_path_from_abspath.
  • Change contract so pyramid.path.package_path and it's dependents don't work with zip files (or returning zip "path")
  • Write an implementation that extracts package to tmp directory, mimicking pkg_resources behaviior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions