-
Notifications
You must be signed in to change notification settings - Fork 427
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
Changes from 6 commits
20d0a12
7998d33
3f19216
f955083
2ce0e20
904078a
424e1f2
89c7bc8
496092c
05785c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1187,9 +1187,7 @@ def _lookup_in_prefix_packages( | |
if len(precs_in_reqs) == 1: | ||
_print_msg( | ||
errors, | ||
"{}: {} found in {}{}".format( | ||
info_prelude, n_dso_p, precs_in_reqs[0], and_also | ||
), | ||
f"{info_prelude}: {n_dso_p} found in {precs_in_reqs[0]}{and_also}", | ||
verbose=verbose, | ||
) | ||
elif in_whitelist: | ||
|
@@ -1201,25 +1199,20 @@ def _lookup_in_prefix_packages( | |
elif len(precs_in_reqs) == 0 and len(precs) > 0: | ||
_print_msg( | ||
errors, | ||
"{}: {} found in {}{}".format( | ||
msg_prelude, n_dso_p, [prec.name for prec in precs], and_also | ||
), | ||
f"{msg_prelude}: {n_dso_p} found in {[str(prec) for prec in precs]}{and_also}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This upgrades from name to the full str representation. i.e. from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this is now more detailed (but still less verbose than the change was inspired by the fix below on line 1214-1215, where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's good that this is now more consistent with the full spec which was already output at https://github.com/conda/conda-build/pull/5108/files#diff-5073339a2e88f80714f82a001af334869aa5df9627b2f00ffd18d7a2035f537eR1190 . |
||
verbose=verbose, | ||
) | ||
_print_msg( | ||
errors, | ||
"{}: .. but {} not in reqs/run, (i.e. it is overlinking)" | ||
" (likely) or a missing dependency (less likely)".format( | ||
msg_prelude, [prec.name for prec in precs] | ||
), | ||
f"{msg_prelude}: .. but {[str(prec) for prec in precs]} not in reqs/run, " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I find the change to use But I don't have a strong opinion on this one. |
||
"(i.e. it is overlinking) (likely) or a missing dependency (less likely)", | ||
verbose=verbose, | ||
) | ||
elif len(precs_in_reqs) > 1: | ||
_print_msg( | ||
errors, | ||
"{}: {} found in multiple packages in run/reqs: {}{}".format( | ||
warn_prelude, in_prefix_dso, precs_in_reqs, and_also | ||
), | ||
f"{warn_prelude}: {in_prefix_dso} found in multiple packages in run/reqs: " | ||
f"{[str(prec) for prec in precs_in_reqs]}{and_also}", | ||
verbose=verbose, | ||
) | ||
else: | ||
|
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# Copyright (C) 2014 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import annotations | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
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 | ||
|
||
|
||
@pytest.mark.skipif( | ||
parse(conda_version) < Version("23.5.0"), | ||
reason="tmp_env fixture first available in conda 23.5.0", | ||
) | ||
kenodegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_which_package(tmp_path: Path): | ||
# create a dummy environment | ||
(tmp_path / "conda-meta").mkdir() | ||
(tmp_path / "conda-meta" / "history").touch() | ||
# a dummy package with a unique file (softlink) and a shared file (shared) | ||
kenodegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(tmp_path / "conda-meta" / "packageA-1-0.json").write_text( | ||
json.dumps( | ||
{ | ||
"build": "0", | ||
"build_number": 0, | ||
"channel": "packageA-channel", | ||
"files": ["softlink", "shared"], | ||
"name": "packageA", | ||
"paths_data": { | ||
"paths": [ | ||
{ | ||
"_path": "softlink", | ||
"path_type": "softlink", | ||
"size_in_bytes": 0, | ||
}, | ||
{ | ||
"_path": "shared", | ||
"path_type": "hardlink", | ||
"size_in_bytes": 0, | ||
}, | ||
], | ||
"paths_version": 1, | ||
}, | ||
"version": "1", | ||
} | ||
) | ||
) | ||
# a dummy package with a unique file (hardlink) and a shared file (shared) | ||
kenodegard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(tmp_path / "conda-meta" / "packageB-1-0.json").write_text( | ||
json.dumps( | ||
{ | ||
"build": "0", | ||
"build_number": 0, | ||
"channel": "packageB-channel", | ||
"files": ["hardlink", "shared"], | ||
"name": "packageB", | ||
"paths_data": { | ||
"paths": [ | ||
{ | ||
"_path": "hardlink", | ||
"path_type": "hardlink", | ||
"size_in_bytes": 0, | ||
}, | ||
{ | ||
"_path": "shared", | ||
"path_type": "hardlink", | ||
"size_in_bytes": 0, | ||
}, | ||
], | ||
"paths_version": 1, | ||
}, | ||
"version": "1", | ||
} | ||
) | ||
) | ||
|
||
# fetch package records | ||
pd = PrefixData(tmp_path) | ||
precA = pd.get("packageA") | ||
precB = pd.get("packageB") | ||
|
||
# test returned package records given a path | ||
precs_missing = list(which_package(tmp_path / "missing", tmp_path)) | ||
assert not precs_missing | ||
|
||
precs_softlink = list(which_package(tmp_path / "softlink", tmp_path)) | ||
assert len(precs_softlink) == 1 | ||
assert precs_softlink[0] == precA | ||
|
||
precs_hardlink = list(which_package(tmp_path / "hardlink", tmp_path)) | ||
assert len(precs_hardlink) == 1 | ||
assert precs_hardlink[0] == precB | ||
|
||
precs_shared = list(which_package(tmp_path / "shared", tmp_path)) | ||
assert len(precs_shared) == 2 | ||
assert precs_shared == [precB, precA] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 firstTrue
: https://docs.python.org/3/library/functions.html#anyThere was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, this is essentially what was happening pre #5041:
conda-build/conda_build/inspect_pkg.py
Lines 57 to 62 in c71c4ab
definitely something to consider