Skip to content

Commit

Permalink
Merge pull request #116 from cs50/rongxin-patch-1
Browse files Browse the repository at this point in the history
Replace pkg_resources with importlib.metadata for Python 3.12
  • Loading branch information
rongxin-liu authored Jul 8, 2024
2 parents 14d34fa + 68becf3 commit 8ae5e0e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
29 changes: 10 additions & 19 deletions cli50/__init__.py
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"
7 changes: 4 additions & 3 deletions cli50/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import inflect
import json
import os
import pkg_resources
import re
import requests
import shlex
import shutil
import subprocess
import textwrap
import tzlocal
from importlib.resources import files
from packaging import version

from . import __version__

Expand All @@ -35,7 +36,7 @@
TAG = "latest"

# Internationalization
t = gettext.translation("cli50", pkg_resources.resource_filename("cli50", "locale"), fallback=True)
t = gettext.translation("cli50", str(files("cli50").joinpath("locale")), fallback=True)
t.install()


Expand All @@ -61,7 +62,7 @@ def main():
# Check PyPI for newer version
if __version__ and not args["fast"]:
try:
release = max(requests.get("https://pypi.org/pypi/cli50/json").json()["releases"], key=pkg_resources.parse_version)
release = max(requests.get("https://pypi.org/pypi/cli50/json").json()["releases"], key=version.parse)
assert release <= __version__
except requests.RequestException:
pass
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development"
],
message_extractors = {
Expand All @@ -15,7 +15,7 @@
description="This is CS50 CLI, with which you can mount a directory inside of an Ubuntu container.",
long_description=open("README.md").read(),
license="GPLv3",
install_requires=["inflect", "requests", "tzlocal"],
install_requires=["inflect", "packaging", "requests", "tzlocal"],
keywords="cli50",
name="cli50",
python_requires=">=3.8",
Expand All @@ -24,6 +24,6 @@
"console_scripts": ["cli50=cli50.__main__:main"]
},
url="https://github.com/cs50/cli50",
version="7.5.1",
version="8.0.0",
include_package_data=True
)

0 comments on commit 8ae5e0e

Please sign in to comment.