Skip to content

Commit

Permalink
Merge pull request #322 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 Nov 19, 2023
2 parents 941d0e3 + 64b36f2 commit c9d3d2e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
20 changes: 6 additions & 14 deletions check50/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
def _set_version():
"""Set check50 __version__"""
global __version__
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("check50")
# 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, "check50")):
# 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("check50")
except PackageNotFoundError:
__version__ = "UNKNOWN"


def _setup_translation():
import gettext
from pkg_resources import resource_filename
from importlib.resources import files
global _translation
_translation = gettext.translation(
"check50", resource_filename("check50", "locale"), fallback=True)
"check50", str(files("check50").joinpath("locale")), fallback=True)
_translation.install()


Expand Down
5 changes: 3 additions & 2 deletions check50/renderer/_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import pathlib

import jinja2
import pkg_resources
import termcolor

TEMPLATES = pathlib.Path(pkg_resources.resource_filename("check50.renderer", "templates"))
from importlib.resources import files

TEMPLATES = pathlib.Path(files("check50.renderer").joinpath("templates"))


def to_html(slug, results, version):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
message_extractors = {
'check50': [('**.py', 'python', None),],
},
install_requires=["attrs>=18", "beautifulsoup4>=0", "pexpect>=4.6", "lib50>=3,<4", "pyyaml>6,<7", "requests>=2.19", "setuptools", "termcolor>=1.1", "jinja2>=2.10"],
install_requires=["attrs>=18", "beautifulsoup4>=0", "lib50>=3,<4", "packaging", "pexpect>=4.6", "pyyaml>6,<7", "requests>=2.19", "setuptools", "termcolor>=1.1", "jinja2>=2.10"],
extras_require = {
"develop": ["sphinx", "sphinx-autobuild", "sphinx_rtd_theme"]
},
Expand All @@ -30,6 +30,6 @@
"console_scripts": ["check50=check50.__main__:main"]
},
url="https://github.com/cs50/check50",
version="3.3.9",
version="3.3.10",
include_package_data=True
)

0 comments on commit c9d3d2e

Please sign in to comment.