Remove pkg_resources for Python >=3.9 (#673)

* WIP: addresses pkg_resources deprecation

* more fixes

* attempt for py3.9

* paths to strings

* One path not many

* Update jnius_config.py - use path obj

* Be verbose during testing

* Print for baseline too

* Remove prints

* drop unused import

* revert pytest change

* address review feedback
This commit is contained in:
Craig Macdonald 2023-10-01 14:23:04 +01:00 committed by GitHub
parent 9ef610cfc3
commit d3525a34bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 2 deletions

View File

@ -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
import atexit
# 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) ]
file_manager.enter_context(importlib.resources.as_file(resource_path))
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