diff --git a/cli50/__init__.py b/cli50/__init__.py index 2e47898..fc9734f 100644 --- a/cli50/__init__.py +++ b/cli50/__init__.py @@ -1,22 +1,13 @@ import os -from pkg_resources import DistributionNotFound, get_distribution +import sys +from importlib.metadata import PackageNotFoundError, version -# https://stackoverflow.com/a/17638236/5156190 -try: - - # Get package's distribution - _dist = get_distribution("cli50") - - # Normalize path for cross-OS compatibility - _dist_loc = os.path.normcase(_dist.location) - _here = os.path.normcase(__file__) +# Require Python 3.8+ +if sys.version_info < (3, 8): + sys.exit("You have an old version of python. Install version 3.8 or higher.") - # This version is not installed, but another version is - if not _here.startswith(os.path.join(_dist_loc, "cli50")): - raise DistributionNotFound - -except DistributionNotFound: - __version__ = None - -else: - __version__ = _dist.version +# Get version +try: + __version__ = version("cli50") +except PackageNotFoundError: + __version__ = "UNKNOWN" diff --git a/cli50/__main__.py b/cli50/__main__.py index 684250b..279d0e1 100644 --- a/cli50/__main__.py +++ b/cli50/__main__.py @@ -8,7 +8,6 @@ import inflect import json import os -import pkg_resources import re import requests import shlex @@ -16,6 +15,8 @@ import subprocess import textwrap import tzlocal +from importlib.resources import files +from packaging import version from . import __version__ @@ -35,7 +36,7 @@ TAG = "latest" # Internationalization -t = gettext.translation("cli50", pkg_resources.resource_filename("cli50", "locale"), fallback=True) +t = gettext.translation("cli50", str(files("cli50").joinpath("locale")), fallback=True) t.install() @@ -61,7 +62,7 @@ def main(): # Check PyPI for newer version if __version__ and not args["fast"]: try: - release = max(requests.get("https://pypi.org/pypi/cli50/json").json()["releases"], key=pkg_resources.parse_version) + release = max(requests.get("https://pypi.org/pypi/cli50/json").json()["releases"], key=version.parse) assert release <= __version__ except requests.RequestException: pass diff --git a/setup.py b/setup.py index 23e54aa..8ef9f7a 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ classifiers=[ "Intended Audience :: Developers", "Intended Audience :: System Administrators", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.8", "Topic :: Software Development" ], message_extractors = { @@ -15,7 +15,7 @@ description="This is CS50 CLI, with which you can mount a directory inside of an Ubuntu container.", long_description=open("README.md").read(), license="GPLv3", - install_requires=["inflect", "requests", "tzlocal"], + install_requires=["inflect", "packaging", "requests", "tzlocal"], keywords="cli50", name="cli50", python_requires=">=3.8", @@ -24,6 +24,6 @@ "console_scripts": ["cli50=cli50.__main__:main"] }, url="https://github.com/cs50/cli50", - version="7.5.1", + version="8.0.0", include_package_data=True )