From f6403dc16687c5d6227551cc974207198628edd6 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Fri, 8 Mar 2024 14:54:36 -0600 Subject: [PATCH] Port deprecated `conda.auxlib.packaging.get_version_from_git_tag` to `conda_build` (#5221) --- conda_build/conda_interface.py | 14 +++++++++++--- conda_build/environ.py | 19 ++++++++++++++++++- news/5221-deprecate-get_version_from_git_tag | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 news/5221-deprecate-get_version_from_git_tag diff --git a/conda_build/conda_interface.py b/conda_build/conda_interface.py index f309b338a0..3f25e89591 100644 --- a/conda_build/conda_interface.py +++ b/conda_build/conda_interface.py @@ -8,9 +8,6 @@ from importlib import import_module # noqa: F401 from conda import __version__ as CONDA_VERSION # noqa: F401 -from conda.auxlib.packaging import ( # noqa: F401 - _get_version_from_git_tag as get_version_from_git_tag, -) from conda.base.context import context, determine_target_prefix, reset_context from conda.base.context import non_x86_machines as non_x86_linux_machines # noqa: F401 from conda.core.package_cache import ProgressiveFetchExtract # noqa: F401 @@ -117,3 +114,14 @@ def handle_proxy_407(x, y): ) def md5_file(path: str | os.PathLike) -> str: return compute_sum(path, "md5") + + +@deprecated( + "24.3", + "24.5", + addendum="Use `conda_build.environ.get_version_from_git_tag` instead.", +) +def get_version_from_git_tag(tag): + from .environ import get_version_from_git_tag + + return get_version_from_git_tag(tag) diff --git a/conda_build/environ.py b/conda_build/environ.py index ba57d39314..4fe68add36 100644 --- a/conda_build/environ.py +++ b/conda_build/environ.py @@ -48,7 +48,6 @@ TemporaryDirectory, context, create_default_packages, - get_version_from_git_tag, pkgs_dirs, reset_context, root_dir, @@ -223,6 +222,24 @@ def verify_git_repo( return OK +GIT_DESCRIBE_REGEX = re.compile( + r"(?:[_-a-zA-Z]*)" + r"(?P[a-zA-Z0-9.]+)" + r"(?:-(?P\d+)-g(?P[0-9a-f]{7,}))$" +) + + +def get_version_from_git_tag(tag): + """Return a PEP440-compliant version derived from the git status. + If that fails for any reason, return the changeset hash. + """ + m = GIT_DESCRIBE_REGEX.match(tag) + if m is None: + return None + version, post_commit, hash = m.groups() + return version if post_commit == "0" else f"{version}.post{post_commit}+{hash}" + + def get_git_info(git_exe, repo, debug): """ Given a repo to a git repo, return a dictionary of: diff --git a/news/5221-deprecate-get_version_from_git_tag b/news/5221-deprecate-get_version_from_git_tag new file mode 100644 index 0000000000..2c1e811a54 --- /dev/null +++ b/news/5221-deprecate-get_version_from_git_tag @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* Mark `conda_build.conda_interface.get_version_from_git_tag` as deprecated. Use `conda_build.environ.get_version_from_git_tag` instead. (#5221) + +### Docs + +* + +### Other + +*