diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2023-03-05 09:18:48 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2023-03-05 09:34:02 -0500 |
| commit | a1aeda391a0c462ea53627bcdf50dd4c0daadaed (patch) | |
| tree | f461174e894e7ce9ce2712fdf7631bf35d7add42 | |
| parent | f04a29aafff0778d2daf9276faf31455e6f791ac (diff) | |
| download | python-setuptools-git-a1aeda391a0c462ea53627bcdf50dd4c0daadaed.tar.gz | |
Deprecate pkg_resources, removing excuse that 'discouraged is not deprecated'.
| -rw-r--r-- | docs/pkg_resources.rst | 5 | ||||
| -rw-r--r-- | pkg_resources/__init__.py | 13 | ||||
| -rw-r--r-- | pytest.ini | 3 | ||||
| -rw-r--r-- | setuptools/tests/contexts.py | 9 |
4 files changed, 18 insertions, 12 deletions
diff --git a/docs/pkg_resources.rst b/docs/pkg_resources.rst index 40e5e6f8..fcb91b7a 100644 --- a/docs/pkg_resources.rst +++ b/docs/pkg_resources.rst @@ -11,12 +11,13 @@ subpackages, and APIs for managing Python's current "working set" of active packages. .. attention:: - Use of ``pkg_resources`` is discouraged in favor of + Use of ``pkg_resources`` is deprecated in favor of `importlib.resources <https://docs.python.org/3/library/importlib.html#module-importlib.resources>`_, `importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_, and their backports (:pypi:`importlib_resources`, :pypi:`importlib_metadata`). - Please consider using those libraries instead of pkg_resources. + Users should refrain from new usage of ``pkg_resources`` and + should work to port to importlib-based solutions. -------- diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 1eb3f9e2..e08d17f4 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -12,6 +12,12 @@ The package resource API is designed to work with normal filesystem packages, .egg files, and unpacked .egg files. It can also work in a limited way with .zip files and with custom PEP 302 loaders that support the ``get_data()`` method. + +This module is deprecated. Users are directed to +`importlib.resources <https://docs.python.org/3/library/importlib.resources.html>`_ +and +`importlib.metadata <https://docs.python.org/3/library/importlib.metadata.html>`_ +instead. """ import sys @@ -112,6 +118,9 @@ _namespace_handlers = None _namespace_packages = None +warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning) + + class PEP440Warning(RuntimeWarning): """ Used when there is an issue with a version or specifier not complying with @@ -914,9 +923,7 @@ class WorkingSet: list(map(shadow_set.add, self)) for project_name in plugin_projects: - for dist in plugin_env[project_name]: - req = [dist.as_requirement()] try: @@ -1822,7 +1829,6 @@ class ZipProvider(EggProvider): # FIXME: 'ZipProvider._extract_resource' is too complex (12) def _extract_resource(self, manager, zip_path): # noqa: C901 - if zip_path in self._index(): for name in self._index()[zip_path]: last = self._extract_resource(manager, os.path.join(zip_path, name)) @@ -1836,7 +1842,6 @@ class ZipProvider(EggProvider): '"os.rename" and "os.unlink" are not supported ' 'on this platform' ) try: - real_path = manager.get_cache_path(self.egg_name, self._parts(zip_path)) if self._is_current(real_path, zip_path): @@ -86,3 +86,6 @@ filterwarnings= # Avoid errors when testing pkg_resources.declare_namespace ignore:.*pkg_resources\.declare_namespace.*:DeprecationWarning + + # suppress known deprecation + ignore:pkg_resources is deprecated:DeprecationWarning diff --git a/setuptools/tests/contexts.py b/setuptools/tests/contexts.py index 7ddbc780..112cdf4b 100644 --- a/setuptools/tests/contexts.py +++ b/setuptools/tests/contexts.py @@ -6,7 +6,6 @@ import contextlib import site import io -import pkg_resources from filelock import FileLock @@ -28,11 +27,7 @@ def environment(**replacements): In a context, patch the environment with replacements. Pass None values to clear the values. """ - saved = dict( - (key, os.environ[key]) - for key in replacements - if key in os.environ - ) + saved = dict((key, os.environ[key]) for key in replacements if key in os.environ) # remove values that are null remove = (key for (key, value) in replacements.items() if value is None) @@ -81,6 +76,8 @@ def save_user_site_setting(): @contextlib.contextmanager def save_pkg_resources_state(): + import pkg_resources + pr_state = pkg_resources.__getstate__() # also save sys.path sys_path = sys.path[:] |
