Skip to content

Commit ddeecce

Browse files
adisbladiscpcloud
andauthored
chore(deps): implement Nix testing as separate derivation from env (#10473)
Co-authored-by: Phillip Cloud <[email protected]>
1 parent 321a382 commit ddeecce

File tree

6 files changed

+123
-88
lines changed

6 files changed

+123
-88
lines changed

.github/workflows/nix.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ jobs:
6161
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
6262
extraPullNames: nix-community
6363

64-
- name: nix build and test
64+
- name: nix build environment
6565
run: |
6666
set -euo pipefail
6767
6868
version='${{ matrix.python-version }}'
6969
nix build ".#ibis${version//./}" --fallback --keep-going --print-build-logs
7070
71+
- name: nix test
72+
run: |
73+
set -euo pipefail
74+
75+
version='${{ matrix.python-version }}'
76+
nix build ".#ibis${version//./}.passthru.tests.pytest" --fallback --keep-going --print-build-logs
77+
7178
- name: nix build devShell
7279
# TODO: dev shell doesn't yet build on macos-14 (aarch64-darwin)
7380
continue-on-error: ${{ matrix.os == 'macos-14' }}

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
update-lock-files check-release-notes-spelling;
151151
};
152152

153+
checks = {
154+
ibis310-pytest = pkgs.ibis310.passthru.tests.pytest;
155+
ibis311-pytest = pkgs.ibis311.passthru.tests.pytest;
156+
ibis312-pytest = pkgs.ibis312.passthru.tests.pytest;
157+
};
158+
153159
devShells = rec {
154160
ibis310 = mkDevShell pkgs.ibisDevEnv310;
155161
ibis311 = mkDevShell pkgs.ibisDevEnv311;

nix/ibis.nix

Lines changed: 0 additions & 54 deletions
This file was deleted.

nix/overlay.nix

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,43 @@ let
77
sourcePreference = "wheel";
88
};
99

10+
# Create an overlay enabling editable mode for all local dependencies.
11+
# This is for usage with `nix develop`
1012
editableOverlay =
11-
# Create an overlay enabling editable mode for all local dependencies.
12-
# This is for usage with nix-nix develop
1313
workspace.mkEditablePyprojectOverlay {
1414
root = "$REPO_ROOT";
1515
};
1616

17+
# Build fixups overlay
1718
pyprojectOverrides = import ./pyproject-overrides.nix { inherit pkgs; };
1819

19-
mkEnv = python: { deps ? workspace.deps.all, editable ? true }:
20-
# This devShell uses uv2nix to construct a virtual environment purely from Nix, using the same dependency specification as the application.
21-
#
22-
# This means that any changes done to your local files do not require a rebuild.
20+
# Adds tests to ibis-framework.passthru.tests
21+
testOverlay = import ./tests.nix {
22+
inherit pkgs;
23+
deps = defaultDeps;
24+
};
25+
26+
# Default dependencies for env
27+
defaultDeps = {
28+
ibis-framework = [
29+
"duckdb"
30+
"datafusion"
31+
"sqlite"
32+
"polars"
33+
"decompiler"
34+
"visualization"
35+
];
36+
};
37+
38+
mkEnv' =
39+
{
40+
# Python dependency specification
41+
deps
42+
, # Installs ibis-framework as an editable package for use with `nix develop`.
43+
# This means that any changes done to your local files do not require a rebuild.
44+
editable
45+
,
46+
}: python:
2347
let
2448
# Construct package set
2549
pythonSet =
@@ -30,10 +54,29 @@ let
3054
(lib.composeManyExtensions ([
3155
envOverlay
3256
pyprojectOverrides
33-
] ++ lib.optional editable editableOverlay));
57+
]
58+
++ lib.optionals editable [ editableOverlay ]
59+
++ lib.optionals (!editable) [ testOverlay ]));
3460
in
3561
# Build virtual environment
36-
pythonSet.mkVirtualEnv "ibis-${python.pythonVersion}" deps;
62+
(pythonSet.mkVirtualEnv "ibis-${python.pythonVersion}" deps).overrideAttrs (_old: {
63+
# Add passthru.tests from ibis-framework to venv passthru.
64+
# This is used to build tests by CI.
65+
passthru = {
66+
inherit (pythonSet.ibis-framework.passthru) tests;
67+
};
68+
});
69+
70+
mkEnv = mkEnv' {
71+
deps = defaultDeps;
72+
editable = false;
73+
};
74+
75+
mkDevEnv = mkEnv' {
76+
# Enable all dependencies for development shell
77+
deps = workspace.deps.all;
78+
editable = true;
79+
};
3780

3881
inherit (pkgs) lib stdenv;
3982
in
@@ -46,30 +89,22 @@ in
4689
sha256 = "sha256-1fenQNQB+Q0pbb0cbK2S/UIwZDE4PXXG15MH3aVbyLU=";
4790
};
4891

49-
ibis310 = pkgs.callPackage ./ibis.nix {
50-
python = pkgs.python310;
51-
inherit mkEnv;
52-
};
53-
54-
ibis311 = pkgs.callPackage ./ibis.nix {
55-
python = pkgs.python311;
56-
inherit mkEnv;
57-
};
58-
59-
ibis312 = pkgs.callPackage ./ibis.nix {
60-
python = pkgs.python312;
61-
inherit mkEnv;
62-
};
92+
ibis310 = mkEnv pkgs.python310;
93+
ibis311 = mkEnv pkgs.python311;
94+
ibis312 = mkEnv pkgs.python312;
6395

64-
ibisDevEnv310 = mkEnv pkgs.python310 { };
65-
ibisDevEnv311 = mkEnv pkgs.python311 { };
66-
ibisDevEnv312 = mkEnv pkgs.python312 { };
96+
ibisDevEnv310 = mkDevEnv pkgs.python310;
97+
ibisDevEnv311 = mkDevEnv pkgs.python311;
98+
ibisDevEnv312 = mkDevEnv pkgs.python312;
6799

68-
ibisSmallDevEnv = mkEnv pkgs.python312 {
69-
deps = {
70-
ibis-framework = [ "dev" ];
71-
};
72-
};
100+
ibisSmallDevEnv = mkEnv'
101+
{
102+
deps = {
103+
ibis-framework = [ "dev" ];
104+
};
105+
editable = false;
106+
}
107+
pkgs.python312;
73108

74109
duckdb = super.duckdb.overrideAttrs (
75110
_: lib.optionalAttrs (stdenv.isAarch64 && stdenv.isLinux) {

nix/tests.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ pkgs, deps }:
2+
let
3+
inherit (pkgs) stdenv;
4+
in
5+
final: prev: {
6+
ibis-framework = prev.ibis-framework.overrideAttrs (old: {
7+
passthru = old.passthru // {
8+
tests = old.passthru.tests or { } // {
9+
pytest =
10+
let
11+
pythonEnv = final.mkVirtualEnv "ibis-framework-test-env" (deps // {
12+
# Use default dependencies from overlay.nix + enabled tests group.
13+
ibis-framework = deps.ibis-framework or [ ] ++ [ "tests" ];
14+
});
15+
in
16+
stdenv.mkDerivation {
17+
name = "ibis-framework-test";
18+
nativeCheckInputs = [ pythonEnv pkgs.graphviz-nox ];
19+
src = ../.;
20+
doCheck = true;
21+
preCheck = ''
22+
set -euo pipefail
23+
24+
ln -s ${pkgs.ibisTestingData} $PWD/ci/ibis-testing-data
25+
26+
HOME="$(mktemp -d)"
27+
export HOME
28+
'';
29+
checkPhase = ''
30+
runHook preCheck
31+
pytest -m datafusion
32+
pytest -m 'core or duckdb or sqlite or polars' --numprocesses $NIX_BUILD_CORES --dist loadgroup
33+
runHook postCheck
34+
'';
35+
36+
installPhase = "mkdir $out";
37+
};
38+
};
39+
};
40+
});
41+
}

0 commit comments

Comments
 (0)