From b5a10cc03683d346959dc93f47f9423c6dd14754 Mon Sep 17 00:00:00 2001 From: Luciano Bello Date: Thu, 20 Jul 2023 01:23:43 +0200 Subject: [PATCH] __qiskit_version__ deprecation (#10242) * __qiskit_version__ deprecation * reno * reno feature * PackageNotFoundError * revert stacklevel=2 * revert change in test * remove OrderedDict * other qiskit.__qiskit_version__ packages have their own __version__ * wording in the reno * lint * Update qiskit/tools/jupyter/version_table.py Co-authored-by: Matthew Treinish * Update qiskit/tools/jupyter/version_table.py * Restore removed version checks --------- Co-authored-by: Matthew Treinish --- qiskit/tools/jupyter/version_table.py | 27 ++++++++++++------- qiskit/version.py | 17 ++++++++---- .../qiskit_version-956916f7b8d7bbb9.yaml | 9 +++++++ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 releasenotes/notes/qiskit_version-956916f7b8d7bbb9.yaml diff --git a/qiskit/tools/jupyter/version_table.py b/qiskit/tools/jupyter/version_table.py index f013c4fb860d..67681ee51674 100644 --- a/qiskit/tools/jupyter/version_table.py +++ b/qiskit/tools/jupyter/version_table.py @@ -14,6 +14,7 @@ """A module for monitoring backends.""" import time +from sys import modules from IPython.display import HTML, display from IPython.core.magic import line_magic, Magics, magics_class import qiskit @@ -33,19 +34,27 @@ def qiskit_version_table(self, line="", cell=None): """ html = "

Version Information

" html += "" - html += "" + html += "" - packages = [] - qver = qiskit.__qiskit_version__ + packages = {} - for pkg in qver: - if qver[pkg]: - packages.append((f"{pkg}", qver[pkg])) + from importlib.metadata import metadata, PackageNotFoundError - for name, version in packages: - html += f"" + try: + packages["qiskit"] = metadata("qiskit")["Version"] + except PackageNotFoundError: + packages["qiskit"] = None + + packages["qiskit-terra"] = qiskit.__version__ + + qiskit_modules = {module.split(".")[0] for module in modules.keys() if "qiskit" in module} + for qiskit_module in qiskit_modules: + packages[qiskit_module] = getattr(modules[qiskit_module], "__version__", None) + + for name, version in packages.items(): + html += f"" - html += "" + html += "" local_hw_info = local_hardware_info() sys_info = [ diff --git a/qiskit/version.py b/qiskit/version.py index 6fed7c92bc7e..1f38b39a0e29 100644 --- a/qiskit/version.py +++ b/qiskit/version.py @@ -12,12 +12,14 @@ # pylint: disable=no-name-in-module,broad-except,cyclic-import -"""Contains the terra version.""" +"""Contains Qiskit (terra) version.""" import os import subprocess from collections.abc import Mapping +import warnings + ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -86,16 +88,21 @@ def get_version_info(): class QiskitVersion(Mapping): - """A lazy loading wrapper to get qiskit versions.""" + """DEPRECATED in 0.25.0 use qiskit.__version__""" __slots__ = ["_version_dict", "_loaded"] def __init__(self): + warnings.warn( + "qiskit.__qiskit_version__ is deprecated since " + "Qiskit Terra 0.25.0, and will be removed 3 months or more later. " + "Instead, you should use qiskit.__version__. The other packages listed in " + "former qiskit.__qiskit_version__ have their own __version__ module level dunder, " + "as standard in PEP 8.", + category=DeprecationWarning, + ) self._version_dict = { "qiskit-terra": __version__, - "qiskit-aer": None, - "qiskit-ignis": None, - "qiskit-ibmq-provider": None, "qiskit": None, } self._loaded = False diff --git a/releasenotes/notes/qiskit_version-956916f7b8d7bbb9.yaml b/releasenotes/notes/qiskit_version-956916f7b8d7bbb9.yaml new file mode 100644 index 000000000000..33f8d825e3af --- /dev/null +++ b/releasenotes/notes/qiskit_version-956916f7b8d7bbb9.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + The magic ``%qiskit_version_table`` from ``qiskit.tools.jupyter`` now includes all + imported modules with ``'qiskit`` in their name. +deprecations: + - | + The dictionary ``qiskit.__qiskit_version__`` is deprecated, as Qiskit is define with a single package (``qiskit-terra``). + In the future, ``qiskit.__version__`` will be the single point to query the Qiskit release, as a standard string.
Qiskit SoftwareVersion
SoftwareVersion
{name}{version}
{name}{version}
System information
System information