Skip to content

Commit

Permalink
Reworked app.run exit code (#73)
Browse files Browse the repository at this point in the history
* allow run to return exit_code in non-interactive mode
* add tests for exit code from run.  Add variable substituion test for exec
* remove unneeded apptainer def
* bump version
* validate the substitution in test_exec.sh
  • Loading branch information
dmachi committed Jan 26, 2024
1 parent 2dca77e commit 3b00f6f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ represented by the pull requests that fixed them.
Versions in parentheses coincide with what is available on [pypi](https://pypi.org/project/scif/).

## [xxx](https://github.com/vsoch/scif/tree/master) (master)
- (re)add exit code to app.run (0.0.84)
- revert exit code to app.run until further notice (0.0.83)
- add exit code to app.run (0.0.82)
- install return value non zero should stop build (0.0.81)
Expand Down
3 changes: 3 additions & 0 deletions docs/hello-world.scif
Expand Up @@ -39,3 +39,6 @@
fi
echo "Argument supplied, exiting with ${1}"
exit ${1}
%apprun hello-world-exit-code
echo "Exiting with code 155"
exit 155
6 changes: 5 additions & 1 deletion scif/main/commands.py
Expand Up @@ -89,11 +89,15 @@ def _exec(self, app=None, interactive=False, exit=False):
os.system("".join(cmd))

else:
for line in os.popen(cmd):
f = os.popen(cmd)
for line in f.readlines():
try:
print(line.rstrip())
except:
print(line.rstrip().encode(loc))
status = f.close()
if status:
sys.exit(os.waitstatus_to_exitcode(status))


def execute(self, app, cmd=None, args=None):
Expand Down
8 changes: 8 additions & 0 deletions scif/tests/test_exec.sh
Expand Up @@ -6,3 +6,11 @@ echo "Testing exec of commands:"
docker run -it "${CONTAINER_NAME}" exec hello-world-echo echo "Hello World!"
docker run -it "${CONTAINER_NAME}" exec hello-world-script ls /
docker run -it "${CONTAINER_NAME}" exec hello-world-env env

OUT=$(docker run -it "${CONTAINER_NAME}" --quiet exec hello-world-env echo [e]OMG | tr -d '\n\t\r ')
if [ "$OUT" == "TACOS" ]; then
echo "Variable Substitution Success: $OUT"
else
echo "Variable subsitution for e[OMG] failed"
exit 1
fi
2 changes: 2 additions & 0 deletions scif/tests/test_run.sh
Expand Up @@ -7,3 +7,5 @@ docker run -it "${CONTAINER_NAME}" run hello-world-echo
docker run -it "${CONTAINER_NAME}" run hello-world-script
docker run -it "${CONTAINER_NAME}" run hello-world-custom "Meatball"
docker run -it "${CONTAINER_NAME}" run hello-world-env | echo "Success"
docker run -it "${CONTAINER_NAME}" run hello-world-exit-code ; echo "Exit code: $? [should be 155]"
docker run -it "${CONTAINER_NAME}" run hello-world-echo; echo "Exit code: $? [should be 0]"
2 changes: 1 addition & 1 deletion scif/version.py
Expand Up @@ -10,7 +10,7 @@
"""

__version__ = "0.0.83"
__version__ = "0.0.84"
AUTHOR = "Vanessa Sochat"
AUTHOR_EMAIL = "vsochat@stanford.edu"
NAME = "scif"
Expand Down

0 comments on commit 3b00f6f

Please sign in to comment.