Skip to content

Commit

Permalink
build.hooks.pyprojectDistHook: Make it possible to distribute sdists
Browse files Browse the repository at this point in the history
And not just wheels.
  • Loading branch information
adisbladis committed Feb 13, 2025
1 parent 8266e7b commit e5acd6e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
17 changes: 17 additions & 0 deletions build/checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,21 @@ listToAttrs (
pyprojectHook = pythonSet.pyprojectDistHook;
};

install-dist-sdist =
let
python = pkgs.python3;

pythonSet =
(pkgs.callPackage pyproject-nix.build.packages {
inherit python;
}).overrideScope
buildSystems;
in
(pythonSet.build.override {
pyprojectHook = pythonSet.pyprojectDistHook;
}).overrideAttrs
(_old: {
env.uvBuildType = "sdist";
});

}
2 changes: 1 addition & 1 deletion build/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ in
substitutions = {
inherit pythonInterpreter;
script = substituteAll {
src = ./dist-hook/install-wheels.py;
src = ./dist-hook/install-dist.py;
ugrep = lib.getExe ugrep;
store_dir = builtins.storeDir;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def main():
except KeyError:
check_dist = True

wheels: list[Path] = [dist_file for dist_file in dist.iterdir() if dist_file.name.endswith(".whl")]
dists: list[Path] = list(dist.iterdir())

# Verify that wheel is not containing store path
if check_dist:
for wheel in wheels:
for dist in dists:
p = subprocess.run(
[
"@ugrep@",
Expand All @@ -30,19 +30,19 @@ def main():
# zip
"-z",
"@store_dir@",
wheel,
dist,
]
)
if p.returncode == 0:
raise ValueError(f"""
Built whheel '{wheel.name}' contains a Nix store path reference.
Built distribution '{dist.name}' contains a Nix store path reference.
Wheel not usable for distribution.
Distribution not usable.
""")

# Copy wheels to output
# Copy dists to output
out.mkdir()
for wheel in wheels:
for wheel in dists:
shutil.copy(wheel, out.joinpath(wheel.name))


Expand Down
10 changes: 8 additions & 2 deletions build/hooks/pyproject-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ pyprojectBuildPhase() {
echo "Executing pyprojectBuildPhase"
runHook preBuild

echo "Creating a wheel..."
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @uv@/bin/uv build -v --no-cache --python=@pythonInterpreter@ --offline --no-build-isolation --out-dir dist/ --wheel $uvBuildFlags
local buildType="${uvBuildType-wheel}"

echo "Creating a distribution..."
if [ "${buildType}" != "wheel" ] && [ "${buildType}" != "sdist" ]; then
echo "Build type '${buildType}' is unknown" >> /dev/stderr
false
fi
env PYTHONPATH="${NIX_PYPROJECT_PYTHONPATH}:${PYTHONPATH}" @uv@/bin/uv build -v --no-cache --python=@pythonInterpreter@ --offline --no-build-isolation --out-dir dist/ "--${buildType}" $uvBuildFlags

runHook postBuild
echo "Finished executing pyprojectBuildPhase"
Expand Down

0 comments on commit e5acd6e

Please sign in to comment.