# slurm_script_generator.salloc

*module*

Turn a batch script into an interactive allocation.

``slurm-alloc job.sh`` reads the ``#SBATCH`` pragmas out of a script and starts
``salloc`` with the same resource request, so the job can be debugged
interactively on the nodes it would have run on. With ``--run`` the body of the
script is executed inside the allocation instead of dropping into a shell.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L1-L1)

## slurm_script_generator.salloc.SALLOC_OPTIONS

*attribute* · *module attribute*

```python
SALLOC_OPTIONS = frozenset({'--account', '--acctg-freq', '--bb', '--bbf', '--begin', '--bell', '--chdir', '--cluster-constraint', '--clusters', '--comment', '--consolidate-segments', '--constraint', '--container', '--container-id', '--container-type', '--contiguous', '--core-spec', '--cores-per-socket', '--cpu-freq', '--cpus-per-gpu', '--cpus-per-task', '--deadline', '--delay-boot', '--dependency', '--distribution', '--exclude', '--exclusive', '--extra', '--extra-node-info', '--gpu-bind', '--gpu-freq', '--gpus', '--gpus-per-node', '--gpus-per-socket', '--gpus-per-task', '--gres', '--gres-flags', '--hint', '--hold', '--immediate', '--job-name', '--kill-command', '--licenses', '--mail-type', '--mail-user', '--mcs-label', '--mem', '--mem-bind', '--mem-per-cpu', '--mem-per-gpu', '--mem-update', '--mincpus', '--network', '--nice', '--no-bell', '--no-kill', '--no-shell', '--nodefile', '--nodelist', '--nodes', '--ntasks', '--ntasks-per-core', '--ntasks-per-gpu', '--ntasks-per-node', '--ntasks-per-socket', '--oom-kill-step', '--overcommit', '--oversubscribe', '--partition', '--prefer', '--priority', '--profile', '--qos', '--quiet', '--reboot', '--reservation', '--resources', '--resv-ports', '--segment', '--signal', '--sockets-per-node', '--spread-job', '--spread-segments', '--stepmgr', '--switches', '--thread-spec', '--threads-per-core', '--time', '--time-min', '--tmp', '--tres-bind', '--tres-per-task', '--use-min-nodes', '--verbose', '--wait-all-nodes', '--wckey', '--x11'})
```

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L24-L124)

## slurm_script_generator.salloc.build_command

*function*

```python
def build_command(path: str, run: bool = False, extra_args: List[str] | None = None) -> Tuple[List[str], str | None]
```

Build the salloc command for a batch script.

**Parameters**

- `path` (`str`) — Path to the batch script.
- `run` (`bool`) (default: `False`) — Whether to execute the script's commands in the allocation instead of starting an interactive shell.
- `extra_args` (`List[str] | None`) (default: `None`) — Additional arguments to append to the salloc invocation.

**Returns**

- (`Tuple[List[str], str | None]`) — A tuple of (command as an argument list, the body to run or None).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L180-L207)

## slurm_script_generator.salloc.main

*function*

```python
def main(argv: List[str] | None = None) -> int
```

Entry point for the ``slurm-alloc`` command-line tool.

**Parameters**

- `argv` (`List[str] | None`) (default: `None`) — Arguments to parse, defaulting to the process arguments.

**Returns**

- (`int`) — The exit code of salloc.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L210-L298)

## slurm_script_generator.salloc.pragma_to_salloc_arg

*function*

```python
def pragma_to_salloc_arg(pragma: Pragma) -> str
```

Render a pragma as a single salloc command-line argument.

**Parameters**

- `pragma` (`Pragma`) — The pragma to render.

**Returns**

- (`str`) — Either ``"--flag"`` for a valueless switch or ``"--flag=value"``.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L127-L138)

## slurm_script_generator.salloc.salloc_args

*function*

```python
def salloc_args(script: SlurmScript) -> Tuple[List[str], List[str]]
```

Split a script's pragmas into salloc arguments and dropped options.

**Parameters**

- `script` (`SlurmScript`) — The parsed batch script.

**Returns**

- (`Tuple[List[str], List[str]]`) — A tuple of (arguments to pass to salloc, flags salloc does not accept).

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L141-L157)

## slurm_script_generator.salloc.script_body

*function*

```python
def script_body(text: str) -> str
```

Extract the commands of a batch script, dropping shebang and pragmas.

The body is taken verbatim rather than rebuilt from the parsed script, so
that comments, quoting and here-documents survive untouched.

**Parameters**

- `text` (`str`) — The full text of the batch script.

**Returns**

- (`str`) — The remaining lines, with leading and trailing blank lines removed.

[View source](https://github.com/max-models/slurm-script-generator/blob/devel/src/slurm_script_generator/salloc.py#L160-L177)
