Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pkg_resources with importlib.metadata for Python 3.12 #118

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading