From 692670e2bcd0efeb7c277c7c6efccfab72e570c2 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:23:19 -0500 Subject: [PATCH 1/5] replace pkg_resources with importlib.metadata for Python 3.12, require python>=3.8 --- cli50/__init__.py | 29 ++++++++++------------------- cli50/__main__.py | 8 +++++--- setup.py | 4 ++-- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/cli50/__init__.py b/cli50/__init__.py index 2e47898..fc9734f 100644 --- a/cli50/__init__.py +++ b/cli50/__init__.py @@ -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" diff --git a/cli50/__main__.py b/cli50/__main__.py index afdd696..b62fa4e 100644 --- a/cli50/__main__.py +++ b/cli50/__main__.py @@ -6,9 +6,9 @@ import argparse import gettext import inflect +import importlib import json import os -import pkg_resources import re import requests import shlex @@ -16,6 +16,7 @@ import subprocess import textwrap import tzlocal +from packaging import version from . import __version__ @@ -35,7 +36,8 @@ TAG = "latest" # Internationalization -t = gettext.translation("cli50", pkg_resources.resource_filename("cli50", "locale"), fallback=True) +path = importlib.resources.files("cli50").joinpath("locale") +t = gettext.translation("cli50", str(path), fallback=True) t.install() @@ -61,7 +63,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 diff --git a/setup.py b/setup.py index 439aac4..f3ab9ed 100644 --- a/setup.py +++ b/setup.py @@ -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", @@ -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 ) From 330b2daaaa3c34193725a7ce3f1d768268c90627 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:48:49 -0500 Subject: [PATCH 2/5] refactored codes --- cli50/__main__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli50/__main__.py b/cli50/__main__.py index b62fa4e..d1db84c 100644 --- a/cli50/__main__.py +++ b/cli50/__main__.py @@ -6,7 +6,6 @@ import argparse import gettext import inflect -import importlib import json import os import re @@ -17,6 +16,7 @@ import textwrap import tzlocal from packaging import version +from importlib.resources import files from . import __version__ @@ -36,8 +36,7 @@ TAG = "latest" # Internationalization -path = importlib.resources.files("cli50").joinpath("locale") -t = gettext.translation("cli50", str(path), fallback=True) +t = gettext.translation("cli50", str(files("cli50").joinpath("locale")), fallback=True) t.install() From b6a21d763a332781755b5e61ca8f11a85ba39841 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:53:04 -0500 Subject: [PATCH 3/5] alphabetized imports --- cli50/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli50/__main__.py b/cli50/__main__.py index d1db84c..a6d2c39 100644 --- a/cli50/__main__.py +++ b/cli50/__main__.py @@ -15,8 +15,8 @@ import subprocess import textwrap import tzlocal -from packaging import version from importlib.resources import files +from packaging import version from . import __version__ From 3444f21b3c83647b4f17e62e2da4858d682fd054 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sun, 19 Nov 2023 00:39:19 -0500 Subject: [PATCH 4/5] bump version number --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f3ab9ed..002f049 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,6 @@ "console_scripts": ["cli50=cli50.__main__:main"] }, url="https://github.com/cs50/cli50", - version="7.4.1", + version="7.4.2", include_package_data=True ) From 68becf333238a999a9b25805248f0284204dfcf2 Mon Sep 17 00:00:00 2001 From: "David J. Malan" Date: Sat, 6 Jul 2024 06:07:24 -0400 Subject: [PATCH 5/5] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index aba1292..8ef9f7a 100644 --- a/setup.py +++ b/setup.py @@ -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 = { @@ -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 )