Skip to content

Commit e151d69

Browse files
garrisonkt474
andauthored
Migrate from pkg_resources to importlib.metadata (#1449)
PR #1347 added `setuptools` to `requirements-dev.txt` in an effort to make `qiskit-ibm-runtime` work with Python 3.12. However, `qiskit_ibm_runtime/api/session.py` actually imports `pkg_resources`, which is provided by setuptools, so really setuptools should have been added to [`REQUIREMENTS`](https://github.com/Qiskit/qiskit-ibm-runtime/blob/e152d122782959a04ebf2330f776d4c4e309ad14/setup.py#L21) in `setup.py` so that it is installed automatically for any downstream users of Qiskit Runtime, too. Better yet, however, is to drop this explicit dependency on setuptools, since [`pkg_resources` is deprecated](https://setuptools.pypa.io/en/latest/pkg_resources.html) in favor of `importlib`. Hence, this PR migrates from `pkg_resources` to `importlib.metadata` (there are a few more words about this [here](googleapis/python-api-core#27 (comment))). My investigation into this was prompted by us trying to add Python 3.12 support to the circuit-knitting-toolbox (Qiskit/qiskit-addon-cutting#429), and seeing CI errors prompted by `qiskit-ibm-runtime`'s importing of `pkg_resources`. Co-authored-by: Kevin Tian <[email protected]>
1 parent fba5ce1 commit e151d69

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

qiskit_ibm_runtime/api/session.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import sys
2020
from typing import Dict, Optional, Any, Tuple, Union
2121
from pathlib import PurePath
22-
import pkg_resources
22+
import importlib.metadata
2323

2424
from requests import Session, RequestException, Response
2525
from requests.adapters import HTTPAdapter
@@ -74,7 +74,7 @@ def _get_client_header() -> str:
7474
pkg_versions = {"qiskit_ibm_runtime": f"qiskit_ibm_runtime-{ibm_runtime_version}"}
7575
for pkg_name in qiskit_pkgs:
7676
try:
77-
version_info = f"{pkg_name}-{pkg_resources.get_distribution(pkg_name).version}"
77+
version_info = f"{pkg_name}-{importlib.metadata.version(pkg_name)}"
7878

7979
if pkg_name in sys.modules:
8080
version_info += "*"

requirements-dev.txt

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ black~=22.0
1313
coverage>=6.3
1414
pylatexenc
1515
scikit-learn
16-
setuptools
1716
ddt>=1.2.0,!=1.4.0,!=1.4.3
1817

1918
# Documentation

0 commit comments

Comments
 (0)