Skip to content

Commit

Permalink
__qiskit_version__ deprecation (Qiskit#10242)
Browse files Browse the repository at this point in the history
* __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 <[email protected]>

* Update qiskit/tools/jupyter/version_table.py

* Restore removed version checks

---------

Co-authored-by: Matthew Treinish <[email protected]>
  • Loading branch information
2 people authored and to24toro committed Aug 3, 2023
1 parent 478cebb commit b5a10cc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
27 changes: 18 additions & 9 deletions qiskit/tools/jupyter/version_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,19 +34,27 @@ def qiskit_version_table(self, line="", cell=None):
"""
html = "<h3>Version Information</h3>"
html += "<table>"
html += "<tr><th>Qiskit Software</th><th>Version</th></tr>"
html += "<tr><th>Software</th><th>Version</th></tr>"

packages = []
qver = qiskit.__qiskit_version__
packages = {}

for pkg in qver:
if qver[pkg]:
packages.append((f"<code>{pkg}</code>", qver[pkg]))
from importlib.metadata import metadata, PackageNotFoundError

for name, version in packages:
html += f"<tr><td>{name}</td><td>{version}</td></tr>"
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"<tr><td><code>{name}</code></td><td>{version}</td></tr>"

html += "<tr><th>System information</th></tr>"
html += "<tr><th colspan='2'>System information</th></tr>"

local_hw_info = local_hardware_info()
sys_info = [
Expand Down
17 changes: 12 additions & 5 deletions qiskit/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))


Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions releasenotes/notes/qiskit_version-956916f7b8d7bbb9.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit b5a10cc

Please sign in to comment.