slurm-code 0.1.32__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. {slurm_code-0.1.32 → slurm_code-1.0.0}/.github/workflows/conda-release.yml +4 -11
  2. {slurm_code-0.1.32 → slurm_code-1.0.0}/PKG-INFO +1 -1
  3. slurm_code-1.0.0/dev/env-activation-plan.md +156 -0
  4. slurm_code-1.0.0/docs/pages/cancel.md +42 -0
  5. slurm_code-1.0.0/docs/pages/jobs.md +34 -0
  6. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/pages/profiles.md +27 -0
  7. slurm_code-1.0.0/docs/pages/reconnect.md +48 -0
  8. slurm_code-1.0.0/docs/pages/submit.md +237 -0
  9. {slurm_code-0.1.32 → slurm_code-1.0.0}/pyproject.toml +2 -2
  10. slurm_code-1.0.0/src/slurm_code/activation.py +427 -0
  11. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code/cli.py +240 -45
  12. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code/config.py +3 -1
  13. slurm_code-1.0.0/src/slurm_code/core.py +649 -0
  14. slurm_code-1.0.0/src/slurm_code/data/slurm-env-hook.sh +354 -0
  15. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/PKG-INFO +1 -1
  16. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/SOURCES.txt +13 -1
  17. slurm_code-1.0.0/test/fixtures/scontrol_show_job.txt +1 -0
  18. slurm_code-1.0.0/test/test_activation.py +392 -0
  19. slurm_code-1.0.0/test/test_cli_env.py +335 -0
  20. slurm_code-1.0.0/test/test_env_activation_hook.py +413 -0
  21. slurm_code-1.0.0/test/test_env_hook.py +512 -0
  22. slurm_code-1.0.0/test/test_env_setup.py +293 -0
  23. slurm_code-0.1.32/docs/pages/submit.md +0 -150
  24. slurm_code-0.1.32/src/slurm_code/core.py +0 -561
  25. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/Dockerfile +0 -0
  26. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/README.md +0 -0
  27. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/devcontainer.json +0 -0
  28. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/init-firewall.sh +0 -0
  29. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/mcp-setup/generate-config.sh +0 -0
  30. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/mcp-setup/install.sh +0 -0
  31. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/mcp-setup/pixi.toml +0 -0
  32. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/mcp-setup/servers.txt +0 -0
  33. {slurm_code-0.1.32 → slurm_code-1.0.0}/.devcontainer/mcp-setup/test-servers.sh +0 -0
  34. {slurm_code-0.1.32 → slurm_code-1.0.0}/.gitattributes +0 -0
  35. {slurm_code-0.1.32 → slurm_code-1.0.0}/.github/workflows/pypi-release.yml +0 -0
  36. {slurm_code-0.1.32 → slurm_code-1.0.0}/.github/workflows/quarto-publish.yml +0 -0
  37. {slurm_code-0.1.32 → slurm_code-1.0.0}/.gitignore +0 -0
  38. {slurm_code-0.1.32 → slurm_code-1.0.0}/.vscode/vscode.css +0 -0
  39. {slurm_code-0.1.32 → slurm_code-1.0.0}/CHANGELOG.md +0 -0
  40. {slurm_code-0.1.32 → slurm_code-1.0.0}/CLAUDE.md +0 -0
  41. {slurm_code-0.1.32 → slurm_code-1.0.0}/LICENSE +0 -0
  42. {slurm_code-0.1.32 → slurm_code-1.0.0}/README.md +0 -0
  43. {slurm_code-0.1.32 → slurm_code-1.0.0}/conda-build/README.md +0 -0
  44. {slurm_code-0.1.32 → slurm_code-1.0.0}/conda-build/build_env.yaml +0 -0
  45. {slurm_code-0.1.32 → slurm_code-1.0.0}/conda-build/meta.yaml +0 -0
  46. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/.gitignore +0 -0
  47. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/README.md +0 -0
  48. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_extensions/machow/interlinks/.gitignore +0 -0
  49. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_extensions/machow/interlinks/_extension.yml +0 -0
  50. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_extensions/machow/interlinks/interlinks.lua +0 -0
  51. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_inv/griffe_objects.txt +0 -0
  52. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_inv/numpy_objects.txt +0 -0
  53. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_inv/python_objects.txt +0 -0
  54. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/_quarto.yml +0 -0
  55. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/autodoc.mustache +0 -0
  56. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/custom.scss +0 -0
  57. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/objects.txt +0 -0
  58. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/pages/getting-started.md +0 -0
  59. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/pages/managing-jobs.md +0 -0
  60. {slurm_code-0.1.32 → slurm_code-1.0.0}/docs/styles.css +0 -0
  61. {slurm_code-0.1.32 → slurm_code-1.0.0}/pixi.lock +0 -0
  62. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/bump_changelog.py +0 -0
  63. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/bump_version.py +0 -0
  64. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/docs-build-render.sh +0 -0
  65. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/docs-run-notebooks.sh +0 -0
  66. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/git-commit.sh +0 -0
  67. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/github-release.sh +0 -0
  68. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/rename.py +0 -0
  69. {slurm_code-0.1.32 → slurm_code-1.0.0}/scripts/tmux-project.sh +0 -0
  70. {slurm_code-0.1.32 → slurm_code-1.0.0}/setup.cfg +0 -0
  71. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code/__init__.py +0 -0
  72. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code/gdk-code.py +0 -0
  73. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/dependency_links.txt +0 -0
  74. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/entry_points.txt +0 -0
  75. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/requires.txt +0 -0
  76. {slurm_code-0.1.32 → slurm_code-1.0.0}/src/slurm_code.egg-info/top_level.txt +0 -0
  77. {slurm_code-0.1.32 → slurm_code-1.0.0}/test/__init__.py +0 -0
  78. {slurm_code-0.1.32 → slurm_code-1.0.0}/test/test_dummy.py +0 -0
  79. {slurm_code-0.1.32 → slurm_code-1.0.0}/test/test_modulename.py +0 -0
@@ -71,17 +71,10 @@ jobs:
71
71
  # python-version: ${{ matrix.python-version }}
72
72
  # # ==============================================================================
73
73
 
74
-
75
- # - name: Install dependencies
76
- # run: |
77
- # pip install --upgrade pip
78
- # pip install -r requirements.txt
79
-
80
- # - name: Test with pytest
81
- # run: |
82
- # pip install pytest
83
- # pytest test
84
-
74
+ - name: Install conda-build into base
75
+ shell: bash -l {0}
76
+ run: |
77
+ conda install -n base -c conda-forge -y conda-build conda-verify anaconda-client nodejs=24
85
78
 
86
79
  - name: Build and upload the conda packages
87
80
  uses: munch-group/action-conda-build-upload@v0.1.26
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: slurm-code
3
- Version: 0.1.32
3
+ Version: 1.0.0
4
4
  Summary: Project description
5
5
  Author-email: Your Name <your@email.com>
6
6
  License: MIT
@@ -0,0 +1,156 @@
1
+ # Plan v2: generic environment activation (--pixi / --conda / --uv) without generated files
2
+
3
+ v2 incorporates two adversarial reviews (A: hook & tool semantics; B: design, UX, migration, security).
4
+ Builds on the merged SLURM env hook (69eac76): `src/slurm_code/data/slurm-env-hook.sh` → `~/.slurm-code-hook.sh`, sourced from
5
+ `~/.bashrc`, selects the slurm-code job on the node (squeue `%i\t%k\t%j\t%Z`, cwd ⊂ WorkDir, tie → nothing) and exports VS_SLURM_*.
6
+
7
+ ## Problem
8
+ `--pixi` writes `<DIRECTORY>/.slurm-code-pixi-env.sh` (login-node snapshot incl. its PATH), sourced via the RELATIVE bashrc line
9
+ `[ -f .slurm-code-pixi-env.sh ] && source .slurm-code-pixi-env.sh`: left behind, stale, runs a plantable file from any cwd, pixi-only.
10
+
11
+ ## Facts (GenomeDK, 2026-12-05: pixi 0.81.0, Slurm 25.11.6, bash 5.1, NFS home)
12
+ - No conda/uv/modules for the user; conda users self-install. pixi in ~/.pixi/bin.
13
+ - Job comment round-trips verbatim via `squeue %k` (spaces, `;=/:`), ≥1024 chars OK, 1500 rejected. **The owner can change it on a
14
+ running job: `scontrol update JobId=… Comment=…` works.**
15
+ - `pixi shell-hook --as-is`: ~90 ms warm / 413 ms cold on a compute node; never installs or touches the lock; for a NOT installed env it
16
+ exits 0 and prints activation for a non-existent prefix. `--frozen` installs if missing. Concurrent installs are safe (pixi locks).
17
+ `pixi lock --check` and `pixi install --locked|--frozen` exist.
18
+ - conda: `conda.sh` ~5 ms; `conda activate` 18.6 s cold / ~0.3 s warm on a compute node. venv activate ~5 ms.
19
+
20
+ ## Definition of done
21
+ 1. No activation file written anywhere; old `.slurm-code-pixi-env.sh` removed where found; the relative bashrc line is never added and is
22
+ removed (with consent) where found.
23
+ 2. `submit DIRECTORY --pixi [--pixi-env E] | --conda NAME_OR_PREFIX | --uv [--venv PATH]`; profile key `env =`; `--no-env`.
24
+ 3. A terminal opened in DIRECTORY (or below) on the job node has the env active *after all of ~/.bashrc has run*, equivalent to running the
25
+ tool's own activation by hand at that moment.
26
+ 4. Never activates outside DIRECTORY, in job steps, during VSCODE_RESOLVING_ENVIRONMENT, or twice for the same env in nested shells.
27
+ 5. Terminal start never installs, never touches pixi.lock; activation is interruptible (Ctrl-C) and bounded by a timeout; slow cold starts
28
+ are reported, not silent.
29
+ 6. Bad choices fail before sbatch where possible; node-side failures (install) are reported with the option to cancel the job.
30
+ 7. Works under the user's set -e/-u/-f, aliases, nullglob/failglob, custom IFS; activation scripts see a normal top-level shell.
31
+ 8. Tests (bash 3.2 + 5) incl. real-style `activate.d` scripts; GenomeDK end-to-end for all three tools.
32
+
33
+ ## Design
34
+
35
+ ### 0. Prerequisite bug fix: quote the sbatch command
36
+ `build_sbatch_command` joins unquoted options and `run_remote` wraps them in `ssh host '…'` (core.py:33-35, 91-137): a `;` in the comment,
37
+ or a DIRECTORY/conda path with spaces or `'`, breaks or injects. Change to building an argv list, `shlex.join` it, and run via
38
+ `ssh host bash -s` with the command on stdin (no outer single quotes). Test: run the produced command through `sh -c` with a fake
39
+ `sbatch` that records argv; assert exact argv incl. `;`, spaces, quotes, `$`.
40
+
41
+ ### 1. CLI and profiles (fixes Click optional-value ambiguity, verified by reviewer: `submit --pixi ~/proj` ate DIRECTORY)
42
+ - Flags: `--pixi` (flag), `--pixi-env NAME` (implies --pixi), `--conda NAME_OR_PREFIX` (required value), `--uv` (flag), `--venv PATH`
43
+ (implies --uv; relative to DIRECTORY), `--no-env` (drop a profile's env). More than one kind → usage error.
44
+ - All kinds require DIRECTORY (B7: without it WorkDir=$HOME and every shell under ~ would activate).
45
+ - Profile: `env = pixi | pixi:NAME | conda:NAME_OR_PREFIX | uv | uv:PATH`; legacy `pixi = true` ≡ `env = pixi`; both in the same
46
+ resolved profile (incl. DEFAULT) → error. CLI beats profile.
47
+ - Parsing tests for every order: `submit --pixi DIR`, `submit DIR --pixi`, `--pixi --partition x DIR`, `--pixi-env cuda DIR`, etc.
48
+
49
+ ### 2. Carrier: versioned job comment
50
+ `slurm-code;v=1;env=pixi;penv=NAME` | `…;env=conda;prefix=/abs;conda=/abs/bin/conda` | `…;env=uv;venv=/abs`. No env → `slurm-code`.
51
+ Values: no `;`, tab, newline, leading/trailing space; total ≤ 1000 → error. Hook accepts `slurm-code` and `slurm-code;*`, ignores
52
+ unknown fields, and does no activation if `v` is newer than it understands (prints one line). Paths in comments are visible to other
53
+ users via squeue like WorkDir already is — documented.
54
+
55
+ ### 3. Submit flow
56
+ Pre-flight on the login node, before sbatch (one `ssh host bash -s` script; nothing submitted on error):
57
+ - pixi: pixi found (`command -v pixi || ~/.pixi/bin/pixi`); manifest discovered as pixi does (DIRECTORY or parents; pixi.toml or
58
+ pyproject.toml with [tool.pixi]) via `pixi info --json --manifest-path DIR`; NAME is an environment of it; lock policy check (D3).
59
+ - conda: find conda: profile/CLI override `conda_exe`, else `CONDA_EXE`/`type -P conda` from `bash -ic` (user's own init), else
60
+ `~/miniforge3 ~/mambaforge ~/miniconda3 ~/anaconda3 ~/micromamba`… `bin/conda`. Resolve NAME exactly as conda does: run
61
+ `conda shell.posix activate NAME` and read CONDA_PREFIX from it (handles `base`, envs_dirs order, environments.txt). Error lists envs.
62
+ - uv: venv = `--venv` or `DIRECTORY/.venv`; `bin/activate` and `bin/python` exist.
63
+ After allocation, on the node (`ssh node bash -s`), replacing `setup_pixi_env`:
64
+ - pixi: `pixi install --manifest-path DIR -e NAME` with the D3 lock flag (on the node so GPU `system-requirements` like `__cuda` resolve),
65
+ then a timed dry activation (warm-up). conda: timed dry activation. uv: `"$venv/bin/python" -c ''` (catches broken interpreter links).
66
+ - Failure → print the error and ask "Cancel job N? [Y/n]".
67
+ `reconnect DIR [--pixi …|--conda …|--uv …|--no-env]` (D7): runs the same pre-flight + node prep and `scontrol update JobId=… Comment=…`,
68
+ so the env can be set for jobs from older versions or changed without resubmitting. Without options reconnect warns if the job has no
69
+ env field but `DIRECTORY/.slurm-code-pixi-env.sh` existed.
70
+
71
+ ### 4. Hook: decide at bashrc time, activate at first prompt (A2, A3, B3)
72
+ - Decision (inside the existing function, at bashrc time): after VS_SLURM_*, parse the comment fields (split on `;`, first `=`, no eval);
73
+ activate only if env= present, cwd inside the job's WorkDir (realpath; never via the single-candidate fallback), SLURM_CODE_NO_ACTIVATE
74
+ != 1, and the same env is not already active (realpath compare of PIXI_PROJECT_ROOT+PIXI_ENVIRONMENT_NAME / CONDA_PREFIX /
75
+ VIRTUAL_ENV). A *different* active env (e.g. conda base from auto_activate_base) does not block: activating on top is what typing the
76
+ command does. Store the decision in globals `_SLURM_CODE_ACT_*` and prepend a one-shot entry to PROMPT_COMMAND.
77
+ - Activation (at the first prompt, i.e. after the whole ~/.bashrc incl. later conda init/PATH/PS1; top-level scope, so `declare` in
78
+ activation scripts is global): the PROMPT_COMMAND entry sources `~/.slurm-code-hook.sh`, which sees the pending globals and runs the
79
+ activation at file top level (not in a function), then removes its PROMPT_COMMAND entry (string removal; works with bash 3.2 strings
80
+ and bash 5 arrays left untouched) and unsets the globals. Around the activation it saves and restores: `set +e +u +f`,
81
+ `shopt -u expand_aliases nullglob failglob nocasematch`, IFS default.
82
+ - pixi: `out=$(builtin command timeout --foreground 10 "$pixi" shell-hook --manifest-path "$wd" -e "$penv" --shell bash --as-is 2>/dev/null)`;
83
+ verify in a subshell `( eval "$out"; [ -d "$CONDA_PREFIX/conda-meta" ] )`; then `eval "$out"`.
84
+ - conda: `. "$condabase/etc/profile.d/conda.sh"` (defines `conda`, needed for `conda deactivate`, also in nested shells);
85
+ `out=$(builtin command timeout --foreground 30 "$conda_exe" shell.posix activate "$prefix")` then `eval "$out"` and `hash -r`
86
+ — identical to what conda's own `conda activate` function does, but bounded and interruptible.
87
+ - uv: `. "$venv/bin/activate"`.
88
+ - Timing: if activation took > 2 s print `slurm-code: activated <kind> env in N s (cold file cache)`; on failure/timeout one line
89
+ `slurm-code: could not activate <kind> env <x>: <reason>`. Ctrl-C only aborts the activation (bashrc already finished).
90
+ - Commands run as `bash -ic 'cmd'` show no prompt → no activation (acceptable; documented).
91
+ - Hook file carries `# slurm-code-hook-version: N`; the installer refuses to replace a newer version (old clients still can → docs:
92
+ upgrade all clients; the next new submit/reconnect restores it).
93
+
94
+ ### 5. Removing the old mechanism
95
+ - Delete setup_pixi_env, PIXI_ENV_SCRIPT writing, PIXI_BASHRC_LINE; the bashrc prompt only adds the hook line.
96
+ - Env-hook setup also `rm -f DIRECTORY/.slurm-code-pixi-env.sh`. Docs: `find -L ~ /faststorage/… -name .slurm-code-pixi-env.sh` guidance.
97
+ - Old relative line (D2): if present (exact line match, commented-out lines ignored), prompt "Remove the unsafe line … from ~/.bashrc?
98
+ [Y/n]"; back up to `~/.bashrc.slurm-code.bak`; rewrite by `cat > ~/.bashrc` through the link (never `sed -i`, which replaces symlinks);
99
+ remove the preceding "# Added by slurm-code" comment only if it then has no slurm-code line under it.
100
+
101
+ ### 6. Tests
102
+ - Hook: fake squeue comments (v1 fields, unknown fields, newer v, malicious values `$(…)`, backticks, quotes never executed); fake pixi
103
+ shell-hook output that sources a fixture `activate.d` script which uses an unset variable, `declare`, and relies on globbing; fake conda
104
+ base with real-shaped `conda.sh` + `conda shell.posix activate` emitter; fake venv. Run the PROMPT_COMMAND phase (`bash -i` with a
105
+ script that sources bashrc-like content then evaluates PROMPT_COMMAND) under set -e/-u/-f, aliases (`alias cd=…`), nullglob/failglob.
106
+ Cases: activation after a later "conda init + auto_activate_base" block wins; PROMPT_COMMAND entry removed after one run and user's
107
+ PROMPT_COMMAND preserved; nested shell same env → skip; different env active → activates on top; outside WorkDir / fallback job → none;
108
+ missing prefix → warning; timeout → warning (fake tool sleeping); realpath (symlinked DIRECTORY) handling.
109
+ - Python: sbatch argv quoting (§0); Click parsing matrix (§1); profile `env` parsing and conflict with `pixi`; comment build/validate;
110
+ pre-flight and node scripts via fake ssh; bashrc line removal (symlinked .bashrc, commented line untouched, backup written); hook
111
+ version no-downgrade.
112
+ - GenomeDK end-to-end (short jobs): pixi default + named env with an `activate.d` package (e.g. openjdk), conda (temporary Miniforge in a
113
+ scratch dir) incl. `--conda base`, uv venv; reconnect switching env via scontrol update; terminal opened ≥10 min after warm-up to
114
+ measure real cold/warm behaviour. Only a real VSCode session can confirm PROMPT_COMMAND interplay with VSCode shell integration —
115
+ user check.
116
+
117
+ ### 7. Docs
118
+ submit.md "Environment activation" (options, comment carrier, first-prompt activation, scope = DIRECTORY, opt-out
119
+ SLURM_CODE_NO_ACTIVATE, timing messages, `bash -ic` caveat; extension host / Python interpreter / Jupyter kernels do NOT get it — select the
120
+ env's interpreter in VSCode; set `python.terminal.activateEnvironment: false` (and the Python Environments extension's auto-activation
121
+ setting) to avoid double activation; security: activation runs code from the project (pixi [activation] scripts, activate.d, venv
122
+ activate) — keep project dirs non-group-writable). reconnect.md (new options). profiles.md (`env`, `conda_exe`, legacy `pixi`).
123
+ Upgrade notes.
124
+
125
+ ## Decisions (made by the user, 2026-12-05)
126
+ - D2: old relative pixi line → prompt to remove, default Yes, with backup `~/.bashrc.slurm-code.bak`.
127
+ - D3: never rewrite pixi.lock → pre-flight `pixi lock --check`; outdated → fail with "run `pixi install` first"; install with `--frozen`.
128
+ - D7: `reconnect` can set/change the env via `scontrol update` (incl. jobs from older versions).
129
+
130
+ ## Rejected review suggestions
131
+ - "Skip if any other env is active" (B10): would never activate for conda users with auto_activate_base; activating on top matches
132
+ manual use. Same-env check kept.
133
+ - Lock-mtime staleness warning (B10): no reliable pixi install stamp verified; `--as-is` + D3 keeps the lock authoritative. Revisit later.
134
+ - Warn on group-writable project dirs (A11): docs only for now.
135
+
136
+ ## Non-goals
137
+ mamba/micromamba envs as a kind (extensible via `env=`), modules, zsh/fish.
138
+
139
+ ## Implementation notes (2026-12-05)
140
+
141
+ - **Changed during implementation:** GenomeDK compute nodes have no internet access ("Network unreachable"
142
+ from `pixi install` on a node). pixi environments are therefore installed with `pixi install --frozen` on
143
+ the login node before `sbatch` (shared filesystem; this also fails fast before allocation). If that fails
144
+ (e.g. GPU `system-requirements` the login node lacks), the node retries `pixi install --frozen` from the
145
+ shared package cache. The node step otherwise only warms up the activation.
146
+ - `pixi lock --check` alone rewrites/creates pixi.lock; the pre-flight uses `pixi lock --check --dry-run`.
147
+ - VSCode shell integration runs a saved copy of PROMPT_COMMAND (`__vsc_original_prompt_command`) inside a
148
+ function; the hook removes its entry from both. In that copy, activation runs inside a function, so
149
+ `declare` in an activation script would be local there (rare; not fixable from the hook).
150
+ - Verified end-to-end on GenomeDK (job on cn-1057, user's real ~/.bashrc with iTerm2/bash-preexec):
151
+ pixi default and `extra` (real `activate.d` from `proj`: PROJ_DATA set), conda prefix env incl. `conda
152
+ deactivate`, uv venv incl. `deactivate`, `--no-env`, reconnect switching env via `scontrol update`,
153
+ activation only inside DIRECTORY, no double activation in nested shells. First-prompt cost: pixi ~0.4–0.5 s,
154
+ conda ~0.8 s, uv ~30 ms.
155
+ - Warm-up persistence: a conda terminal opened 11 min after the warm-up activated in 0.4–0.5 s (vs 18.6 s
156
+ fully cold). Measured on an otherwise idle job; heavy memory pressure in the job could still evict caches.
@@ -0,0 +1,42 @@
1
+ ---
2
+ title: Cancel Jobs
3
+ ---
4
+
5
+ slurm-code provides commands to list, cancel, and reconnect to jobs that were submitted through `slurm-code submit`. These commands identify managed jobs by their `sc-` name prefix.
6
+
7
+ ## Cancelling jobs {#cancelling-jobs}
8
+
9
+ The `cancel` command cancels slurm-code managed jobs.
10
+
11
+ ### Cancel by job ID
12
+
13
+ ```bash
14
+ slurm-code cancel 1234567
15
+ ```
16
+
17
+ ### Cancel by name
18
+
19
+ You can use the directory basename (without the `sc-` prefix):
20
+
21
+ ```bash
22
+ slurm-code cancel my-project
23
+ ```
24
+
25
+ Or the full job name:
26
+
27
+ ```bash
28
+ slurm-code cancel sc-my-project
29
+ ```
30
+
31
+ ### Cancel all jobs
32
+
33
+ ```bash
34
+ slurm-code cancel --all
35
+ ```
36
+
37
+ ### Options
38
+
39
+ | Argument/Option | Description |
40
+ |-----------------|-------------|
41
+ | `JOB_ID_OR_NAME` | A job ID (numeric) or job name to cancel |
42
+ | `--all` | Cancel all slurm-code managed jobs |
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: Listing Jobs
3
+ ---
4
+
5
+ slurm-code provides commands to list, cancel, and reconnect to jobs that were submitted through `slurm-code submit`. These commands identify managed jobs by their `sc-` name prefix.
6
+
7
+ ## Listing jobs {#listing-jobs}
8
+
9
+ The `jobs` command shows your running slurm-code jobs:
10
+
11
+ ```bash
12
+ slurm-code jobs
13
+ ```
14
+
15
+ Example output:
16
+
17
+ ```
18
+ JOBID NAME PARTITION REQMEM CPUS TIMELIMIT ELAPSED STATE
19
+ ----------------------------------------------------------------------------------------------------------
20
+ 1234567 sc-my-project normal 8Gn 1 08:00:00 01:23:45 RUNNING
21
+ 1234568 sc-analysis normal 16Gn 4 12:00:00 00:45:12 RUNNING
22
+ ```
23
+
24
+ ### Options
25
+
26
+ | Option | Description |
27
+ |--------|-------------|
28
+ | `--all-states` | Include PENDING jobs (default: RUNNING only) |
29
+
30
+ To also see pending jobs:
31
+
32
+ ```bash
33
+ slurm-code jobs --all-states
34
+ ```
@@ -51,7 +51,9 @@ Profile keys use the same names as the CLI options (with underscores instead of
51
51
  |-----|---------------------|
52
52
  | `account` | `--account` |
53
53
  | `cpus_per_task` | `--cpus-per-task` |
54
+ | `conda_exe` | `--conda-exe` |
54
55
  | `cpus_per_gpu` | `--cpus-per-gpu` |
56
+ | `env` | `--pixi`, `--pixi-env`, `--conda`, `--uv`, `--venv` (see below) |
55
57
  | `error` | `--error` |
56
58
  | `exclude` | `--exclude` |
57
59
  | `job_name` | `--job-name` |
@@ -72,6 +74,31 @@ Profile keys use the same names as the CLI options (with underscores instead of
72
74
 
73
75
  Boolean keys (`no_requeue`, `requeue`, `use_min_nodes`) accept `true`/`false`, `yes`/`no`, or `1`/`0`.
74
76
 
77
+ ### Environment
78
+
79
+ `env` selects the [environment activated in terminals](submit.md#environment-activation):
80
+
81
+ | Value | Same as |
82
+ |-------|---------|
83
+ | `env = pixi` | `--pixi` |
84
+ | `env = pixi:cuda` | `--pixi-env cuda` |
85
+ | `env = conda:myenv` | `--conda myenv` (a name or a prefix path) |
86
+ | `env = uv` | `--uv` |
87
+ | `env = uv:envs/gpu` | `--venv envs/gpu` |
88
+ | `env = none` | `--no-env` |
89
+
90
+ ```ini
91
+ [gpu]
92
+ partition = gpu
93
+ env = pixi:cuda
94
+
95
+ [analysis]
96
+ env = conda:analysis
97
+ conda_exe = /faststorage/project/me/miniforge3/bin/conda
98
+ ```
99
+
100
+ An environment option on the command line replaces the profile's `env`, and `--no-env` removes it. The older key `pixi = true` still works and means `env = pixi`; a profile (including `[DEFAULT]`) must not set both `pixi` and `env`.
101
+
75
102
  ## Precedence
76
103
 
77
104
  When a profile is active, values are resolved in this order (highest priority first):
@@ -0,0 +1,48 @@
1
+ ---
2
+ title: Reconnecting to Jobs
3
+ ---
4
+
5
+ slurm-code provides commands to list, cancel, and reconnect to jobs that were submitted through `slurm-code submit`. These commands identify managed jobs by their `sc-` name prefix.
6
+
7
+ ## Reconnecting to a job {#reconnecting-to-a-job}
8
+
9
+ If VSCode disconnects or you close the window, use `reconnect` to reopen it on the same node:
10
+
11
+ ```bash
12
+ slurm-code reconnect ~/my-project
13
+ ```
14
+
15
+ This finds the running job that matches the directory name and opens VSCode on its allocated node. Relative paths are resolved relative to `$HOME`.
16
+
17
+ If multiple jobs match the directory name, you'll be prompted to select one:
18
+
19
+ ```
20
+ Multiple matching jobs found:
21
+ [1] 1234567 01:23:45 RUNNING
22
+ [2] 1234568 00:45:12 RUNNING
23
+ Select job number:
24
+ ```
25
+
26
+ ### Usage
27
+
28
+ ```bash
29
+ slurm-code reconnect [OPTIONS] DIRECTORY
30
+ ```
31
+
32
+ | Argument | Description |
33
+ |----------|-------------|
34
+ | `DIRECTORY` | Path on the remote host (used to match the job name) |
35
+
36
+ ### Setting or changing the environment
37
+
38
+ `reconnect` accepts the same environment options as [`submit`](submit.md#environment-activation): `--pixi`, `--pixi-env`, `--conda`, `--conda-exe`, `--uv`, `--venv` and `--no-env`. With one of them, slurm-code checks and prepares the environment, then records it in the running job (`scontrol update ... Comment=...`), so terminals opened afterwards activate it. Terminals that are already open keep what they have.
39
+
40
+ ```bash
41
+ # switch the running job to the project's cuda pixi environment
42
+ slurm-code reconnect ~/my-project --pixi-env cuda
43
+
44
+ # stop activating an environment
45
+ slurm-code reconnect ~/my-project --no-env
46
+ ```
47
+
48
+ This is also how to add environment activation to a job started by an older slurm-code (0.1.32 or earlier), which recorded no environment. `reconnect` points this out when it finds that job's old `.slurm-code-pixi-env.sh` file.
@@ -0,0 +1,237 @@
1
+ ---
2
+ title: Submitting Jobs
3
+ ---
4
+
5
+ The `submit` command creates a SLURM job, waits for a node to be allocated and ready, then opens VSCode connected to that node.
6
+
7
+ ## Usage
8
+
9
+ ```bash
10
+ slurm-code submit [OPTIONS] [DIRECTORY]
11
+ ```
12
+
13
+ `DIRECTORY` is an optional path on the remote host to open in VSCode. Relative paths are resolved relative to `$HOME`. If omitted, VSCode opens the welcome screen on the allocated node.
14
+
15
+ ## Examples
16
+
17
+ Submit with default settings and open a project directory:
18
+
19
+ ```bash
20
+ slurm-code submit ~/my-project
21
+ ```
22
+
23
+ Request more memory and a longer walltime:
24
+
25
+ ```bash
26
+ slurm-code submit -m 16g -t 12:00:00 ~/my-project
27
+ ```
28
+
29
+ Submit to the GPU partition with a named profile:
30
+
31
+ ```bash
32
+ slurm-code submit -P gpu ~/my-project
33
+ ```
34
+
35
+ Override a profile's walltime from the command line:
36
+
37
+ ```bash
38
+ slurm-code submit -P gpu -t 24:00:00 ~/my-project
39
+ ```
40
+
41
+ Activate the project's pixi environment (or its `cuda` environment) in terminals:
42
+
43
+ ```bash
44
+ slurm-code submit --pixi ~/my-project
45
+ slurm-code submit --pixi-env cuda ~/my-project
46
+ ```
47
+
48
+ Activate a conda environment, or the project's `.venv` (uv):
49
+
50
+ ```bash
51
+ slurm-code submit --conda myenv ~/my-project
52
+ slurm-code submit --uv ~/my-project
53
+ ```
54
+
55
+ Submit without opening a specific directory:
56
+
57
+ ```bash
58
+ slurm-code submit -A my_account
59
+ ```
60
+
61
+ ## Options
62
+
63
+ ### Resource allocation
64
+
65
+ | Option | Default | Description |
66
+ |--------|---------|-------------|
67
+ | `-A`, `--account` | | Charge job to specified account |
68
+ | `-c`, `--cpus-per-task` | `1` | CPUs per task |
69
+ | `-n`, `--ntasks` | `1` | Number of tasks |
70
+ | `-N`, `--nodes` | | Number of nodes (`N` or `min-max`) |
71
+ | `--ntasks-per-node` | | Tasks per node |
72
+ | `--mincpus` | | Minimum logical processors per node |
73
+ | `--cpus-per-gpu` | | CPUs per allocated GPU |
74
+
75
+ ### Memory
76
+
77
+ | Option | Default | Description |
78
+ |--------|---------|-------------|
79
+ | `-m`, `--mem-per-cpu` | `8g` | Memory per allocated CPU |
80
+ | `--mem` | | Minimum total real memory (e.g. `4g`) |
81
+
82
+ ### Time and scheduling
83
+
84
+ | Option | Default | Description |
85
+ |--------|---------|-------------|
86
+ | `-t`, `--walltime` | `08:00:00` | Time limit (e.g. `08:00:00`) |
87
+ | `-p`, `--partition` | | Partition requested |
88
+
89
+ ### Job identity
90
+
91
+ | Option | Default | Description |
92
+ |--------|---------|-------------|
93
+ | `-J`, `--job-name` | `sc-<dirname>` | Job name (auto-derived from directory if not set) |
94
+ | `-e`, `--error` | | File for batch script's standard error |
95
+
96
+ ### Node selection
97
+
98
+ | Option | Description |
99
+ |--------|-------------|
100
+ | `-w`, `--nodelist` | Request specific hosts |
101
+ | `-x`, `--exclude` | Exclude specific hosts |
102
+ | `--use-min-nodes` | Prefer smaller node count |
103
+
104
+ ### Job behaviour
105
+
106
+ | Option | Description |
107
+ |--------|-------------|
108
+ | `--requeue` | Permit the job to be requeued |
109
+ | `--no-requeue` | Do not requeue the job |
110
+ | `--oom-kill-step` | OOMKillStep behaviour (`0` or `1`) |
111
+ | `--thread-spec` | Count of reserved threads |
112
+
113
+ ### Environment
114
+
115
+ | Option | Description |
116
+ |--------|-------------|
117
+ | `--pixi` | Activate the [pixi](https://pixi.sh) environment of the workspace containing DIRECTORY |
118
+ | `--pixi-env NAME` | pixi environment to activate (implies `--pixi`; default: `default`) |
119
+ | `--conda NAME_OR_PREFIX` | Activate a conda environment, by name (as for `conda activate`) or prefix path |
120
+ | `--conda-exe PATH` | conda executable on the cluster (default: auto-detect) |
121
+ | `--uv` | Activate the virtual environment `DIRECTORY/.venv` (created by uv or `python -m venv`) |
122
+ | `--venv PATH` | Virtual environment to activate, relative to DIRECTORY (implies `--uv`) |
123
+ | `--no-env` | Activate no environment, even if the profile sets one |
124
+
125
+ At most one environment can be chosen, and it requires a `DIRECTORY`.
126
+
127
+ #### SLURM environment variables
128
+
129
+ VSCode integrated terminals run outside the job's process tree, so they don't get the job's SLURM environment variables. slurm-code provides them under a `VS_` prefix (`VS_SLURM_JOB_ID`, `VS_SLURM_JOB_NAME`, `VS_SLURM_JOB_PARTITION`, `VS_SLURM_JOB_ACCOUNT`, `VS_SLURM_JOB_NUM_NODES`, `VS_SLURM_CPUS_ON_NODE`, `VS_SLURM_JOB_NODELIST`, `VS_SLURM_TIMELIMIT`, `VS_SLURM_SUBMIT_DIR`, `VS_SLURM_CPUS_PER_TASK`, `VS_SLURM_NTASKS` and `VS_SLURM_MEM_PER_CPU` in MB). The prefix avoids colliding with native SLURM variables, which would interfere with `sbatch` and `srun`.
130
+
131
+ The variables are looked up live each time an interactive shell starts on a compute node. Nothing job-specific is written to disk, so there is nothing to clean up and nothing goes stale. The lookup runs `squeue` and `scontrol` for the current node, which takes a few milliseconds. On a login node it does nothing.
132
+
133
+ Which job is used:
134
+
135
+ - slurm-code jobs are recognised by their `--comment=slurm-code` tag, or by the `sc-` name prefix for jobs submitted with older versions. Other jobs you run on the node are ignored.
136
+ - If several slurm-code jobs run on the node, the job whose working directory (the `DIRECTORY` you submitted) contains the shell's current directory is used. VSCode terminals start in the project folder, so this picks the right job.
137
+ - If the current directory is in none of the jobs' directories and there is exactly one slurm-code job on the node, that job is used.
138
+ - If the choice is ambiguous (for example two jobs on the same directory), no variables are set.
139
+
140
+ Shells started inside a job step (where `SLURM_JOB_ID` is set) are left alone. Set `SLURM_CODE_NO_ENV=1` to turn the lookup off.
141
+
142
+ #### Environment activation
143
+
144
+ With `--pixi`, `--conda` or `--uv` (or `env` in a [submit profile](profiles.md)), terminals you open in the job's `DIRECTORY`, or below it, start with that environment active. Nothing is written to the project or your home directory: the choice is stored in the job's SLURM comment (for example `slurm-code;v=1;env=conda;prefix=...`) and disappears with the job.
145
+
146
+ Before submitting, slurm-code checks the environment on the login node and stops with an explanation if something is wrong, for example a missing environment, a missing `.venv`, or conda that cannot be found:
147
+
148
+ - **pixi**: the workspace is found as pixi finds it (DIRECTORY or a parent with `pixi.toml` or `pyproject.toml`), and the environment must be defined in it. slurm-code never changes `pixi.lock`: if the lock file is missing or out of date with the manifest, run `pixi install` in the workspace first.
149
+ - **conda**: conda is found from your own conda setup (`conda init`), `PATH`, or the usual install locations (`~/miniforge3`, `~/mambaforge`, `~/miniconda3`, ...). Use `--conda-exe` or `conda_exe` in a profile if it is elsewhere. Names are resolved exactly as `conda activate` resolves them, so `--conda base` works too.
150
+ - **uv**: the virtual environment must exist (create it with `uv sync` or `uv venv` on the cluster).
151
+
152
+ A pixi environment is then installed with `pixi install --frozen` on the login node, before the job is submitted: compute nodes may have no internet access, and the environment lives on the shared filesystem. If that fails (for example a GPU environment whose system requirements only a GPU node meets), it is retried on the compute node once the job runs, using the shared package cache.
153
+
154
+ Once the job runs, slurm-code prepares the environment on the allocated node: it runs the activation once (and `pixi install --frozen` again, a no-op if already installed), so files are cached on the node and the first terminal opens quickly. If this fails, you are asked whether to cancel the job.
155
+
156
+ When a terminal opens, the [bashrc hook](#bashrc-hook) activates the environment at the first prompt, after the rest of your `~/.bashrc` has run. Later lines in `~/.bashrc`, such as a `conda init` block that activates `base`, therefore cannot undo it. The activation is the tool's own, so the result is the same as typing it:
157
+
158
+ - pixi: `pixi shell-hook --as-is` (never installs anything at terminal start)
159
+ - conda: `conda activate` (`conda deactivate` works as usual)
160
+ - uv: `source .venv/bin/activate` (`deactivate` works as usual)
161
+
162
+ Details:
163
+
164
+ - Activation only happens in terminals started inside the job's `DIRECTORY`. Other shells on the node, such as a plain `ssh` login that starts in `~`, still get the `VS_SLURM_*` variables but no environment.
165
+ - If the same environment is already active (for example in a nested shell), it is not activated again. A *different* active environment, such as conda's `base`, does not prevent activation; the job's environment is activated on top, as typing the command would do.
166
+ - Activation is limited to 10 s (pixi) or 30 s (conda) and can be interrupted with Ctrl-C. If it takes longer than 2 s, or fails, a one-line message says so.
167
+ - Commands run as `bash -ic '...'` show no prompt and are not activated.
168
+ - Set `SLURM_CODE_NO_ACTIVATE=1` to turn off activation, keeping the `VS_SLURM_*` variables.
169
+ - Use `slurm-code reconnect DIRECTORY --pixi` (or `--conda`, `--uv`, `--no-env`) to set or change the environment of a running job. This applies to terminals opened afterwards.
170
+
171
+ ::: {.callout-note}
172
+ Only terminals are activated. The VSCode Python extension, Jupyter kernels and tasks choose their interpreter themselves: select the environment's Python in VSCode (for pixi it is in `.pixi/envs/<env>/bin/python`). To avoid the Python extension activating another environment in the same terminals, set `"python.terminal.activateEnvironment": false` in VSCode's settings.
173
+ :::
174
+
175
+ ::: {.callout-warning}
176
+ Activation runs code from the project: pixi activation scripts, conda `activate.d` scripts and `.venv/bin/activate`. Anyone who can write to the project directory can change what runs in your terminals there, so don't make project directories group-writable unless you trust the group.
177
+ :::
178
+
179
+ Job comments, including environment paths, are visible to other users via `squeue`, like the job's working directory.
180
+
181
+ #### Bashrc hook
182
+
183
+ On every `submit` and `reconnect`, slurm-code writes the hook script to `~/.slurm-code-hook.sh` on the cluster. The script is the same for every job; rewriting it just keeps it up to date, and a newer version installed by a newer slurm-code is never replaced by an older one. On first use, you will be prompted to add this line to `~/.bashrc` on the cluster:
184
+
185
+ ```bash
186
+ [ -f ~/.slurm-code-hook.sh ] && . ~/.slurm-code-hook.sh
187
+ ```
188
+
189
+ In interactive shells on a compute node it provides the `VS_SLURM_*` variables and schedules [environment activation](#environment-activation) for the first prompt.
190
+
191
+ ##### Upgrading from slurm-code 0.1.32 or earlier
192
+
193
+ Older versions wrote the variables to `<DIRECTORY>/.slurm-code-slurm-env.sh` and a loader `~/.slurm-code-env.sh`. These files went stale after the job ended. The next `submit` or `reconnect` deletes the loader, the project file it pointed to, and the file in the submitted `DIRECTORY`. The old `~/.slurm-code-env.sh` line in `~/.bashrc` then does nothing and can be removed. To delete leftover files in other projects:
194
+
195
+ ```bash
196
+ find ~ -name .slurm-code-slurm-env.sh -delete
197
+ ```
198
+
199
+ Older versions also implemented `--pixi` with a file `<DIRECTORY>/.slurm-code-pixi-env.sh` and this line in `~/.bashrc`:
200
+
201
+ ```bash
202
+ [ -f .slurm-code-pixi-env.sh ] && source .slurm-code-pixi-env.sh
203
+ ```
204
+
205
+ That line runs `.slurm-code-pixi-env.sh` from whatever directory a shell starts in, so anyone able to create that file in a directory you `cd` into could run code in your shell. `submit` offers to remove the line (default yes; a backup is saved as `~/.bashrc.slurm-code.bak`) and deletes the file in the submitted `DIRECTORY`. Jobs started by an older version have no environment recorded; `reconnect` tells you so and you can add one with `slurm-code reconnect DIRECTORY --pixi`. To delete leftover files elsewhere (including project directories reached through symlinks):
206
+
207
+ ```bash
208
+ find -L ~ -name .slurm-code-pixi-env.sh -delete
209
+ ```
210
+
211
+ If an older slurm-code is still used against the same cluster account (for example on another computer), it recreates the old files and lines and replaces the hook with its own version. Upgrade all installations.
212
+
213
+ ### Profiles
214
+
215
+ | Option | Description |
216
+ |--------|-------------|
217
+ | `-P`, `--profile` | Apply a named submit profile from the config file |
218
+
219
+ See [Submit Profiles](profiles.md) for details on setting up and using profiles.
220
+
221
+ ## What happens when you submit
222
+
223
+ 1. The remote directory is verified on the host (if specified)
224
+ 2. If an environment is chosen (`--pixi`, `--conda`, `--uv` or the profile's `env`), it is checked on the login node (and a pixi environment installed there)
225
+ 3. An `sbatch` command is built from CLI flags, profile values, and defaults, and the job is submitted via SSH
226
+ 4. slurm-code polls `squeue` until the job enters RUNNING state
227
+ 5. SSH connectivity to the allocated node is verified
228
+ 6. If an environment is chosen, it is warmed up on the node
229
+ 7. The environment hook `~/.slurm-code-hook.sh` is installed or refreshed, and files from older versions are removed
230
+ 8. `~/.bashrc` is checked: the hook line is added and the unsafe line from older versions removed (prompts)
231
+ 9. VSCode opens with a remote connection to the node
232
+
233
+ ## Job naming
234
+
235
+ Jobs are automatically named `sc-<dirname>` based on the directory basename. For example, submitting `~/projects/my-analysis` creates a job named `sc-my-analysis`. If no directory is given, the name is `sc-<timestamp>`. You can override this with `--job-name`.
236
+
237
+ The `sc-` prefix is how slurm-code identifies its own jobs for the `jobs`, `cancel`, and `connect` commands.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "slurm-code"
7
- version = "0.1.32"
7
+ version = "1.0.0"
8
8
  description = "Project description"
9
9
  authors = [
10
10
  {name = "Your Name", email = "your@email.com"}
@@ -37,7 +37,7 @@ where = ["src"]
37
37
  exclude = ["test*"]
38
38
 
39
39
  [tool.setuptools.package-data]
40
- slurm_code = ["data/*.txt", "data/*.csv", "data/*.pickle", "data/*.h5"]
40
+ slurm_code = ["data/*.txt", "data/*.csv", "data/*.pickle", "data/*.h5", "data/*.sh"]
41
41
 
42
42
  [tool.pixi.workspace]
43
43
  channels = ["conda-forge", "munch-group"]