From 5e231bdac142cd5a3fa722faa2b2cc3f94c2b28f Mon Sep 17 00:00:00 2001 From: vsoch Date: Sat, 20 Mar 2021 13:19:26 -0600 Subject: [PATCH 1/2] adding more verbosity for running commands If the user provides quiet=False, we should see the full command that is generated for singularity python Signed-off-by: vsoch --- CHANGELOG.md | 1 + spython/main/build.py | 4 ++++ spython/main/execute.py | 9 +++++++++ spython/main/inspect.py | 5 +++++ spython/main/instances.py | 9 +++++++++ spython/main/run.py | 9 ++++++++- spython/version.py | 4 ++-- 7 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13b9958..14977d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to singularity on pypi), and the versions here will coincide with these releases. ## [master](https://github.com/singularityhub/singularity-cli/tree/master) + - adding more verbosity to running commands (0.0.11) - log error paths are optional (0.1.1) - instance list doesn't always include container_image (0.1.0) - add sudo_options option to Instance.start/stop and Client.execute (0.0.85) diff --git a/spython/main/build.py b/spython/main/build.py index b3a7487..b379fab 100644 --- a/spython/main/build.py +++ b/spython/main/build.py @@ -109,6 +109,10 @@ def build( cmd = cmd + options + [image, recipe] + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + if not stream: self._run_command( cmd, diff --git a/spython/main/execute.py b/spython/main/execute.py index 8d09237..53e456e 100644 --- a/spython/main/execute.py +++ b/spython/main/execute.py @@ -99,6 +99,10 @@ def execute( cmd = cmd + [image] + command + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + if not stream: return self._run_command( cmd, @@ -124,6 +128,7 @@ def shell( options=None, singularity_options=None, sudo=False, + quiet=True, ): """shell into a container. A user is advised to use singularity to do this directly, however this function is useful for supporting tools. @@ -172,6 +177,10 @@ def shell( cmd.append(image) singularity = which("singularity") + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + if writable or sudo: os.execvp("sudo", ["sudo"] + cmd) diff --git a/spython/main/inspect.py b/spython/main/inspect.py index ac8bc2f..64e6e89 100644 --- a/spython/main/inspect.py +++ b/spython/main/inspect.py @@ -52,6 +52,11 @@ def inspect( cmd.append("--json") cmd.append(image) + + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + result = run_command(cmd, quiet=quiet) if result["return_code"] == 0: diff --git a/spython/main/instances.py b/spython/main/instances.py index 2d8c395..8023e1a 100644 --- a/spython/main/instances.py +++ b/spython/main/instances.py @@ -55,6 +55,10 @@ def list_instances( if name is not None: cmd.append(name) + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + output = run_command(cmd, quiet=True, sudo=sudo, sudo_options=sudo_options) instances = [] @@ -126,6 +130,11 @@ def stopall(self, sudo=False, quiet=True, singularity_options=None): cmd = self._init_command(subgroup, singularity_options) cmd = cmd + ["--all"] + + # Does the user want to see the command printed? + if not (quiet or self.quiet): + bot.info(" ".join(cmd)) + output = run_command(cmd, sudo=sudo, quiet=quiet) if output["return_code"] != 0: diff --git a/spython/main/run.py b/spython/main/run.py index 7e9be6b..fa03349 100644 --- a/spython/main/run.py +++ b/spython/main/run.py @@ -24,6 +24,7 @@ def run( options=None, singularity_options=None, return_result=False, + quiet=False, ): """ run will run the container, with or withour arguments (which @@ -46,7 +47,7 @@ def run( nv: if True, load Nvidia Drivers in runtime (default False) return_result: if True, return entire json object with return code and message result (default is False) - + quiet: print the command to the user """ from spython.utils import check_install @@ -54,6 +55,9 @@ def run( cmd = self._init_command("run", singularity_options) + # Does the user want to see the command printed? + quiet = quiet or self.quiet + # nv option leverages any GPU cards if nv: cmd += ["--nv"] @@ -93,6 +97,9 @@ def run( args = args.split(" ") cmd = cmd + args + if not quiet: + bot.info(" ".join(cmd)) + if not stream: result = self._run_command(cmd, sudo=sudo, return_result=return_result) else: diff --git a/spython/version.py b/spython/version.py index 6777621..50a5647 100644 --- a/spython/version.py +++ b/spython/version.py @@ -5,11 +5,11 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -__version__ = "0.1.1" +__version__ = "0.1.11" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsochat@stanford.edu" NAME = "spython" -PACKAGE_URL = "http://www.github.com/singularityhub/singularity-cli" +PACKAGE_URL = "http://github.com/singularityhub/singularity-cli" KEYWORDS = "singularity python client (spython)" DESCRIPTION = "Command line python tool for working with singularity." LICENSE = "LICENSE" From 4b0191d97eab18e8dc0d11e587d1fa0439ae654d Mon Sep 17 00:00:00 2001 From: vsoch Date: Sat, 20 Mar 2021 13:21:35 -0600 Subject: [PATCH 2/2] adding docstrings Signed-off-by: vsoch --- CHANGELOG.md | 2 +- spython/main/execute.py | 2 ++ spython/version.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14977d7..a0a4db1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ The client here will eventually be released as "spython" (and eventually to singularity on pypi), and the versions here will coincide with these releases. ## [master](https://github.com/singularityhub/singularity-cli/tree/master) - - adding more verbosity to running commands (0.0.11) + - adding more verbosity to running commands (0.1.11) - log error paths are optional (0.1.1) - instance list doesn't always include container_image (0.1.0) - add sudo_options option to Instance.start/stop and Client.execute (0.0.85) diff --git a/spython/main/execute.py b/spython/main/execute.py index 53e456e..55039b6 100644 --- a/spython/main/execute.py +++ b/spython/main/execute.py @@ -48,6 +48,8 @@ def execute( nv: if True, load Nvidia Drivers in runtime (default False) return_result: if True, return entire json object with return code and message result not (default) + quiet: Do not print verbose output. + environ: extra environment to add. """ from spython.utils import check_install diff --git a/spython/version.py b/spython/version.py index 50a5647..c0c3583 100644 --- a/spython/version.py +++ b/spython/version.py @@ -9,7 +9,7 @@ AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsochat@stanford.edu" NAME = "spython" -PACKAGE_URL = "http://github.com/singularityhub/singularity-cli" +PACKAGE_URL = "https://github.com/singularityhub/singularity-cli" KEYWORDS = "singularity python client (spython)" DESCRIPTION = "Command line python tool for working with singularity." LICENSE = "LICENSE"