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 3befc8f commit ef9b056
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion setup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
entry_points={
"console_scripts": ["submit50=submit50.__main__:main"]
},
version="3.1.2",
version="3.1.3",
include_package_data=True
)
17 changes: 4 additions & 13 deletions submit50/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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")
23 changes: 12 additions & 11 deletions submit50/__main__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import enum
import gettext
import logging
import pkg_resources
import re
import shutil
import sys
Expand All @@ -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"

Expand Down Expand Up @@ -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. "
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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")
)

Expand Down

0 comments on commit ef9b056

Please sign in to comment.