Skip to content

Commit d8b090f

Browse files
committed
workspace: Add support for using workspaceRoot from attrset with outPath
As returned from things like `builtins.fetchGit` & other builtin fetchers. Closes #173
1 parent 9d34657 commit d8b090f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/test_workspace.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,36 @@ in
153153
};
154154
};
155155

156+
# Test workspaceRoot passed as an attrset
157+
# This is analogous to using builtins.fetchGit & such which return an attrset with an outPath member.
158+
loadWorkspace.fetchedWorkspace =
159+
let
160+
mkTestSet =
161+
workspaceRoot:
162+
let
163+
ws = workspace.loadWorkspace { inherit workspaceRoot; };
164+
165+
overlay = ws.mkPyprojectOverlay { sourcePreference = "wheel"; };
166+
167+
pythonSet =
168+
(pkgs.callPackage pyproject-nix.build.packages {
169+
python = pkgs.python312;
170+
}).overrideScope
171+
overlay;
172+
in
173+
pythonSet;
174+
175+
wsRoot = {
176+
outPath = "${./fixtures/workspace-flat}";
177+
};
178+
testSet = mkTestSet wsRoot;
179+
in
180+
{
181+
# Test that the stringly src lookup is correct relative to the workspace root
182+
testOutpathSrc = {
183+
expr = testSet."pkg-a".src == "${wsRoot}/packages/pkg-a";
184+
expected = true;
185+
};
186+
};
187+
156188
}

lib/workspace.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ fix (self: {
9595
# - A function taking the generated config as an argument, and returning the augmented config
9696
config ? { },
9797
}:
98-
assert (isPath workspaceRoot || (isString workspaceRoot || hasContext workspaceRoot));
98+
assert (
99+
isPath workspaceRoot
100+
|| (isString workspaceRoot && hasContext workspaceRoot)
101+
|| (isAttrs workspaceRoot && workspaceRoot ? outPath)
102+
);
99103
assert isAttrs config || isFunction config;
100104
let
101105
pyproject = importTOML (workspaceRoot + "/pyproject.toml");

0 commit comments

Comments
 (0)