Skip to content

Commit

Permalink
replace pkg_resources with importlib.metadata for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
rongxin-liu committed Nov 19, 2023
1 parent b58023a commit 35a777d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
]
},
url="https://github.com/cs50/style50",
version="2.9.0",
version="2.9.1",
include_package_data=True,
)
25 changes: 11 additions & 14 deletions style50/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
from pkg_resources import get_distribution, DistributionNotFound
import os
import sys
from importlib.metadata import PackageNotFoundError, version

# https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
# 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.")

# Get version
try:
_dist = get_distribution("style50")
# 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, "style50")):
# 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("style50")
except PackageNotFoundError:
__version__ = "UNKNOWN"


__all__ = ["Style50", "languages", "StyleCheck", "Error"]

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

import jinja2
import pkg_resources
import termcolor

from importlib.resources import files

TEMPLATES = pathlib.Path(pkg_resources.resource_filename("style50.renderer", "templates"))

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


def to_ansi(files, score, version):
Expand Down

0 comments on commit 35a777d

Please sign in to comment.