1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Description: Remove usages of pkg_resources
pkg_resources are no longer available in Python 3.12 due to setuptools
removal from the default installation. This patch replaces the usages of
pkg_resources with importlib.resources.
Author: Vladimir Petko <vladimir.petko@canonical.com>
Bug: https://github.com/PacificBiosciences/kineticsTools/pull/105
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/kineticstools/+bug/2095050
Last-Update: 2025-01-16
--- 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,9 +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):
--- 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 @@
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):
|