| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| """Contains the Algorithms version.""" |
|
|
| import os |
| import subprocess |
|
|
| ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| QISKIT_DIR = os.path.dirname(ROOT_DIR) |
|
|
|
|
| def _minimal_ext_cmd(cmd): |
| |
| env = {} |
| for k in ["SYSTEMROOT", "PATH"]: |
| v = os.environ.get(k) |
| if v is not None: |
| env[k] = v |
| |
| env["LANGUAGE"] = "C" |
| env["LANG"] = "C" |
| env["LC_ALL"] = "C" |
| with subprocess.Popen( |
| cmd, |
| stdout=subprocess.PIPE, |
| stderr=subprocess.PIPE, |
| env=env, |
| cwd=os.path.join(os.path.dirname(QISKIT_DIR)), |
| ) as proc: |
| stdout, stderr = proc.communicate() |
| if proc.returncode > 0: |
| raise OSError( |
| f"Command {cmd} exited with code {proc.returncode}: {stderr.strip().decode('ascii')}" |
| ) |
| return stdout |
|
|
|
|
| def git_version(): |
| """Get the current git head sha1.""" |
| |
| try: |
| out = _minimal_ext_cmd(["git", "rev-parse", "HEAD"]) |
| git_revision = out.strip().decode("ascii") |
| except OSError: |
| git_revision = "Unknown" |
|
|
| return git_revision |
|
|
|
|
| with open(os.path.join(ROOT_DIR, "VERSION.txt"), "r", encoding="utf8") as version_file: |
| VERSION = version_file.read().strip() |
|
|
|
|
| def get_version_info(): |
| """Get the full version string.""" |
| |
| |
| |
| full_version = VERSION |
|
|
| if not os.path.exists(os.path.join(os.path.dirname(QISKIT_DIR), ".git")): |
| return full_version |
| try: |
| release = _minimal_ext_cmd(["git", "tag", "-l", "--points-at", "HEAD"]) |
| except Exception: |
| return full_version |
| git_revision = git_version() |
| if not release: |
| full_version += ".dev0+" + git_revision[:7] |
|
|
| return full_version |
|
|
|
|
| __version__ = get_version_info() |
|
|