from __future__ import annotations
__commit_id__: str | None
__version__: str
try:
from sympy._version import __commit_id__, __version__
except ImportError:
# Wheels replace this module with static version information generated by
# setuptools-scm. The _version import above supports older distributions;
# a direct checkout does not have that module, so use Git to provide a
# useful, but explicitly uninstalled, development version. Keep these
# imports here so they are not loaded by older installed copies.
import re
from pathlib import Path
try:
import subprocess
except ImportError:
subprocess = None # type: ignore[assignment]
if subprocess is None:
git_unavailable = True
git_description = ""
else:
try:
git_description = subprocess.check_output(
[
"git",
"describe",
"--tags",
"--long",
"--dirty",
"--match",
"sympy-*",
],
cwd=Path(__file__).resolve().parent.parent,
encoding="ascii",
stderr=subprocess.DEVNULL,
).strip()
except OSError:
git_unavailable = True
git_description = ""
except subprocess.CalledProcessError:
git_unavailable = False
git_description = ""
else:
git_unavailable = False
match = re.fullmatch(
r"sympy-(?P<tag>.+)-(?P<distance>\d+)-g"
r"(?P<commit>[0-9a-f]+)(?P<dirty>-dirty)?",
git_description,
)
if git_unavailable:
# Some constrained Python runtimes have neither subprocess support nor
# a Git executable. Keep a direct source checkout importable without
# claiming to know its release or commit.
__commit_id__ = None
__version__ = "0+unknown.uninstalled"
elif match is None:
try:
is_shallow = subprocess.check_output(
["git", "rev-parse", "--is-shallow-repository"],
cwd=Path(__file__).resolve().parent.parent,
encoding="ascii",
stderr=subprocess.DEVNULL,
).strip() == "true"
except (OSError, subprocess.CalledProcessError):
is_shallow = False
if is_shallow:
raise ImportError(
"SymPy could not determine its version because this is a "
"shallow Git checkout. Run 'git fetch --unshallow --tags' "
"or install SymPy with 'python -m pip install .'."
) from None
raise ImportError(
"SymPy could not determine its version. This source tree is "
"neither an installed SymPy distribution nor an intact Git "
"checkout. GitHub's automatically generated source archives "
"do not contain the version metadata needed by SymPy. Install "
"an official release from PyPI or a SymPy source distribution, "
"or obtain the development source with Git."
) from None
else:
tag = match["tag"]
distance = int(match["distance"])
commit = match["commit"]
dirty = match["dirty"] is not None
__commit_id__ = f"g{commit}"
if distance == 0 and not dirty:
__version__ = f"{tag}+uninstalled"
else:
local_version = f"g{commit}"
if dirty:
local_version += ".dirty"
# Match setuptools-scm's release-branch-semver policy: development
# branches target the next minor release, while a release branch
# named for the tagged major/minor version targets the next patch.
# This is only needed in an uninstalled checkout, so querying Git
# here adds no work when the generated version module is present.
tag_match = re.fullmatch(
r"(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)", tag
)
try:
branch = subprocess.check_output(
["git", "branch", "--show-current"],
cwd=Path(__file__).resolve().parent.parent,
encoding="ascii",
stderr=subprocess.DEVNULL,
).strip()
except (OSError, subprocess.CalledProcessError):
branch = ""
if tag_match is None:
# Keep unusual historical or prerelease tags usable even
# though the normal SymPy release tags are X.Y.Z.
next_version = f"{tag}.post{distance}"
dev_number = 0
else:
major = int(tag_match["major"])
minor = int(tag_match["minor"])
patch = int(tag_match["patch"])
branch_version = re.fullmatch(
r"(?P<major>\d+)\.(?P<minor>\d+)",
branch.rsplit("/", 1)[-1],
)
if (
branch_version is not None
and int(branch_version["major"]) == major
and int(branch_version["minor"]) == minor
):
next_version = f"{major}.{minor}.{patch + 1}"
else:
next_version = f"{major}.{minor + 1}.0"
dev_number = distance
__version__ = f"{next_version}.dev{dev_number}+{local_version}.uninstalled"
¤ Dauer der Verarbeitung: 0.4 Sekunden
¤
*© Formatika GbR, Deutschland