From ef9b05602bc6534d94615ab62697c910f931cc43 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:36:03 -0500 Subject: [PATCH 1/4] replace pkg_resources with importlib.metadata for Python 3.12, require python>=3.8 --- setup.py | 2 +- submit50/__init__.py | 17 ++++------------- submit50/__main__.py | 23 ++++++++++++----------- 3 files changed, 17 insertions(+), 25 deletions(-) mode change 100644 => 100755 setup.py mode change 100644 => 100755 submit50/__init__.py mode change 100644 => 100755 submit50/__main__.py diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index e125a6c..c98e932 --- a/setup.py +++ b/setup.py @@ -26,6 +26,6 @@ entry_points={ "console_scripts": ["submit50=submit50.__main__:main"] }, - version="3.1.2", + version="3.1.3", include_package_data=True ) diff --git a/submit50/__init__.py b/submit50/__init__.py old mode 100644 new mode 100755 index c2bfa22..af841cc --- a/submit50/__init__.py +++ b/submit50/__init__.py @@ -1,19 +1,10 @@ -from pkg_resources import get_distribution, DistributionNotFound +from importlib.metadata import PackageNotFoundError, version import os -# https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package try: - _dist = get_distribution("submit50") - # Normalize path for cross-OS compatibility. - _dist_loc = os.path.normcase(_dist.location) - _here = os.path.normcase(__file__) - if not _here.startswith(os.path.join(_dist_loc, "submit50")): - # This version is not installed, but another version is. - raise DistributionNotFound -except DistributionNotFound: - __version__ = "locally installed, no version information available" -else: - __version__ = _dist.version + __version__ = version("submit50") +except PackageNotFoundError: + __version__ = "UNKNOWN" CONFIG_LOADER = __import__("lib50").config.Loader("submit50") CONFIG_LOADER.scope("files", "include", "exclude", "require") diff --git a/submit50/__main__.py b/submit50/__main__.py old mode 100644 new mode 100755 index 5665505..85c443d --- a/submit50/__main__.py +++ b/submit50/__main__.py @@ -3,7 +3,6 @@ import enum import gettext import logging -import pkg_resources import re import shutil import sys @@ -14,10 +13,12 @@ import requests import termcolor +from packaging import version +from importlib.resources import files from . import __version__, CONFIG_LOADER # Internationalization -gettext.install("submit50", pkg_resources.resource_filename("submit50", "locale")) +gettext.install("submit50", files("submit50").joinpath("locale")) SUBMIT_URL = "https://submit.cs50.io" @@ -65,8 +66,8 @@ def check_version(): "Please visit our status page https://cs50.statuspage.io for more information.")) # Check that latest version == version installed - required_version = pkg_resources.parse_version(res.text.strip()) - local_version = pkg_resources.parse_version(__version__) + required_version = version.parse(res.text.strip()) + local_version = version.parse(__version__) if required_version > local_version: raise Error(_("You have an outdated version of submit50. " @@ -126,7 +127,7 @@ def prompt(honesty, included, excluded): # If there's no honesty question, continue. if not honesty: return True - + # Prompt for honesty try: # Show default message @@ -138,17 +139,17 @@ def prompt(honesty, included, excluded): # If a custom message is configured, show that instead else: honesty_question = str(honesty) - + # Get the user's answer answer = input(honesty_question) except EOFError: answer = None print() - + # If no answer given, or yes is not given, don't continue if not answer or not re.match(f"^\s*(?:{_('y|yes')})\s*$", answer, re.I): return False - + # Otherwise, do continue return True @@ -199,12 +200,12 @@ def main(): '\ndebug: adds the output of all commands run.') ) parser.add_argument( - "-V", "--version", - action="version", + "-V", "--version", + action="version", version=f"%(prog)s {__version__}" ) parser.add_argument( - "slug", + "slug", help=_("prescribed identifier of work to submit") ) From 2d4f7dd6dc73732df6599ea44bd4c3980e8a79cc Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:43:54 -0500 Subject: [PATCH 2/4] required packaging --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c98e932..09fbafc 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ }, description="This is submit50, with which you can submit solutions to problems for CS50.", long_description="This is submit50, with which you can submit solutions to problems for CS50.", - install_requires=["lib50>=3,<4", "requests>=2.19", "setuptools", "termcolor>=1.1"], + install_requires=["lib50>=3,<4", "packaging", "requests>=2.19", "setuptools", "termcolor>=1.1"], keywords=["submit", "submit50"], name="submit50", python_requires=">=3.6", From 1487a9205ef9aca5b924fbf89f1de3a1b731f452 Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:49:44 -0500 Subject: [PATCH 3/4] stringify file path --- submit50/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submit50/__main__.py b/submit50/__main__.py index 85c443d..b08c4b4 100755 --- a/submit50/__main__.py +++ b/submit50/__main__.py @@ -18,7 +18,7 @@ from . import __version__, CONFIG_LOADER # Internationalization -gettext.install("submit50", files("submit50").joinpath("locale")) +gettext.install("submit50", str(files("submit50").joinpath("locale"))) SUBMIT_URL = "https://submit.cs50.io" From d550e3d59cc3596d216c6153ec846438138e991d Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Sat, 18 Nov 2023 23:52:38 -0500 Subject: [PATCH 4/4] alphabetized imports --- submit50/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/submit50/__main__.py b/submit50/__main__.py index b08c4b4..5db6a33 100755 --- a/submit50/__main__.py +++ b/submit50/__main__.py @@ -13,8 +13,8 @@ import requests import termcolor -from packaging import version from importlib.resources import files +from packaging import version from . import __version__, CONFIG_LOADER # Internationalization