Skip to content

Commit d17ed1e

Browse files
authored
adding more verbosity for running commands (#173)
* adding more verbosity for running commands If the user provides quiet=False, we should see the full command that is generated for singularity python * adding docstrings Signed-off-by: vsoch <[email protected]>
1 parent 689fcde commit d17ed1e

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to
1717
singularity on pypi), and the versions here will coincide with these releases.
1818

1919
## [master](https://github.com/singularityhub/singularity-cli/tree/master)
20+
- adding more verbosity to running commands (0.1.11)
2021
- log error paths are optional (0.1.1)
2122
- instance list doesn't always include container_image (0.1.0)
2223
- add sudo_options option to Instance.start/stop and Client.execute (0.0.85)

spython/main/build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ def build(
109109

110110
cmd = cmd + options + [image, recipe]
111111

112+
# Does the user want to see the command printed?
113+
if not (quiet or self.quiet):
114+
bot.info(" ".join(cmd))
115+
112116
if not stream:
113117
self._run_command(
114118
cmd,

spython/main/execute.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def execute(
4848
nv: if True, load Nvidia Drivers in runtime (default False)
4949
return_result: if True, return entire json object with return code
5050
and message result not (default)
51+
quiet: Do not print verbose output.
52+
environ: extra environment to add.
5153
"""
5254
from spython.utils import check_install
5355

@@ -99,6 +101,10 @@ def execute(
99101

100102
cmd = cmd + [image] + command
101103

104+
# Does the user want to see the command printed?
105+
if not (quiet or self.quiet):
106+
bot.info(" ".join(cmd))
107+
102108
if not stream:
103109
return self._run_command(
104110
cmd,
@@ -124,6 +130,7 @@ def shell(
124130
options=None,
125131
singularity_options=None,
126132
sudo=False,
133+
quiet=True,
127134
):
128135
"""shell into a container. A user is advised to use singularity to do
129136
this directly, however this function is useful for supporting tools.
@@ -172,6 +179,10 @@ def shell(
172179
cmd.append(image)
173180
singularity = which("singularity")
174181

182+
# Does the user want to see the command printed?
183+
if not (quiet or self.quiet):
184+
bot.info(" ".join(cmd))
185+
175186
if writable or sudo:
176187
os.execvp("sudo", ["sudo"] + cmd)
177188

spython/main/inspect.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def inspect(
5252
cmd.append("--json")
5353

5454
cmd.append(image)
55+
56+
# Does the user want to see the command printed?
57+
if not (quiet or self.quiet):
58+
bot.info(" ".join(cmd))
59+
5560
result = run_command(cmd, quiet=quiet)
5661

5762
if result["return_code"] == 0:

spython/main/instances.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def list_instances(
5555
if name is not None:
5656
cmd.append(name)
5757

58+
# Does the user want to see the command printed?
59+
if not (quiet or self.quiet):
60+
bot.info(" ".join(cmd))
61+
5862
output = run_command(cmd, quiet=True, sudo=sudo, sudo_options=sudo_options)
5963
instances = []
6064

@@ -126,6 +130,11 @@ def stopall(self, sudo=False, quiet=True, singularity_options=None):
126130

127131
cmd = self._init_command(subgroup, singularity_options)
128132
cmd = cmd + ["--all"]
133+
134+
# Does the user want to see the command printed?
135+
if not (quiet or self.quiet):
136+
bot.info(" ".join(cmd))
137+
129138
output = run_command(cmd, sudo=sudo, quiet=quiet)
130139

131140
if output["return_code"] != 0:

spython/main/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def run(
2424
options=None,
2525
singularity_options=None,
2626
return_result=False,
27+
quiet=False,
2728
):
2829
"""
2930
run will run the container, with or withour arguments (which
@@ -46,14 +47,17 @@ def run(
4647
nv: if True, load Nvidia Drivers in runtime (default False)
4748
return_result: if True, return entire json object with return code
4849
and message result (default is False)
49-
50+
quiet: print the command to the user
5051
"""
5152
from spython.utils import check_install
5253

5354
check_install()
5455

5556
cmd = self._init_command("run", singularity_options)
5657

58+
# Does the user want to see the command printed?
59+
quiet = quiet or self.quiet
60+
5761
# nv option leverages any GPU cards
5862
if nv:
5963
cmd += ["--nv"]
@@ -93,6 +97,9 @@ def run(
9397
args = args.split(" ")
9498
cmd = cmd + args
9599

100+
if not quiet:
101+
bot.info(" ".join(cmd))
102+
96103
if not stream:
97104
result = self._run_command(cmd, sudo=sudo, return_result=return_result)
98105
else:

spython/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

77

8-
__version__ = "0.1.1"
8+
__version__ = "0.1.11"
99
AUTHOR = "Vanessa Sochat"
1010
AUTHOR_EMAIL = "[email protected]"
1111
NAME = "spython"
12-
PACKAGE_URL = "http://www.github.com/singularityhub/singularity-cli"
12+
PACKAGE_URL = "https://github.com/singularityhub/singularity-cli"
1313
KEYWORDS = "singularity python client (spython)"
1414
DESCRIPTION = "Command line python tool for working with singularity."
1515
LICENSE = "LICENSE"

0 commit comments

Comments
 (0)