Skip to content

Commit

Permalink
update shpc show output stream and support --limit (#647)
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <[email protected]>
Co-authored-by: vsoch <[email protected]>
  • Loading branch information
vsoch and vsoch authored May 4, 2023
1 parent f89a16d commit 52caaac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
- Do not write directly to output with shpc show (0.1.22)
- Podman template bug (0.1.21)
- Improvement to shpc help command output (0.1.2)
- Support for remote registries on self-hosted Gitlab instances (0.1.19)
Expand Down
6 changes: 6 additions & 0 deletions docs/getting_started/user-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,12 @@ To filter down the result set, use ``--filter``:
biocontainers/bedtools
biocontainers/tpp
Set a limit of results with `--limit`:

.. code-block:: console
$ shpc show --filter bio --limit 5
To get details about a package, you would then add it's name to show:

Expand Down
7 changes: 7 additions & 0 deletions shpc/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ def get_parser():
default=None,
dest="filter_string",
)
show.add_argument(
"-l",
"--limit",
help="set a limit for the number to show",
default=None,
type=int,
)

for command in docgen, show, add, remove, sync:
command.add_argument(
Expand Down
7 changes: 6 additions & 1 deletion shpc/client/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ def main(args, parser, extra, subparser):
if args.registry:
cli.settings.registry = [args.registry]
cli.reload_registry()
cli.show(args.name, names_only=not args.versions, filter_string=args.filter_string)
cli.show(
args.name,
names_only=not args.versions,
filter_string=args.filter_string,
limit=args.limit,
)
27 changes: 20 additions & 7 deletions shpc/main/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import os
import shutil
import sys

import shpc.main.container as container
import shpc.main.registry as registry
Expand Down Expand Up @@ -228,7 +227,7 @@ def docgen(self, module_name, registry=None):
"""
raise NotImplementedError

def show(self, name, names_only=False, out=None, filter_string=None):
def show(self, name, names_only=False, out=None, filter_string=None, limit=None):
"""
Show available packages
"""
Expand All @@ -237,13 +236,27 @@ def show(self, name, names_only=False, out=None, filter_string=None):
config = self._load_container(name)
config.dump(out)
else:
out = out or sys.stdout
# Assemble the list of contents to write
modules = []
for i, entry in enumerate(
self.registry.iter_registry(filter_string=filter_string)
):
# Break after the limit
if limit and i > limit:
break

# List the known registry modules
for entry in self.registry.iter_registry(filter_string=filter_string):
config = container.ContainerConfig(entry)
if names_only:
out.write("%s\n" % config.name)
if out is None:
print(config.name)
modules.append(config.name)
else:
for version in config.tags.keys():
out.write("%s:%s\n" % (config.name, version))
module = "%s:%s" % (config.name, version)
if out is None:
print(module)
modules.append(module)

# Write output to file or print to terminal
if out is not None:
utils.write_file(out, "\n".join(modules))
2 changes: 1 addition & 1 deletion shpc/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__copyright__ = "Copyright 2021-2023, Vanessa Sochat"
__license__ = "MPL 2.0"

__version__ = "0.1.21"
__version__ = "0.1.22"
AUTHOR = "Vanessa Sochat"
EMAIL = "[email protected]"
NAME = "singularity-hpc"
Expand Down

0 comments on commit 52caaac

Please sign in to comment.