Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit with the exit code from a app when run() #68

Merged
merged 10 commits into from Jan 24, 2024
Merged
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)
- 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)
Expand Down
25 changes: 25 additions & 0 deletions 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
```
19 changes: 19 additions & 0 deletions 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
7 changes: 7 additions & 0 deletions 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
10 changes: 3 additions & 7 deletions scif/main/commands.py
Expand Up @@ -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):
Expand Down Expand Up @@ -173,7 +170,6 @@ def run(self, app=None, args=None):
# updates environment
# sets entrypoint
# sets entryfolder

return self._exec(app, interactive=interactive)


Expand Down
2 changes: 1 addition & 1 deletion scif/version.py
Expand Up @@ -10,7 +10,7 @@

"""

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