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

Fix Python 3.12 compat: pkg_resources -> importlib #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion lice/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pkg_resources import (resource_stream, resource_listdir)
from io import StringIO
import argparse
import datetime
Expand All @@ -8,6 +7,21 @@
import sys
import getpass

try:
from pkg_resources import resource_stream, resource_listdir
except ImportError:
import importlib.resources

def resource_stream(package_or_requirement, resource_name):
# https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-stream
ref = importlib.resources.files(package_or_requirement).joinpath(resource_name)
return ref.open('rb')

def resource_listdir(package_or_requirement, resource_name):
# https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-listdir
resource_qualname = '.'.join([package_or_requirement, resource_name]).rstrip('.')
return [r.name for r in importlib.resources.files(resource_qualname).iterdir()]


LICENSES = []
for file in sorted(resource_listdir(__name__, '.')):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
entry_points={
'console_scripts': ['lice = lice:main']},
platforms=['any'],
test_suite='lice.tests.collector',
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: BSD License',
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tox]
env_list =
py311
py312
minversion = 4.12.1

[testenv]
deps =
-r requirements.txt
commands =
pytest {tty:--color=yes} {posargs}