Skip to content

Commit

Permalink
Port deprecated conda.auxlib.packaging.get_version_from_git_tag to …
Browse files Browse the repository at this point in the history
…`conda_build` (#5221)
  • Loading branch information
kenodegard committed Mar 8, 2024
1 parent 5353b38 commit f6403dc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
14 changes: 11 additions & 3 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
19 changes: 18 additions & 1 deletion conda_build/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
TemporaryDirectory,
context,
create_default_packages,
get_version_from_git_tag,
pkgs_dirs,
reset_context,
root_dir,
Expand Down Expand Up @@ -223,6 +222,24 @@ def verify_git_repo(
return OK


GIT_DESCRIBE_REGEX = re.compile(
r"(?:[_-a-zA-Z]*)"
r"(?P<version>[a-zA-Z0-9.]+)"
r"(?:-(?P<post>\d+)-g(?P<hash>[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:
Expand Down
19 changes: 19 additions & 0 deletions news/5221-deprecate-get_version_from_git_tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* <news item>

### 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

* <news item>

### Other

* <news item>

0 comments on commit f6403dc

Please sign in to comment.