Skip to content

Commit

Permalink
Migrate from pkg_resources to importlib.metadata (Qiskit#1449)
Browse files Browse the repository at this point in the history
PR Qiskit#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]>
  • Loading branch information
garrison and kt474 authored Feb 29, 2024
1 parent fba5ce1 commit e151d69
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions qiskit_ibm_runtime/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import sys
from typing import Dict, Optional, Any, Tuple, Union
from pathlib import PurePath
import pkg_resources
import importlib.metadata

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

if pkg_name in sys.modules:
version_info += "*"
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ black~=22.0
coverage>=6.3
pylatexenc
scikit-learn
setuptools
ddt>=1.2.0,!=1.4.0,!=1.4.3

# Documentation
Expand Down

0 comments on commit e151d69

Please sign in to comment.