From 27573c737be41f0f6ae99759c362b0fc678147cf Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Fri, 2 Feb 2024 10:14:10 +0100 Subject: [PATCH] Move dist_str_to_quad, strip_extension to .history Signed-off-by: Marcel Bargull --- conda/history.py | 26 ++++++++++++++++++++++++-- conda/models/dist.py | 18 +----------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/conda/history.py b/conda/history.py index 09aef7334e4..6ff811a2a34 100644 --- a/conda/history.py +++ b/conda/history.py @@ -19,7 +19,11 @@ from . import __version__ as CONDA_VERSION from .auxlib.ish import dals -from .base.constants import DEFAULTS_CHANNEL_NAME +from .base.constants import ( + CONDA_PACKAGE_EXTENSIONS, + DEFAULTS_CHANNEL_NAME, + UNKNOWN_CHANNEL, +) from .base.context import context from .common.compat import ensure_text_type, open from .common.iterators import groupby_to_dict as groupby @@ -27,7 +31,6 @@ from .core.prefix_data import PrefixData from .exceptions import CondaHistoryError, NotWritableError from .gateways.disk.update import touch -from .models.dist import dist_str_to_quad from .models.match_spec import MatchSpec from .models.version import VersionOrder, version_relation_re @@ -38,6 +41,25 @@ class CondaHistoryWarning(Warning): pass +# originally from conda.models.dist +def strip_extension(original_dist): + for ext in CONDA_PACKAGE_EXTENSIONS: + if original_dist.endswith(ext): + original_dist = original_dist[: -len(ext)] + return original_dist + + +# originally from conda.models.dist +def dist_str_to_quad(dist_str): + dist_str = strip_extension(dist_str) + if "::" in dist_str: + channel_str, dist_str = dist_str.split("::", 1) + else: + channel_str = UNKNOWN_CHANNEL + name, version, build = dist_str.rsplit("-", 2) + return name, version, build, channel_str + + def write_head(fo): fo.write("==> %s <==\n" % time.strftime("%Y-%m-%d %H:%M:%S")) fo.write("# cmd: %s\n" % (" ".join(ensure_text_type(s) for s in sys.argv))) diff --git a/conda/models/dist.py b/conda/models/dist.py index 4c261846a0d..5b011fa73ab 100644 --- a/conda/models/dist.py +++ b/conda/models/dist.py @@ -17,6 +17,7 @@ from ..common.constants import NULL from ..common.url import has_platform, is_url, join_url from ..deprecations import deprecated +from ..history import dist_str_to_quad, strip_extension # noqa: F401 from .channel import Channel from .package_info import PackageInfo from .records import PackageRecord @@ -71,13 +72,6 @@ def __call__(cls, *args, **kwargs): return super().__call__(*args, **kwargs) -def strip_extension(original_dist): - for ext in CONDA_PACKAGE_EXTENSIONS: - if original_dist.endswith(ext): - original_dist = original_dist[: -len(ext)] - return original_dist - - def split_extension(original_dist): stripped = strip_extension(original_dist) return stripped, original_dist[len(stripped) :] @@ -354,13 +348,3 @@ def __contains__(self, item): @property def fn(self): return self.to_filename() - - -def dist_str_to_quad(dist_str): - dist_str = strip_extension(dist_str) - if "::" in dist_str: - channel_str, dist_str = dist_str.split("::", 1) - else: - channel_str = UNKNOWN_CHANNEL - name, version, build = dist_str.rsplit("-", 2) - return name, version, build, channel_str