File tree Expand file tree Collapse file tree 5 files changed +135
-0
lines changed Expand file tree Collapse file tree 5 files changed +135
-0
lines changed Original file line number Diff line number Diff line change @@ -250,4 +250,34 @@ listToAttrs (
250
250
cffi = [ ] ;
251
251
} ;
252
252
253
+ install-dist =
254
+ let
255
+ python = pkgs . python3 ;
256
+
257
+ pythonSet =
258
+ ( pkgs . callPackage pyproject-nix . build . packages {
259
+ inherit python ;
260
+ } ) . overrideScope
261
+ buildSystems ;
262
+ in
263
+ pythonSet . build . override {
264
+ pyprojectHook = pythonSet . pyprojectDistHook ;
265
+ } ;
266
+
267
+ install-dist-cross =
268
+ let
269
+ pkgs' = pkgs . pkgsCross . aarch64-multiplatform ;
270
+
271
+ python = pkgs . python3 ;
272
+
273
+ pythonSet =
274
+ ( pkgs' . callPackage pyproject-nix . build . packages {
275
+ inherit python ;
276
+ } ) . overrideScope
277
+ buildSystems ;
278
+ in
279
+ pythonSet . build . override {
280
+ pyprojectHook = pythonSet . pyprojectDistHook ;
281
+ } ;
282
+
253
283
}
Original file line number Diff line number Diff line change 7
7
stdenv ,
8
8
hooks ,
9
9
runCommand ,
10
+ substituteAll ,
10
11
} :
11
12
let
12
13
inherit ( python ) pythonOnBuildForHost ;
272
273
} ;
273
274
} ./pypa-install-hook/pyproject-pypa-install-hook.sh
274
275
) { } ;
276
+
277
+ /*
278
+ Install dist directory with wheels into output
279
+ .
280
+ */
281
+ pyprojectInstallDistHook =
282
+ callPackage
283
+ (
284
+ { ugrep } :
285
+ makeSetupHook {
286
+ name = "pyproject-install-dist-hook" ;
287
+ substitutions = {
288
+ inherit pythonInterpreter ;
289
+ script = substituteAll {
290
+ src = ./dist-hook/install-wheels.py ;
291
+ ugrep = lib . getExe ugrep ;
292
+ store_dir = builtins . storeDir ;
293
+ } ;
294
+ } ;
295
+ } ./dist-hook/pyproject-install-dist-hook.sh
296
+ )
297
+ {
298
+ inherit ( buildPackages ) ugrep ;
299
+ } ;
300
+
301
+ /*
302
+ Hook used to build a wheel file and install it into the output directory.
303
+
304
+ Use instead of pyprojectHook.
305
+ */
306
+ pyprojectDistHook = hooks . pyprojectHook . override {
307
+ pyprojectInstallHook = hooks . pyprojectInstallDistHook ;
308
+ pyprojectOutputSetupHook = null ;
309
+ } ;
275
310
}
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ import os
3
+ import shutil
4
+ import subprocess
5
+ from pathlib import Path
6
+
7
+
8
+ def main ():
9
+ cwd = Path (os .getcwd ())
10
+ dist = cwd .joinpath ("dist" )
11
+
12
+ out = Path (os .environ ["out" ])
13
+
14
+ check_dist : bool
15
+ try :
16
+ check_dist = not bool (os .environ ["dontUsePyprojectInstallDistCheck" ])
17
+ except KeyError :
18
+ check_dist = True
19
+
20
+ wheels : list [Path ] = [dist_file for dist_file in dist .iterdir () if dist_file .name .endswith (".whl" )]
21
+
22
+ # Verify that wheel is not containing store path
23
+ if check_dist :
24
+ for wheel in wheels :
25
+ p = subprocess .run (
26
+ [
27
+ "@ugrep@" ,
28
+ # quiet
29
+ "-q" ,
30
+ # zip
31
+ "-z" ,
32
+ "@store_dir@" ,
33
+ wheel ,
34
+ ]
35
+ )
36
+ if p .returncode == 0 :
37
+ raise ValueError (f"""
38
+ Built whheel '{ wheel .name } ' contains a Nix store path reference.
39
+
40
+ Wheel not usable for distribution.
41
+ """ )
42
+
43
+ # Copy wheels to output
44
+ out .mkdir ()
45
+ for wheel in wheels :
46
+ shutil .copy (wheel , out .joinpath (wheel .name ))
47
+
48
+
49
+ if __name__ == "__main__" :
50
+ main ()
Original file line number Diff line number Diff line change
1
+ # Setup hook for installing built wheels into output
2
+ echo " Sourcing pyproject-install-dist-hook"
3
+
4
+ pyprojectInstallDistPhase () {
5
+ echo " Executing pyprojectInstallDistPhase"
6
+ runHook preInstall
7
+
8
+ @pythonInterpreter@ @script@
9
+
10
+ runHook postInstall
11
+ echo " Finished executing pyprojectInstallDistPhase"
12
+ }
13
+
14
+ if [ -z " ${dontUsePyprojectInstallDist-} " ] && [ -z " ${installPhase-} " ]; then
15
+ echo " Using pyprojectInstallDistPhase"
16
+ installPhase=pyprojectInstallDistPhase
17
+ fi
Original file line number Diff line number Diff line change 86
86
pyprojectBuildEditableHook
87
87
pyprojectFixupEditableHook
88
88
pyprojectEditableHook
89
+ pyprojectInstallDistHook
90
+ pyprojectDistHook
91
+ pyprojectPypaInstallHook
89
92
;
90
93
} ;
91
94
You can’t perform that action at this time.
0 commit comments