Skip to content

Commit

Permalink
replace pkg_resources with importlib.metadata for Python 3.12, requir…
Browse files Browse the repository at this point in the history
…e python>=3.8
  • Loading branch information
rongxin-liu committed Nov 19, 2023
1 parent a420ffe commit 3f48c04
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cli50/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import os
from pkg_resources import DistributionNotFound, get_distribution
import sys
from importlib.metadata import PackageNotFoundError, version

# https://stackoverflow.com/a/17638236/5156190
# 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.")

# Get version
try:

# Get package's distribution
_dist = get_distribution("cli50")
_dist = version("cli50")

# Normalize path for cross-OS compatibility
_dist_loc = os.path.normcase(_dist.location)
_here = os.path.normcase(__file__)

# This version is not installed, but another version is
if not _here.startswith(os.path.join(_dist_loc, "cli50")):
raise DistributionNotFound
raise PackageNotFoundError

except DistributionNotFound:
except PackageNotFoundError:
__version__ = None

else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"console_scripts": ["cli50=cli50.__main__:main"]
},
url="https://github.com/cs50/cli50",
version="7.4.0",
version="7.4.1",
include_package_data=True
)

0 comments on commit 3f48c04

Please sign in to comment.