diff --git a/CHANGELOG.md b/CHANGELOG.md index ac847c9..f6db124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) + - return exit code of app in run command (0.0.82) - install return value non zero should stop build (0.0.81) - removing Python less than 3.6 support (0.0.80) - code formatting with black, shell entrypoint bug (0.0.79) diff --git a/docs/examples/exit-from-run/README.md b/docs/examples/exit-from-run/README.md new file mode 100644 index 0000000..678f66b --- /dev/null +++ b/docs/examples/exit-from-run/README.md @@ -0,0 +1,25 @@ +# Exit Code from run + +This should be built from the root of the repository as follows: + +``` +# apptainer build scif.sif docs/examples/exit-from-run/apptainer.def +``` + +The force_fail app returns exit code 155 +``` +$ apptainer run scif.sif run force_fail ; echo "Exit Code: $?"; +[force_fail] executing /bin/bash /scif/apps/force_fail/scif/runscript +Calling exit 155 +ERROR Return code 155 +Exit Code: 155 +``` + +The 'success' app returns exit code 0 + +``` +$ apptainer run scif.sif run success ; echo "Exit Code: $?"; +[success] executing /bin/bash /scif/apps/success/scif/runscript +Running successfully +Exit Code: 0 +``` diff --git a/docs/examples/exit-from-run/apptainer.def b/docs/examples/exit-from-run/apptainer.def new file mode 100644 index 0000000..5e2db1b --- /dev/null +++ b/docs/examples/exit-from-run/apptainer.def @@ -0,0 +1,19 @@ +Bootstrap: docker +From: continuumio/miniconda3 + +# apptainer build scif.simg docs/examples/exit-from-run/apptainer.def + +%runscript + exec /opt/conda/bin/scif "$@" + +%files + docs/examples/exit-from-run/recipe.scif /recipe.scif + . /opt/scif +%post + apt-get update && apt-get install -y git build-essential + + # Install SCIF + cd /opt/scif + /opt/conda/bin/pip install setuptools + /opt/conda/bin/pip install . + scif install /recipe.scif diff --git a/docs/examples/exit-from-run/recipe.scif b/docs/examples/exit-from-run/recipe.scif new file mode 100644 index 0000000..7b703b4 --- /dev/null +++ b/docs/examples/exit-from-run/recipe.scif @@ -0,0 +1,7 @@ +%apprun force_fail +echo "Calling exit 155" +exit 155 + +%apprun success +echo "Running successfully" +exit 0 diff --git a/scif/main/commands.py b/scif/main/commands.py index 739f725..5dd1801 100644 --- a/scif/main/commands.py +++ b/scif/main/commands.py @@ -87,13 +87,10 @@ def _exec(self, app=None, interactive=False, exit=False): sys.exit(result["return_code"]) else: os.system("".join(cmd)) - else: - for line in os.popen(cmd): - try: - print(line.rstrip()) - except: - print(line.rstrip().encode(loc)) + cmd = cmd.split(" ") + result = self._run_command(cmd=cmd, spinner=False, quiet=False) + sys.exit(result["return_code"]) def execute(self, app, cmd=None, args=None): @@ -173,7 +170,6 @@ def run(self, app=None, args=None): # updates environment # sets entrypoint # sets entryfolder - return self._exec(app, interactive=interactive) diff --git a/scif/version.py b/scif/version.py index 088a3fb..0cf6dc1 100644 --- a/scif/version.py +++ b/scif/version.py @@ -10,7 +10,7 @@ """ -__version__ = "0.0.81" +__version__ = "0.0.82" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsochat@stanford.edu" NAME = "scif"