Skip to content

Commit

Permalink
Move dist_str_to_quad, strip_extension to .history
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Bargull <[email protected]>
  • Loading branch information
mbargull committed Feb 2, 2024
1 parent 4e0a393 commit 27573c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
26 changes: 24 additions & 2 deletions conda/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@

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
from .common.path import paths_equal
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

Expand All @@ -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)))
Expand Down
18 changes: 1 addition & 17 deletions conda/models/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) :]
Expand Down Expand Up @@ -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

0 comments on commit 27573c7

Please sign in to comment.