Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__qiskit_version__ deprecation #10242

Merged
merged 16 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__
mtreinish marked this conversation as resolved.
Show resolved Hide resolved

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.