-
Notifications
You must be signed in to change notification settings - Fork 428
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 all 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,20 @@ | ||
### 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
|
||
* Fix `conda_build.post._lookup_in_prefix_packages` to display `str(PackageRecord)` instead of `repr(PackageRecord)`. (#5108) | ||
|
||
### Deprecations | ||
|
||
* <news item> | ||
|
||
### Docs | ||
|
||
* <news item> | ||
|
||
### Other | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Copyright (C) 2014 Anaconda, Inc | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
from __future__ import annotations | ||
|
||
import json | ||
from pathlib import Path | ||
|
||
from conda.core.prefix_data import PrefixData | ||
|
||
from conda_build.inspect_pkg import which_package | ||
|
||
|
||
def test_which_package(tmp_path: Path): | ||
# create a dummy environment | ||
(tmp_path / "conda-meta").mkdir() | ||
(tmp_path / "conda-meta" / "history").touch() | ||
|
||
# dummy files | ||
(tmp_path / "hardlinkA").touch() # packageA | ||
(tmp_path / "shared").touch() # packageA & packageB | ||
(tmp_path / "internal").symlink_to(tmp_path / "hardlinkA") # packageA | ||
(tmp_path / "external").symlink_to(tmp_path / "hardlinkB") # packageA | ||
(tmp_path / "hardlinkB").touch() # packageB | ||
|
||
# a dummy package with a hardlink file, shared file, internal softlink, and external softlink | ||
(tmp_path / "conda-meta" / "packageA-1-0.json").write_text( | ||
json.dumps( | ||
{ | ||
"build": "0", | ||
"build_number": 0, | ||
"channel": "packageA-channel", | ||
"files": ["hardlinkA", "shared", "internal", "external"], | ||
"name": "packageA", | ||
"paths_data": { | ||
"paths": [ | ||
{ | ||
"_path": "hardlinkA", | ||
"path_type": "hardlink", | ||
"size_in_bytes": 0, | ||
}, | ||
{ | ||
"_path": "shared", | ||
"path_type": "hardlink", | ||
"size_in_bytes": 0, | ||
}, | ||
{ | ||
"_path": "internal", | ||
"path_type": "softlink", | ||
"size_in_bytes": 0, | ||
}, | ||
{ | ||
"_path": "external", | ||
"path_type": "softlink", | ||
"size_in_bytes": 0, | ||
}, | ||
], | ||
"paths_version": 1, | ||
}, | ||
"version": "1", | ||
} | ||
) | ||
) | ||
# a dummy package with a hardlink file and shared file | ||
(tmp_path / "conda-meta" / "packageB-1-0.json").write_text( | ||
json.dumps( | ||
{ | ||
"build": "0", | ||
"build_number": 0, | ||
"channel": "packageB-channel", | ||
"files": ["hardlinkB", "shared"], | ||
"name": "packageB", | ||
"paths_data": { | ||
"paths": [ | ||
{ | ||
"_path": "hardlinkB", | ||
"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_hardlinkA = list(which_package(tmp_path / "hardlinkA", tmp_path)) | ||
assert len(precs_hardlinkA) == 1 | ||
assert precs_hardlinkA[0] == precA | ||
|
||
precs_shared = list(which_package(tmp_path / "shared", tmp_path)) | ||
assert len(precs_shared) == 2 | ||
assert set(precs_shared) == {precA, precB} | ||
|
||
precs_internal = list(which_package(tmp_path / "internal", tmp_path)) | ||
assert len(precs_internal) == 1 | ||
assert precs_internal[0] == precA | ||
|
||
precs_external = list(which_package(tmp_path / "external", tmp_path)) | ||
assert len(precs_external) == 2 | ||
assert set(precs_external) == {precA, precB} | ||
|
||
precs_hardlinkB = list(which_package(tmp_path / "hardlinkB", tmp_path)) | ||
assert len(precs_hardlinkB) == 2 | ||
assert set(precs_hardlinkB) == {precA, precB} |
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