Skip to content

Commit bf9ddd7

Browse files
authored
Merge branch 'main' into menuinst-validation
2 parents 1cc30c5 + d1b96db commit bf9ddd7

10 files changed

+433
-337
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ repos:
6666
- id: blacken-docs
6767
additional_dependencies: [black]
6868
- repo: https://github.com/astral-sh/ruff-pre-commit
69-
rev: v0.1.3
69+
rev: v0.1.4
7070
hooks:
7171
- id: ruff
7272
args: [--fix]

conda_build/conda_interface.py

+22-31
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import os
77
from functools import partial
88
from importlib import import_module # noqa: F401
9+
from pathlib import Path
10+
from typing import Iterable
911

1012
from conda import __version__ as CONDA_VERSION # noqa: F401
1113
from conda.auxlib.packaging import ( # noqa: F401
@@ -53,7 +55,6 @@
5355
human_bytes,
5456
input,
5557
install_actions,
56-
is_linked,
5758
lchmod,
5859
linked,
5960
linked_data,
@@ -75,7 +76,7 @@
7576
)
7677
from conda.models.channel import get_conda_build_local_url # noqa: F401
7778
from conda.models.dist import Dist # noqa: F401
78-
from conda.models.records import PackageRecord
79+
from conda.models.records import PackageRecord, PrefixRecord
7980

8081
from .deprecations import deprecated
8182

@@ -125,46 +126,36 @@ class SignatureError(Exception):
125126
pass
126127

127128

128-
@deprecated("3.28.0", "4.0.0")
129-
def which_package(path):
130-
"""
131-
Given the path (of a (presumably) conda installed file) iterate over
132-
the conda packages the file came from. Usually the iteration yields
133-
only one package.
134-
"""
135-
from os.path import abspath, join
129+
@deprecated(
130+
"3.28.0",
131+
"4.0.0",
132+
addendum="Use `conda_build.inspect_pkg.which_package` instead.",
133+
)
134+
def which_package(path: str | os.PathLike | Path) -> Iterable[PrefixRecord]:
135+
from .inspect_pkg import which_package
136136

137-
path = abspath(path)
138-
prefix = which_prefix(path)
139-
if prefix is None:
140-
raise RuntimeError("could not determine conda prefix from: %s" % path)
141-
for dist in linked(prefix):
142-
meta = is_linked(prefix, dist)
143-
if any(abspath(join(prefix, f)) == path for f in meta["files"]):
144-
yield dist
137+
return which_package(path, which_prefix(path))
145138

146139

147140
@deprecated("3.28.0", "4.0.0")
148-
def which_prefix(path):
141+
def which_prefix(path: str | os.PathLike | Path) -> Path:
149142
"""
150143
Given the path (to a (presumably) conda installed file) return the
151144
environment prefix in which the file in located
152145
"""
153-
from os.path import abspath, dirname, isdir, join
146+
from conda.gateways.disk.test import is_conda_environment
154147

155-
prefix = abspath(path)
156-
iteration = 0
157-
while iteration < 20:
158-
if isdir(join(prefix, "conda-meta")):
159-
# we found it, so let's return it
160-
break
161-
if prefix == dirname(prefix):
148+
prefix = Path(path)
149+
for _ in range(20):
150+
if is_conda_environment(prefix):
151+
return prefix
152+
elif prefix == (parent := prefix.parent):
162153
# we cannot chop off any more directories, so we didn't find it
163-
prefix = None
164154
break
165-
prefix = dirname(prefix)
166-
iteration += 1
167-
return prefix
155+
else:
156+
prefix = parent
157+
158+
raise RuntimeError("could not determine conda prefix from: %s" % path)
168159

169160

170161
@deprecated("3.28.0", "4.0.0")

0 commit comments

Comments
 (0)