Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

which_package to yield unique collection of package records #5108

Merged
merged 10 commits into from
Dec 14, 2023
5 changes: 2 additions & 3 deletions conda_build/inspect_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def which_package(
path = prefix / path

for prec in PrefixData(str(prefix)).iter_records():
for file in prec["files"]:
if samefile(prefix / file, path):
yield prec
if any(samefile(prefix / file, path) for file in prec["files"]):
Copy link
Contributor

@dholth dholth Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(n * m) ? I see this version skips work if true.

Too bad to iterate over all installed files to do the search

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worst case yes, same as before

any returns on the first True: https://docs.python.org/3/library/functions.html#any

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what avoids the duplicated records to begin with, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a subsequent PR, we could see if implementing a cached path -> artifact map would speed this up. It can be a veeery slow part of the post processing stage in conda-build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what avoids the duplicated records to begin with, right?

correct, this is essentially what was happening pre #5041:

for dist in fn(prefix):
# dfiles = set(dist.get('files', []))
dfiles = dist_files(prefix, dist)
# TODO :: This is completely wrong when the env is on a case-sensitive FS!
if any(norm_ipp == normcase(w) for w in dfiles):
yield dist

cached path -> artifact map

definitely something to consider

yield prec


def print_object_info(info, key):
Expand Down
19 changes: 19 additions & 0 deletions news/5108-fix-which_package
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* <news item>

### Bug fixes

* Fix `conda_build.inspect_pkg.which_package` so it does not return duplicate package records. (#5108)
kenodegard marked this conversation as resolved.
Show resolved Hide resolved

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
from conda_build.utils import check_call_env, copy_into, prepend_bin_path
from conda_build.variants import get_default_variant

pytest_plugins = ["conda.testing"]

kenodegard marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture(scope="function")
def testing_workdir(monkeypatch: MonkeyPatch, tmp_path: Path) -> Iterator[str]:
Expand Down
26 changes: 26 additions & 0 deletions tests/test_inspect_pkg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (C) 2014 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
from __future__ import annotations

import pytest
from conda import __version__ as conda_version
from conda.core.prefix_data import PrefixData
from packaging.version import Version, parse

from conda_build.inspect_pkg import which_package

if TYPE_CHECKING := False:
from conda.testing import TmpEnvFixture


@pytest.mark.skipif(
parse(conda_version) < Version("23.5.0"),
reason="tmp_env fixture first available in conda 23.5.0",
)
def test_which_package(tmp_env: TmpEnvFixture):
with tmp_env("ca-certificates") as prefix:
pd = PrefixData(prefix)
prec = pd.get("ca-certificates")
precs = list(which_package(prefix / prec.files[0], prefix))
kenodegard marked this conversation as resolved.
Show resolved Hide resolved
assert len(precs) == 1
assert precs[0] == prec
Loading