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

Remove pkg_resources for Python >=3.9 #673

Merged
merged 12 commits into from
Oct 1, 2023
20 changes: 18 additions & 2 deletions jnius_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,27 @@ def get_classpath():
"Retrieves the classpath the JVM will use."
from os import environ
from os.path import realpath
import sys
global classpath

# add a path to java classes packaged with jnius
from pkg_resources import resource_filename
return_classpath = [realpath(resource_filename(__name__, 'jnius/src'))]
if sys.version_info >= (3, 9):
from contextlib import ExitStack
import importlib.resources, atexit
cmacdonald marked this conversation as resolved.
Show resolved Hide resolved

# see https://importlib-resources.readthedocs.io/en/latest/migration.html#pkg-resources-resource-filename
file_manager = ExitStack()
atexit.register(file_manager.close)
# importlib.resources.files is only available from Python 3.9
# use https://github.com/python/importlib_resources/issues/60 not __name__ as jnius_config.py is not a package
resource_path = importlib.resources.files('jnius') / 'src'
return_classpath = [ str(resource_path) ]
path = file_manager.enter_context(
importlib.resources.as_file(resource_path))
misl6 marked this conversation as resolved.
Show resolved Hide resolved
else:
from pkg_resources import resource_filename
return_classpath = [realpath(resource_filename(__name__, 'jnius/src'))]


if classpath is not None:
return_classpath = classpath + return_classpath
Expand Down