Skip to content

Commit b746a81

Browse files
authored
Merge pull request #177 from singularityhub/fix/pull-output-bug
Fixing changed behavior with singularity pull
2 parents 7701dbb + 8cc1fed commit b746a81

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
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+
- choose output for stream_command (0.0.14)
2021
- adding support to pull from a url (0.1.13)
2122
- add more verbosity to instance start/stop (0.1.12)
2223
- adding more verbosity to running commands (0.1.11)

spython/main/pull.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ def pull(
9797

9898
# Option 3: A custom name we can predict (not commit/hash) and can also show
9999
else:
100-
return final_image, stream_command(cmd, sudo=False)
100+
101+
# As of Singularity 3.x (at least 3.8) output goes to stderr
102+
return final_image, stream_command(cmd, sudo=False, output_type="stderr")
101103

102104
if os.path.exists(final_image) and not quiet:
103105
bot.info(final_image)

spython/utils/terminal.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,13 @@ def get_installdir():
110110
return os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
111111

112112

113-
def stream_command(cmd, no_newline_regexp="Progess", sudo=False, sudo_options=None):
113+
def stream_command(
114+
cmd,
115+
no_newline_regexp="Progess",
116+
sudo=False,
117+
sudo_options=None,
118+
output_type="stdout",
119+
):
114120
"""stream a command (yield) back to the user, as each line is available.
115121
116122
# Example usage:
@@ -127,14 +133,25 @@ def stream_command(cmd, no_newline_regexp="Progess", sudo=False, sudo_options=No
127133
sudo_options: string or list of strings that will be passed as options to sudo
128134
129135
"""
136+
if output_type not in ["stdout", "stderr"]:
137+
bot.exit("Invalid output type %s. Must be stderr or stdout." % output_type)
130138
cmd = _process_sudo_cmd(cmd, sudo, sudo_options)
131139

132140
process = subprocess.Popen(
133141
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True
134142
)
135-
for line in iter(process.stdout.readline, ""):
143+
144+
# Allow the runner to choose streaming output or error
145+
stream = process.stdout.readline
146+
if output_type == "stderr":
147+
stream = process.stderr.readline
148+
149+
# Stream lines back to the caller
150+
for line in iter(stream, ""):
136151
if not re.search(no_newline_regexp, line):
137152
yield line
153+
154+
# If there is an error, raise.
138155
process.stdout.close()
139156
return_code = process.wait()
140157
if return_code:

spython/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
66

77

8-
__version__ = "0.1.13"
8+
__version__ = "0.1.14"
99
AUTHOR = "Vanessa Sochat"
1010
AUTHOR_EMAIL = "[email protected]"
1111
NAME = "spython"

0 commit comments

Comments
 (0)