-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avoid the use of pkg_resources when importlib.metadata is available (#…
…799) * feat: avoid the use of pkg_resources when importlib.metadata, since pkg_resources is removed from Python 3.12 * feat: avoid the use of pkg_resources when importlib.metadata, since pkg_resources is removed from Python 3.12 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: remove flake8 errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0dd41a3
commit c286019
Showing
2 changed files
with
29 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
from pkg_resources import DistributionNotFound, get_distribution | ||
|
||
PackageNotFoundError = None | ||
DistributionNotFound = None | ||
try: | ||
__version__ = get_distribution("django-pipeline").version | ||
except DistributionNotFound: | ||
# package is not installed | ||
__version__ = None | ||
from importlib.metadata import PackageNotFoundError | ||
from importlib.metadata import version as get_version | ||
except ImportError: | ||
get_version = None | ||
PackageNotFoundError = None | ||
if get_version is None: | ||
try: | ||
from pkg_resources import DistributionNotFound, get_distribution | ||
|
||
def get_version(x): | ||
return get_distribution(x).version | ||
|
||
except ImportError: | ||
get_version = None | ||
DistributionNotFound = None | ||
get_distribution = None | ||
|
||
__version__ = None | ||
if get_version is not None: | ||
try: | ||
__version__ = get_version("django-pipeline") | ||
except PackageNotFoundError: | ||
pass | ||
except DistributionNotFound: | ||
pass |