forked from fedora-copr/copr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli, rpmbuild, common: replace deprecated pkg_resources with importli…
…b.metadata Fix fedora-copr#2674 Fix fedora-copr#3349
- Loading branch information
Showing
6 changed files
with
87 additions
and
12 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
A compatibility layer between already deprecated things from Rawhide and not | ||
yet available replacements in old EPELs | ||
""" | ||
|
||
|
||
def package_version(name): | ||
""" | ||
Return version of a given Python package | ||
The `importlib.metadata` module was introduced in Python 3.8 while | ||
EPEL 8 has Python 3.6. At the same time, `pkg_resources` is deprecated | ||
since Python 3.12 (Fedora 40): | ||
""" | ||
# pylint: disable=import-outside-toplevel | ||
try: | ||
from importlib.metadata import distribution, PackageNotFoundError | ||
try: | ||
return distribution(name).version | ||
except PackageNotFoundError: | ||
return "git" | ||
except ImportError: | ||
import pkg_resources | ||
try: | ||
return pkg_resources.require(name)[0].version | ||
except pkg_resources.DistributionNotFound: | ||
return "git" |
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