-
Notifications
You must be signed in to change notification settings - Fork 445
remove logic that uses import importlib_metadata #13809
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
Draft
chojomok
wants to merge
9
commits into
main
Choose a base branch
from
mohammad/update_importlib_metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+29
−73
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e837e82
remove logic that uses import importlib_metadata
chojomok e2c6553
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok 37f07c8
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok 53135cb
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok a3cac19
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok 321e7b0
group is not a param before 3.9
chojomok 7b64179
implement a solution for < and > 3.10
chojomok fba4728
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok 1031720
Merge branch 'main' into mohammad/update_importlib_metadata
chojomok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,7 @@ | |
@callonce | ||
def get_distributions() -> t.Mapping[str, str]: | ||
"""returns the mapping from distribution name to version for all distributions in a python path""" | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
pkgs = {} | ||
for dist in importlib_metadata.distributions(): | ||
|
@@ -47,10 +44,7 @@ def get_package_distributions() -> t.Mapping[str, t.List[str]]: | |
"""a mapping of importable package names to their distribution name(s)""" | ||
global _PACKAGE_DISTRIBUTIONS | ||
if _PACKAGE_DISTRIBUTIONS is None: | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
# Prefer the official API if available, otherwise fallback to the vendored version | ||
if hasattr(importlib_metadata, "packages_distributions"): | ||
|
@@ -89,13 +83,9 @@ def get_module_distribution_versions(module_name: str) -> t.Optional[t.Tuple[str | |
|
||
|
||
@cached(maxsize=1024) | ||
def get_version_for_package(name): | ||
# type: (str) -> str | ||
def get_version_for_package(name: str) -> str: | ||
"""returns the version of a package""" | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
try: | ||
return importlib_metadata.version(name) | ||
|
@@ -149,10 +139,7 @@ def _root_module(path: Path) -> str: | |
|
||
@callonce | ||
def _package_for_root_module_mapping() -> t.Optional[t.Dict[str, Distribution]]: | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata as importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
namespaces: t.Dict[str, bool] = {} | ||
|
||
|
@@ -291,10 +278,7 @@ def _(path: str) -> bool: | |
@cached(maxsize=256) | ||
def is_distribution_available(name: str) -> bool: | ||
"""Determine if a distribution is available in the current environment.""" | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
try: | ||
importlib_metadata.distribution(name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check to see if . distribution is supported or changed from 3.8 -> 3.10 |
||
|
@@ -318,10 +302,7 @@ def _packages_distributions() -> t.Mapping[str, t.List[str]]: | |
>>> all(isinstance(dist, collections.abc.Sequence) for dist in pkgs.values()) | ||
True | ||
""" | ||
try: | ||
import importlib.metadata as importlib_metadata | ||
except ImportError: | ||
import importlib_metadata # type: ignore[no-redef] | ||
import importlib.metadata as importlib_metadata | ||
|
||
pkg_to_dist = collections.defaultdict(list) | ||
for dist in importlib_metadata.distributions(): | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
revert these changes