-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from cs50/rongxin-patch-1
Replace pkg_resources with importlib.metadata for Python 3.12
- Loading branch information
Showing
3 changed files
with
17 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
import os | ||
from pkg_resources import DistributionNotFound, get_distribution | ||
import sys | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
# https://stackoverflow.com/a/17638236/5156190 | ||
try: | ||
|
||
# Get package's distribution | ||
_dist = get_distribution("cli50") | ||
|
||
# Normalize path for cross-OS compatibility | ||
_dist_loc = os.path.normcase(_dist.location) | ||
_here = os.path.normcase(__file__) | ||
# Require Python 3.8+ | ||
if sys.version_info < (3, 8): | ||
sys.exit("You have an old version of python. Install version 3.8 or higher.") | ||
|
||
# This version is not installed, but another version is | ||
if not _here.startswith(os.path.join(_dist_loc, "cli50")): | ||
raise DistributionNotFound | ||
|
||
except DistributionNotFound: | ||
__version__ = None | ||
|
||
else: | ||
__version__ = _dist.version | ||
# Get version | ||
try: | ||
__version__ = version("cli50") | ||
except PackageNotFoundError: | ||
__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
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