-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Misc.} Remove pkg_resources
#31616
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
{Misc.} Remove pkg_resources
#31616
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import pkg_resources | ||
| pkg_resources.declare_namespace(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it declares namespace package. This does not look like a namespace package at all.
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| import pkg_resources | ||
| pkg_resources.declare_namespace(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc\sphinx\ folder appears related to documentation generation but hasn't been updated in a long time.
Confirmed with doc team, they only use doc\sphinx\azhelpgen\doc_source_map.json
| import logging | ||
| import unittest | ||
| from pkg_resources import working_set | ||
| from importlib.metadata import distributions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def distributions(**kwargs):
"""Get all ``Distribution`` instances in the current environment.
:return: An iterable of ``Distribution`` instances.
"""
return Distribution.discover(**kwargs)
Distribution doc: https://docs.python.org/3/library/importlib.metadata.html#distributions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importlib.metadata.distributions is not even documented by https://docs.python.org/3.15/library/importlib.metadata.html
| expected_modules = set([n for n, _ in automation_path.get_command_modules_paths(include_prefix=True)]) | ||
|
|
||
| installed_command_modules = [dist.key for dist in list(working_set) if dist.key.startswith(COMMAND_MODULE_PREFIX)] | ||
| installed_command_modules = [dist.metadata['Name'] for dist in distributions() if dist.metadata['Name'].startswith(COMMAND_MODULE_PREFIX)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dist's type is importlib.metadata.PathDistribution, but this class is not documented by https://docs.python.org/3.15/library/importlib.metadata.html either.
Another way to access the name of the distribution is dist.name. Actually, importlib.metadata.Distribution.name is defined as
@property
def name(self):
"""Return the 'Name' metadata for the distribution package."""
return self.metadata['Name']|
After this PR, there is no need to install I'm unsure if any extensions still depend on it. |
Description
pkg_resourcesis deprecated and importing it in setuptools 80.9.0 raises this warning:This PR removes its usage.
Related issue: #31591