-
-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace most pkg_resources calls with importlib.metadata and packaging
pkg_resources is deprecated and, under some circumstances, causes import errors in Python 3.12. This commit replaces the deprecated pkg_resources functions that access distribution metadata with calls to corresponding functions from importlib.metadata (or its backport importlib_metadata) and packaging. This change will bring pyinfra more in line with modern recommendations and should resolve the errors. The change introduces a new dependency on importlib_metadata in Python versions prior to 3.10. Even though importlib.metadata was available in Python 3.8, its entry_points() function did not have the group keyword argument until 3.10, hence this commit prefers the backport until that Python version. The only remaining use of pkg_resources is the require() function, which will take more work to replace since there's no ready equivalent in any of the importlib* or packaging modules.
- Loading branch information
Showing
4 changed files
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
try: | ||
from pkg_resources import get_distribution | ||
try: | ||
from importlib_metadata import version | ||
except ImportError: | ||
from importlib.metadata import version | ||
|
||
__version__ = get_distribution("pyinfra").version | ||
__version__ = version("pyinfra") | ||
except Exception: | ||
__version__ = "unknown" |
This file contains 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