Skip to content

Commit

Permalink
Merge branch 'main' into menuinst-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp authored Nov 10, 2023
2 parents 1cc30c5 + d1b96db commit bf9ddd7
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
- id: blacken-docs
additional_dependencies: [black]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
rev: v0.1.4
hooks:
- id: ruff
args: [--fix]
Expand Down
53 changes: 22 additions & 31 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
from functools import partial
from importlib import import_module # noqa: F401
from pathlib import Path
from typing import Iterable

from conda import __version__ as CONDA_VERSION # noqa: F401
from conda.auxlib.packaging import ( # noqa: F401
Expand Down Expand Up @@ -53,7 +55,6 @@
human_bytes,
input,
install_actions,
is_linked,
lchmod,
linked,
linked_data,
Expand All @@ -75,7 +76,7 @@
)
from conda.models.channel import get_conda_build_local_url # noqa: F401
from conda.models.dist import Dist # noqa: F401
from conda.models.records import PackageRecord
from conda.models.records import PackageRecord, PrefixRecord

from .deprecations import deprecated

Expand Down Expand Up @@ -125,46 +126,36 @@ class SignatureError(Exception):
pass


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

path = abspath(path)
prefix = which_prefix(path)
if prefix is None:
raise RuntimeError("could not determine conda prefix from: %s" % path)
for dist in linked(prefix):
meta = is_linked(prefix, dist)
if any(abspath(join(prefix, f)) == path for f in meta["files"]):
yield dist
return which_package(path, which_prefix(path))


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

prefix = abspath(path)
iteration = 0
while iteration < 20:
if isdir(join(prefix, "conda-meta")):
# we found it, so let's return it
break
if prefix == dirname(prefix):
prefix = Path(path)
for _ in range(20):
if is_conda_environment(prefix):
return prefix
elif prefix == (parent := prefix.parent):
# we cannot chop off any more directories, so we didn't find it
prefix = None
break
prefix = dirname(prefix)
iteration += 1
return prefix
else:
prefix = parent

raise RuntimeError("could not determine conda prefix from: %s" % path)


@deprecated("3.28.0", "4.0.0")
Expand Down
Loading

0 comments on commit bf9ddd7

Please sign in to comment.