Skip to content

Commit c9d3d2e

Browse files
authored
Merge pull request #322 from cs50/rongxin-patch-1
Replace pkg_resources with importlib.metadata for Python 3.12
2 parents 941d0e3 + 64b36f2 commit c9d3d2e

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

check50/__init__.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
def _set_version():
22
"""Set check50 __version__"""
33
global __version__
4-
from pkg_resources import get_distribution, DistributionNotFound
4+
from importlib.metadata import PackageNotFoundError, version
55
import os
66
# https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
77
try:
8-
dist = get_distribution("check50")
9-
# Normalize path for cross-OS compatibility.
10-
dist_loc = os.path.normcase(dist.location)
11-
here = os.path.normcase(__file__)
12-
if not here.startswith(os.path.join(dist_loc, "check50")):
13-
# This version is not installed, but another version is.
14-
raise DistributionNotFound
15-
except DistributionNotFound:
16-
__version__ = "locally installed, no version information available"
17-
else:
18-
__version__ = dist.version
8+
__version__ = version("check50")
9+
except PackageNotFoundError:
10+
__version__ = "UNKNOWN"
1911

2012

2113
def _setup_translation():
2214
import gettext
23-
from pkg_resources import resource_filename
15+
from importlib.resources import files
2416
global _translation
2517
_translation = gettext.translation(
26-
"check50", resource_filename("check50", "locale"), fallback=True)
18+
"check50", str(files("check50").joinpath("locale")), fallback=True)
2719
_translation.install()
2820

2921

check50/renderer/_renderers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import pathlib
33

44
import jinja2
5-
import pkg_resources
65
import termcolor
76

8-
TEMPLATES = pathlib.Path(pkg_resources.resource_filename("check50.renderer", "templates"))
7+
from importlib.resources import files
8+
9+
TEMPLATES = pathlib.Path(files("check50.renderer").joinpath("templates"))
910

1011

1112
def to_html(slug, results, version):

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
message_extractors = {
1919
'check50': [('**.py', 'python', None),],
2020
},
21-
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"],
21+
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"],
2222
extras_require = {
2323
"develop": ["sphinx", "sphinx-autobuild", "sphinx_rtd_theme"]
2424
},
@@ -30,6 +30,6 @@
3030
"console_scripts": ["check50=check50.__main__:main"]
3131
},
3232
url="https://github.com/cs50/check50",
33-
version="3.3.9",
33+
version="3.3.10",
3434
include_package_data=True
3535
)

0 commit comments

Comments
 (0)