Skip to content

Commit 52caaac

Browse files
authored
update shpc show output stream and support --limit (#647)
Signed-off-by: vsoch <[email protected]> Co-authored-by: vsoch <[email protected]>
1 parent f89a16d commit 52caaac

File tree

6 files changed

+41
-9
lines changed

6 files changed

+41
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and **Merged pull requests**. Critical items to know are:
1414
The versions coincide with releases on pip. Only major versions will be released as tags on Github.
1515

1616
## [0.0.x](https://github.com/singularityhub/singularity-hpc/tree/main) (0.0.x)
17+
- Do not write directly to output with shpc show (0.1.22)
1718
- Podman template bug (0.1.21)
1819
- Improvement to shpc help command output (0.1.2)
1920
- Support for remote registries on self-hosted Gitlab instances (0.1.19)

docs/getting_started/user-guide.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,6 +1100,12 @@ To filter down the result set, use ``--filter``:
11001100
biocontainers/bedtools
11011101
biocontainers/tpp
11021102
1103+
Set a limit of results with `--limit`:
1104+
1105+
.. code-block:: console
1106+
1107+
$ shpc show --filter bio --limit 5
1108+
11031109
11041110
To get details about a package, you would then add it's name to show:
11051111

shpc/client/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ def get_parser():
446446
default=None,
447447
dest="filter_string",
448448
)
449+
show.add_argument(
450+
"-l",
451+
"--limit",
452+
help="set a limit for the number to show",
453+
default=None,
454+
type=int,
455+
)
449456

450457
for command in docgen, show, add, remove, sync:
451458
command.add_argument(

shpc/client/show.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ def main(args, parser, extra, subparser):
1919
if args.registry:
2020
cli.settings.registry = [args.registry]
2121
cli.reload_registry()
22-
cli.show(args.name, names_only=not args.versions, filter_string=args.filter_string)
22+
cli.show(
23+
args.name,
24+
names_only=not args.versions,
25+
filter_string=args.filter_string,
26+
limit=args.limit,
27+
)

shpc/main/client.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import shutil
8-
import sys
98

109
import shpc.main.container as container
1110
import shpc.main.registry as registry
@@ -228,7 +227,7 @@ def docgen(self, module_name, registry=None):
228227
"""
229228
raise NotImplementedError
230229

231-
def show(self, name, names_only=False, out=None, filter_string=None):
230+
def show(self, name, names_only=False, out=None, filter_string=None, limit=None):
232231
"""
233232
Show available packages
234233
"""
@@ -237,13 +236,27 @@ def show(self, name, names_only=False, out=None, filter_string=None):
237236
config = self._load_container(name)
238237
config.dump(out)
239238
else:
240-
out = out or sys.stdout
239+
# Assemble the list of contents to write
240+
modules = []
241+
for i, entry in enumerate(
242+
self.registry.iter_registry(filter_string=filter_string)
243+
):
244+
# Break after the limit
245+
if limit and i > limit:
246+
break
241247

242-
# List the known registry modules
243-
for entry in self.registry.iter_registry(filter_string=filter_string):
244248
config = container.ContainerConfig(entry)
245249
if names_only:
246-
out.write("%s\n" % config.name)
250+
if out is None:
251+
print(config.name)
252+
modules.append(config.name)
247253
else:
248254
for version in config.tags.keys():
249-
out.write("%s:%s\n" % (config.name, version))
255+
module = "%s:%s" % (config.name, version)
256+
if out is None:
257+
print(module)
258+
modules.append(module)
259+
260+
# Write output to file or print to terminal
261+
if out is not None:
262+
utils.write_file(out, "\n".join(modules))

shpc/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__copyright__ = "Copyright 2021-2023, Vanessa Sochat"
33
__license__ = "MPL 2.0"
44

5-
__version__ = "0.1.21"
5+
__version__ = "0.1.22"
66
AUTHOR = "Vanessa Sochat"
77
88
NAME = "singularity-hpc"

0 commit comments

Comments
 (0)