-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move away from deprecated pkg_resources (#210)
* Move away from deprecated pkg_resources I followed the migration guide: https://importlib-resources.readthedocs.io/en/latest/migration.html. Unfortunately the new APIs are only available as of Python 3.9. There are other ones, also in `importlib.resources`, that are available since 3.7 but are deprecated and 3.11. * Use deprecated pkg_resources on old python versions --------- Co-authored-by: Nick Smith <nick.smith@cern.ch>
- Loading branch information
Showing
4 changed files
with
33 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,20 @@ | ||
def register_pyroot_binding() -> None: | ||
import os.path | ||
import sys | ||
|
||
import pkg_resources | ||
from cppyy import gbl | ||
|
||
from .util import this_module_path | ||
|
||
base_path = this_module_path() | ||
lib = base_path / "lib" | ||
|
||
# maybe not the most robust solution? | ||
if sys.platform.startswith("win32"): | ||
lib = pkg_resources.resource_filename( | ||
"correctionlib", os.path.join("lib", "correctionlib.dll") | ||
) | ||
lib = lib / "correctionlib.dll" | ||
elif sys.platform.startswith("darwin"): | ||
lib = pkg_resources.resource_filename( | ||
"correctionlib", os.path.join("lib", "libcorrectionlib.dylib") | ||
) | ||
lib = lib / "libcorrectionlib.dylib" | ||
else: | ||
lib = pkg_resources.resource_filename( | ||
"correctionlib", os.path.join("lib", "libcorrectionlib.so") | ||
) | ||
lib = lib / "libcorrectionlib.so" | ||
gbl.gSystem.Load(lib) | ||
gbl.gInterpreter.AddIncludePath( | ||
pkg_resources.resource_filename("correctionlib", "include") | ||
) | ||
gbl.gInterpreter.AddIncludePath(base_path / "include") | ||
gbl.gROOT.ProcessLine('#include "correction.h"') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pathlib | ||
import sys | ||
|
||
|
||
def this_module_path() -> pathlib.Path: | ||
# TODO: this package could be a zipball, in which case these paths are temporary | ||
# We could warn but there is an almost negligible chance this is the case | ||
if sys.version_info < (3, 9): | ||
# use deprecated API | ||
import pkg_resources | ||
|
||
return pathlib.Path(pkg_resources.resource_filename("correctionlib", "")) | ||
import importlib.resources | ||
|
||
return importlib.resources.files("correctionlib") |