-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build.hooks: Add hook to install dist directory into output
`pyprojectDistHook` is to be used instead of `pyprojectHook` when you want to get the wheel files instead of the installed files.
- Loading branch information
1 parent
3ee4005
commit 7b88593
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import shutil | ||
import subprocess | ||
from pathlib import Path | ||
|
||
|
||
def main(): | ||
cwd = Path(os.getcwd()) | ||
dist = cwd.joinpath("dist") | ||
|
||
out = Path(os.environ["out"]) | ||
|
||
check_dist: bool | ||
try: | ||
check_dist = not bool(os.environ["dontUsePyprojectInstallDistCheck"]) | ||
except KeyError: | ||
check_dist = True | ||
|
||
wheels: list[Path] = [dist_file for dist_file in dist.iterdir() if dist_file.name.endswith(".whl")] | ||
|
||
# Verify that wheel is not containing store path | ||
if check_dist: | ||
for wheel in wheels: | ||
p = subprocess.run( | ||
[ | ||
"@ugrep@", | ||
# quiet | ||
"-q", | ||
# zip | ||
"-z", | ||
"@store_dir@", | ||
wheel, | ||
] | ||
) | ||
if p.returncode == 0: | ||
raise ValueError(f""" | ||
Built whheel '{wheel.name}' contains a Nix store path reference. | ||
Wheel not usable for distribution. | ||
""") | ||
|
||
# Copy wheels to output | ||
out.mkdir() | ||
for wheel in wheels: | ||
shutil.copy(wheel, out.joinpath(wheel.name)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Setup hook for installing built wheels into output | ||
echo "Sourcing pyproject-install-dist-hook" | ||
|
||
pyprojectInstallDistPhase() { | ||
echo "Executing pyprojectInstallDistPhase" | ||
runHook preInstall | ||
|
||
@pythonInterpreter@ @script@ | ||
|
||
runHook postInstall | ||
echo "Finished executing pyprojectInstallDistPhase" | ||
} | ||
|
||
if [ -z "${dontUsePyprojectInstallDist-}" ] && [ -z "${installPhase-}" ]; then | ||
echo "Using pyprojectInstallDistPhase" | ||
installPhase=pyprojectInstallDistPhase | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters