Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Officially deprecate pkg_resources #3843

Merged
merged 2 commits into from
Mar 5, 2023
Merged

Conversation

jaraco
Copy link
Member

@jaraco jaraco commented Mar 5, 2023

Summary of changes

Closes

Pull Request Checklist

@jaraco
Copy link
Member Author

jaraco commented Mar 5, 2023

I expect this change to have minimal impact on users of Setuptools as a build tool because DeprecationWarnings are suppressed by default.

@jaraco jaraco merged commit c446a06 into main Mar 5, 2023
@jaraco jaraco deleted the debt/deprecate-pkg_resources branch March 5, 2023 21:18
mdickinson added a commit to enthought/envisage that referenced this pull request Apr 3, 2023
This PR fixes mutable-global-state-related issues with the egg-based
tests (again).

The root cause of the problems is that we're interfacing with an
ill-defined (and now
[deprecated](pypa/setuptools#3843) and
unmaintained) API in `setuptools` code, which makes those interactions
fragile, and that tests make significant changes to global state.

The immediate cause of the issues is that we were trying to undo changes
to `pkg_resources` global state by replacing the global
`pkg_resources.working_set` with a fresh `WorkingSet` object during test
teardown, but that `WorkingSet` object was missing some of the
initialization (registered callbacks) that the original `WorkingSet`
had.

The main change in this PR is to try to undo global state changes by
_mutating_ the existing `pkg_resources.working_set` back to its original
state, instead of replacing `pkg_resources.working_set`. Alongside that,
we've reorganised the relevant tests to share common machinery (now in
`envisage.tests.support`) and to make use of context managers for
cleanup.

Fixes #440 
Fixes #563 
The test suite also now runs cleanly under the `haas` test runner.
fanquake added a commit to bitcoin-core/gui that referenced this pull request Aug 29, 2023
…ith importlib.metadata

6c008a2 script: replace deprecated pkg_resources with importlib.metadata (Jon Atack)

Pull request description:

  Running our python linter with a recent python and the latest release of setuptools [v68.1.2](https://setuptools.pypa.io/en/stable/history.html):

  ```
  $ python3 --version
  Python 3.11.5
  $ ./test/lint/lint-python.py:12: DeprecationWarning: pkg_resources is deprecated as an API.
    See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources
  ```

  Using `pkg_resources` was [deprecated](pypa/setuptools#3843) earlier in [v67.5.0](https://setuptools.pypa.io/en/stable/history.html#id55): "Although pkg_resources has been discouraged for use, some projects still consider pkg_resources viable for usage. This change makes it clear that pkg_resources should not be used, emitting a DeprecationWarning when imported."

  The `importlib.metadata` library requires Python 3.8, which is currently our minimum-supported Python version.

  For more details about `importlib.metadata` and the two methods imported and used here, see:

  - https://docs.python.org/3/library/importlib.metadata.html
  - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.metadata
  - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageNotFoundError

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 6c008a2 (review only, did not test)

Tree-SHA512: f5258d37043fcc9744f85641a60a3395ad43822c72d030dea8c39fa7f48ec3d7790cdeeb832f96e8f38046adb7c62fbc577c975ef0c77c8047c0c8f2353ce540
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Sep 8, 2023
…rtlib.metadata

6c008a2 script: replace deprecated pkg_resources with importlib.metadata (Jon Atack)

Pull request description:

  Running our python linter with a recent python and the latest release of setuptools [v68.1.2](https://setuptools.pypa.io/en/stable/history.html):

  ```
  $ python3 --version
  Python 3.11.5
  $ ./test/lint/lint-python.py:12: DeprecationWarning: pkg_resources is deprecated as an API.
    See https://setuptools.pypa.io/en/latest/pkg_resources.html
    import pkg_resources
  ```

  Using `pkg_resources` was [deprecated](pypa/setuptools#3843) earlier in [v67.5.0](https://setuptools.pypa.io/en/stable/history.html#id55): "Although pkg_resources has been discouraged for use, some projects still consider pkg_resources viable for usage. This change makes it clear that pkg_resources should not be used, emitting a DeprecationWarning when imported."

  The `importlib.metadata` library requires Python 3.8, which is currently our minimum-supported Python version.

  For more details about `importlib.metadata` and the two methods imported and used here, see:

  - https://docs.python.org/3/library/importlib.metadata.html
  - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.metadata
  - https://importlib-metadata.readthedocs.io/en/latest/api.html#importlib_metadata.PackageNotFoundError

ACKs for top commit:
  MarcoFalke:
    lgtm ACK 6c008a2 (review only, did not test)

Tree-SHA512: f5258d37043fcc9744f85641a60a3395ad43822c72d030dea8c39fa7f48ec3d7790cdeeb832f96e8f38046adb7c62fbc577c975ef0c77c8047c0c8f2353ce540
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Jul 10, 2024
* Update swift from branch 'master'
  to 9c38d756e0233eaa5f9e26066756eea9ce6a11ad
  - Merge "Use entry_points for server executables"
  - Use entry_points for server executables
    
    The old [files]scripts method of specifying executable Python scripts
    triggers some legacy easy-install-like mode for editable installs,
    which relies on pkg_resources. Recent versions of setuptools (67.5.0+)
    have started emitting warnings when importing pkg_resources, which in
    turn cause quite noticeable slowdowns in process startup. This is
    particularly prominant on py312, which stopped pre-installing (an often
    older version of) setuptools in new venvs.
    
    See also:
     - python/cpython#95299
     - pypa/setuptools#3843
     - pypa/setuptools#3966
    
    Now, use [entry_points]console_scripts to specify these executables,
    which does not use pkg_resources in the generated script files.
    
    Change-Id: Ifcc8138e7b55d5b82bea0d411ec6bfcca2c77c83
openstack-mirroring pushed a commit to openstack/swift that referenced this pull request Jul 10, 2024
The old [files]scripts method of specifying executable Python scripts
triggers some legacy easy-install-like mode for editable installs,
which relies on pkg_resources. Recent versions of setuptools (67.5.0+)
have started emitting warnings when importing pkg_resources, which in
turn cause quite noticeable slowdowns in process startup. This is
particularly prominant on py312, which stopped pre-installing (an often
older version of) setuptools in new venvs.

See also:
 - python/cpython#95299
 - pypa/setuptools#3843
 - pypa/setuptools#3966

Now, use [entry_points]console_scripts to specify these executables,
which does not use pkg_resources in the generated script files.

Change-Id: Ifcc8138e7b55d5b82bea0d411ec6bfcca2c77c83
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