[Debian-med-packaging] Bug#1093230: python-pbcore: unable to import pbcore with python default 3.13
Vladimir Petko
vpa1977 at gmail.com
Thu Jan 16 19:25:32 GMT 2025
Package: python-pbcore
Version: 2.1.2+dfsg-10
Severity: important
Tags: patch
User: ubuntu-devel at lists.ubuntu.com
Usertags: origin-ubuntu plucky ubuntu-patch
Dear Maintainer,
Adding a simple autopkgtest `python -c "import pbcore"` fails with the
following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
import pbcore
File "/tmp/autopkgtest.Mysbkx/build.qos/real-tree/pbcore/__init__.py", line
1, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
This is due to python 3.12 removing setuptools from the default installation.
In Ubuntu, the attached patch was applied to achieve the following:
* d/p/remove-pkg-resources.patch: replace the usages of pkg_resources
with importlib.resources for Python 3.13 compatibility (LP: #2095040).
* d/t/control: add smoke test.
Thanks for considering the patch.
-- System Information:
Debian Release: trixie/sid
APT prefers oracular-updates
APT policy: (500, 'oracular-updates'), (500, 'oracular-security'), (500, 'oracular'), (100, 'oracular-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 6.11.0-13-generic (SMP w/32 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_WARN, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
-------------- next part --------------
diff -Nru python-pbcore-2.1.2+dfsg/debian/patches/remove-pkg-resources.patch python-pbcore-2.1.2+dfsg/debian/patches/remove-pkg-resources.patch
--- python-pbcore-2.1.2+dfsg/debian/patches/remove-pkg-resources.patch 1970-01-01 12:00:00.000000000 +1200
+++ python-pbcore-2.1.2+dfsg/debian/patches/remove-pkg-resources.patch 2025-01-15 16:11:18.000000000 +1300
@@ -0,0 +1,116 @@
+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 at canonical.com>
+Bug: https://github.com/PacificBiosciences/pbcore/pull/126
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-pbcore/+bug/2095040
+Last-Update: 2025-01-15
+
+--- a/pbcore/data/datasets/__init__.py
++++ b/pbcore/data/datasets/__init__.py
+@@ -1,7 +1,7 @@
+ """Doctest resources"""
+
+ import os
+-from pkg_resources import Requirement, resource_filename
++from importlib import resources
+
+ XML_FILES = ["alignment.dataset.xml", # 0
+ "barcode.dataset.xml",
+@@ -33,8 +33,10 @@
+
+
+ def _getAbsPath(fname):
+- return resource_filename(Requirement.parse('pbcore'),
+- 'pbcore/data/datasets/%s' % fname)
++ with resources.as_file(
++ resources.files('pbcore') /
++ 'data/datasets' / fname) as ret:
++ return str(ret)
+
+
+ def getXml(no=0):
+--- a/pbcore/data/__init__.py
++++ b/pbcore/data/__init__.py
+@@ -1,4 +1,4 @@
+-from pkg_resources import Requirement, resource_filename
++from importlib import resources
+
+ MOVIE_NAME_14 = "m110818_075520_42141_c100129202555500000315043109121112_s1_p0"
+ MOVIE_NAME_20 = "m130522_092457_42208_c100497142550000001823078008081323_s1_p0"
+@@ -9,7 +9,10 @@
+
+
+ def _getAbsPath(fname):
+- return resource_filename(Requirement.parse('pbcore'), 'pbcore/data/%s' % fname)
++ with resources.as_file(
++ resources.files('pbcore') /
++ 'data' / fname) as ret:
++ return str(ret)
+
+
+ def getCCSBAM():
+--- a/pbcore/__init__.py
++++ b/pbcore/__init__.py
+@@ -1,6 +1,6 @@
+-import pkg_resources
++from importlib.metadata import Distribution, PackageNotFoundError
+
+ try:
+- __VERSION__ = pkg_resources.get_distribution('pbcore').version
+-except Exception:
++ __VERSION__ = Distribution.from_name('pbcore').version
++except PackageNotFoundError:
+ __VERSION__ = 'unknown'
+--- a/pbcore/chemistry/chemistry.py
++++ b/pbcore/chemistry/chemistry.py
+@@ -6,7 +6,7 @@
+ import xml.etree.ElementTree as ET
+ import os.path
+
+-from pkg_resources import Requirement, resource_filename
++from importlib import resources
+
+
+ class ChemistryLookupError(Exception):
+@@ -35,12 +35,16 @@
+
+ def _loadBarcodeMappings():
+ try:
+- mappingFname = resource_filename(Requirement.parse(
+- 'pbcore'), 'pbcore/chemistry/resources/mapping.xml')
++ mappingFnameContext = resources.as_file(
++ resources.files('pbcore') /
++ 'chemistry/resources/mapping.xml')
++ with mappingFnameContext as mappingFname:
++ mappings = _loadBarcodeMappingsFromFile(mappingFname)
+ except:
+ mappingFname = os.path.join(os.path.dirname(__file__),
+- 'resources/mapping.xml')
+- mappings = _loadBarcodeMappingsFromFile(mappingFname)
++ 'resources/mapping.xml')
++ mappings = _loadBarcodeMappingsFromFile(mappingFname)
++
+ updMappingDir = os.getenv("SMRT_CHEMISTRY_BUNDLE_DIR")
+ if updMappingDir:
+ import logging
+--- a/doc/conf.py
++++ b/doc/conf.py
+@@ -11,12 +11,13 @@
+ # All configuration values have a default; values that are commented out
+ # serve to show the default.
+
+-import pkg_resources
+ import sys, os
+
++from importlib.metadata import Distribution, PackageNotFoundError
++
+ try:
+- __VERSION__ = pkg_resources.get_distribution('pbcore').version
+-except Exception:
++ __VERSION__ = Distribution.from_name('pbcore').version
++except PackageNotFoundError:
+ __VERSION__ = 'unknown'
+
+
diff -Nru python-pbcore-2.1.2+dfsg/debian/patches/series python-pbcore-2.1.2+dfsg/debian/patches/series
--- python-pbcore-2.1.2+dfsg/debian/patches/series 2024-12-17 06:22:11.000000000 +1300
+++ python-pbcore-2.1.2+dfsg/debian/patches/series 2025-01-15 16:11:18.000000000 +1300
@@ -4,3 +4,4 @@
seek-curdir-for-xml.patch
numpy_1.24.patch
no-intersphinx.patch
+remove-pkg-resources.patch
diff -Nru python-pbcore-2.1.2+dfsg/debian/tests/control python-pbcore-2.1.2+dfsg/debian/tests/control
--- python-pbcore-2.1.2+dfsg/debian/tests/control 2024-12-17 06:22:11.000000000 +1300
+++ python-pbcore-2.1.2+dfsg/debian/tests/control 2025-01-15 16:11:18.000000000 +1300
@@ -2,3 +2,8 @@
Depends: @, python3-pytest, python3-pytest-runner, python3-pytest-xdist, python3-pytest-cov
Restrictions: allow-stderr
Architecture: amd64 arm64 ppc64el
+
+Test-Command: python3 -c "import pbcore"
+Depends: @
+Restrictions: allow-stderr
+Architecture: amd64 arm64 ppc64el
More information about the Debian-med-packaging
mailing list