mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-05 10:34:23 +01:00
Add a flake that provides local test environments equivalent to the CPU pull-request job, so local results are comparable with CI on hosts whose system Python differs. - Nix supplies Python 3.11, 3.12 and 3.13, git and the native runtime libraries prebuilt wheels need; uv.lock remains the single source of Python dependencies. - `nix run .#test[-py311|-py312|-py313]` installs uv at the CI pin, syncs the locked non-editable environment with the CI extras and runs pytest with the CI options, marker filter and environment variables. Extras, markers and the state directory can be overridden, e.g. for the operator-UI Gradio gate. - docs/NIX_TEST_ENVIRONMENT.md documents usage and scope; per-interpreter state directories are ignored by git. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.9 KiB
Nix
96 lines
3.9 KiB
Nix
{
|
|
description = "OBLITERATUS test environments matching the CPU pull-request CI";
|
|
|
|
# Nix supplies the interpreter, uv and native runtime libraries; uv.lock stays
|
|
# the single source of truth for Python dependencies, exactly as in CI.
|
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
outputs = { self, nixpkgs }:
|
|
let
|
|
systems = [ "x86_64-linux" "aarch64-linux" ];
|
|
forAll = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
|
|
|
|
# Kept in step with UV_VERSION and the marker expression in .github/workflows/ci.yml.
|
|
uvVersion = "0.12.4";
|
|
ciMarkers = "not slow and not gpu and not mps and not mlx and not network"
|
|
+ " and not download and not remote and not operator_ui and not gloo";
|
|
ciExtras = "--extra dev --extra recovery --extra mcp";
|
|
|
|
pythons = pkgs: {
|
|
py311 = pkgs.python311;
|
|
py312 = pkgs.python312;
|
|
py313 = pkgs.python313;
|
|
};
|
|
|
|
ciEnv = pkgs: python: tag: {
|
|
CUDA_VISIBLE_DEVICES = "";
|
|
HF_DATASETS_OFFLINE = "1";
|
|
HF_HUB_DISABLE_TELEMETRY = "1";
|
|
HF_HUB_OFFLINE = "1";
|
|
TOKENIZERS_PARALLELISM = "false";
|
|
TRANSFORMERS_OFFLINE = "1";
|
|
PIP_DISABLE_PIP_VERSION_CHECK = "1";
|
|
PIP_NO_INPUT = "1";
|
|
UV_PYTHON = "${python}/bin/python";
|
|
UV_PYTHON_DOWNLOADS = "never";
|
|
OBLITERATUS_NIX_TAG = tag;
|
|
# Prebuilt manylinux wheels (torch, numpy, tokenizers) need these at runtime.
|
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib pkgs.zlib ];
|
|
};
|
|
|
|
# Installs the pinned uv into a per-interpreter tool venv, syncs the locked
|
|
# non-editable test environment, then runs pytest with the CI marker filter.
|
|
runner = pkgs: python: tag:
|
|
pkgs.writeShellApplication {
|
|
name = "obliteratus-test-${tag}";
|
|
runtimeInputs = [ python pkgs.git pkgs.coreutils ];
|
|
text = ''
|
|
root="$(git rev-parse --show-toplevel)"
|
|
cd "$root"
|
|
state="''${OBLITERATUS_NIX_STATE:-$root/.nix-test}/${tag}"
|
|
tools="$state/tools"
|
|
if [ ! -x "$tools/bin/uv" ] || [ "$("$tools/bin/uv" --version | cut -d' ' -f2)" != "${uvVersion}" ]; then
|
|
python -m venv --clear "$tools"
|
|
"$tools/bin/python" -m pip install --quiet "uv==${uvVersion}"
|
|
fi
|
|
export UV_PROJECT_ENVIRONMENT="$state/env"
|
|
# shellcheck disable=SC2086
|
|
"$tools/bin/uv" sync --locked --no-default-groups ''${OBLITERATUS_TEST_EXTRAS:-${ciExtras}} \
|
|
--no-editable --link-mode copy --quiet
|
|
basetemp="$(mktemp -d "''${TMPDIR:-/tmp}/obliteratus-pytest-XXXXXX")"
|
|
exec "$state/env/bin/python" -m pytest \
|
|
-p no:cacheprovider \
|
|
-o "addopts=--strict-config --strict-markers" \
|
|
-m "''${OBLITERATUS_TEST_MARKERS:-${ciMarkers}}" \
|
|
--basetemp="$basetemp/t" \
|
|
"''${@:-tests}"
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
devShells = forAll (pkgs:
|
|
let
|
|
shells = nixpkgs.lib.mapAttrs (tag: python:
|
|
pkgs.mkShell ({
|
|
packages = [ python pkgs.git (runner pkgs python tag) ];
|
|
} // ciEnv pkgs python tag)) (pythons pkgs);
|
|
in
|
|
shells // { default = shells.py312; });
|
|
|
|
apps = forAll (pkgs:
|
|
let
|
|
mk = tag: python: {
|
|
type = "app";
|
|
program = "${pkgs.writeShellScript "obliteratus-test-${tag}-env" ''
|
|
${pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList
|
|
(k: v: "export ${k}=${pkgs.lib.escapeShellArg v}") (ciEnv pkgs python tag))}
|
|
exec ${runner pkgs python tag}/bin/obliteratus-test-${tag} "$@"
|
|
''}";
|
|
};
|
|
apps = nixpkgs.lib.mapAttrs (tag: python: mk tag python) (pythons pkgs);
|
|
in
|
|
nixpkgs.lib.mapAttrs' (tag: v: nixpkgs.lib.nameValuePair "test-${tag}" v) apps
|
|
// { test = apps.py312; });
|
|
};
|
|
}
|