From a05ebd0044246da04de95b69215e384eccfbda97 Mon Sep 17 00:00:00 2001 From: Vladimir Petko Date: Thu, 16 Jan 2025 13:09:41 +1300 Subject: [PATCH] chore(3.12): replace pkg_resources with importlib Python 3.12 removes setuptools from the default installation. Replace usage of pkg_resources with importlib. I have added except: case to allow testing without install. --- kineticsTools/ipdModel.py | 9 ++++++--- kineticsTools/ipdSummary.py | 10 ++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/kineticsTools/ipdModel.py b/kineticsTools/ipdModel.py index b1d4964..792bbc2 100644 --- a/kineticsTools/ipdModel.py +++ b/kineticsTools/ipdModel.py @@ -1,4 +1,4 @@ -from pkg_resources import Requirement, resource_filename +from importlib import resources import logging import gzip import os.path as op @@ -47,8 +47,11 @@ def _getAbsPath(fname): - return resource_filename(Requirement.parse( - 'kineticsTools'), 'kineticsTools/%s' % fname) + try: + with resources.as_file(resources.files('kineticsTools') / fname) as path: + return str(path) + except: + return os.path.join(os.path.dirname(__file__), path) class GbmContextModel(object): diff --git a/kineticsTools/ipdSummary.py b/kineticsTools/ipdSummary.py index 7b7d4b5..d10c2b0 100644 --- a/kineticsTools/ipdSummary.py +++ b/kineticsTools/ipdSummary.py @@ -20,7 +20,7 @@ import numpy as np import queue import traceback -from pkg_resources import Requirement, resource_filename +from importlib import resources from pbcommand.common_options import add_debug_option from pbcommand.cli import get_default_argparser_with_base_opts, pacbio_args_runner @@ -43,9 +43,11 @@ class Constants(object): def _getResourcePathSpec(): - default_dir = resource_filename(Requirement.parse( - 'kineticsTools'), 'kineticsTools/resources') - return loader.getResourcePathSpec(default_dir) + try: + with resources.as_file(resources.files('kineticTools') / 'resources') as path: + return loader.getResourcePathSpec(path) + except: + return loader.getResourcePathSpec(os.path.join(os.path.dirname(__file__), 'resources')) def _validateResource(func, p):