Skip to content
New issue

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

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

Already on GitHub? # to your account

Expose the components kwarg in the CLI and API #253

Merged
merged 5 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions news/253-components-list
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Enhancements

* Expose API and CLI for which components will be listed as part of `cph list`. (#253)

### Bug fixes

* <news item>

### Deprecations

* <news item>

### Docs

* <news item>

### Other

* <news item>
7 changes: 4 additions & 3 deletions src/conda_package_handling/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .exceptions import ConversionError, InvalidArchiveError # NOQA
from .interface import AbstractBaseFormat
from .tarball import CondaTarBZ2 as _CondaTarBZ2
from .utils import filter_info_files
from .utils import ensure_list, filter_info_files
from .utils import get_executor as _get_executor
from .utils import rm_rf as _rm_rf

Expand Down Expand Up @@ -227,8 +227,9 @@ def get_pkg_details(in_file):
raise ValueError(f"Don't know what to do with file {in_file}")


def list_contents(in_file, verbose=False):
def list_contents(in_file, verbose=False, components=None):
components = ensure_list(components or ("info", "pkg"))
for format in SUPPORTED_EXTENSIONS.values():
if format.supported(in_file):
return format.list_contents(in_file, verbose=verbose)
return format.list_contents(in_file, verbose=verbose, components=components)
raise ValueError(f"Don't know what to do with file {in_file}")
12 changes: 11 additions & 1 deletion src/conda_package_handling/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ def build_parser():
action="store_true",
help="Report more details, similar to 'ls -l'. Otherwise, only the filenames are printed.",
)
list_parser.add_argument(
"--components",
dest="components",
default="info,pkg",
help="Comma-separated list of components to read (.conda artifacts only; "
"ignored for .tar.bz2). Allowed values: info, pkg.",
)

return parser

Expand Down Expand Up @@ -148,7 +155,10 @@ def main(args=None):
pprint(failed_files)
sys.exit(1)
elif args.subcommand in ("list", "l"):
api.list_contents(args.archive_path, verbose=args.verbose)
components = [
component.strip() for component in (args.components or "info,pkg").split(",")
]
api.list_contents(args.archive_path, verbose=args.verbose, components=components)


if __name__ == "__main__": # pragma: no cover
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ def test_list(artifact, n_files, capsys):

with pytest.raises(ValueError):
cli.main(["list", "setup.py"])

cli.main(["list", os.path.join(data_dir, artifact), "--components=pkg"])
stdout, stderr = capsys.readouterr()
listed_files = sum(bool(line.strip()) for line in stdout.splitlines())
if artifact.endswith(".conda"):
assert listed_files < n_files # info folder filtered out
else:
assert listed_files == n_files # no info filtering in tar.bz2
Loading