Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ To see which commands this would evaluate, just run `eessi init`.

Create subshell in which EESSI is available and initialised

*(to be implemented)*
```shell
eessi shell --eessi-version 2025.06
```

You *must* specify the EESSI version to use, there is no default value for this.

## Design goals

Expand Down
23 changes: 19 additions & 4 deletions src/eessi/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,35 @@
import tempfile
import typer
from rich import print as rich_print
from typing import Annotated

app = typer.Typer()


def report_error(msg, exit_code: int = 1):
"""
Report error and exit with specified non-zero exit code
"""
rich_print(f"[bold red]{msg}", file=sys.stderr)
if exit_code <= 0:
raise ValueError(f"Exit code should be positive non-zero integer, got {exit_code}")
sys.exit(exit_code)


@app.command()
def shell():
def shell(
eessi_version: Annotated[str, typer.Option(help="EESSI version")] = '',
):
"""
Create subshell in which EESSI is available and initialised
"""
if not eessi_version:
report_error("EESSI version to use is not specified, which is required!")

init_file = tempfile.mkstemp()[1]
with open(init_file, 'w') as fp:
fp.write("set -e; source /cvmfs/software.eessi.io/versions/2023.06/init/bash")
fp.write(f"set -e; source /cvmfs/software.eessi.io/versions/{eessi_version}/init/bash")

res = subprocess.run(['/bin/bash', '--init-file', init_file])
if res.returncode != 0:
rich_print("[bold red]ERROR: Non-zero exit code detected for interactive shell!", file=sys.stderr)
sys.exit(res.returncode)
report_error("ERROR: Non-zero exit code detected for interactive shell!", exit_code=res.returncode)