diff --git a/check50/__init__.py b/check50/__init__.py index 558597b0..5f052914 100644 --- a/check50/__init__.py +++ b/check50/__init__.py @@ -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() diff --git a/check50/renderer/_renderers.py b/check50/renderer/_renderers.py index bbbb43ef..0ddc252a 100644 --- a/check50/renderer/_renderers.py +++ b/check50/renderer/_renderers.py @@ -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): diff --git a/setup.py b/setup.py index b92f4789..a374029b 100644 --- a/setup.py +++ b/setup.py @@ -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"] }, @@ -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 )