diff --git a/build/checks/default.nix b/build/checks/default.nix index 07cf773..fa7da8c 100644 --- a/build/checks/default.nix +++ b/build/checks/default.nix @@ -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"; + }); + } diff --git a/build/hooks/default.nix b/build/hooks/default.nix index fe69c9a..6967dc4 100644 --- a/build/hooks/default.nix +++ b/build/hooks/default.nix @@ -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; }; diff --git a/build/hooks/dist-hook/install-wheels.py b/build/hooks/dist-hook/install-dist.py similarity index 71% rename from build/hooks/dist-hook/install-wheels.py rename to build/hooks/dist-hook/install-dist.py index 78751d0..1c229a0 100644 --- a/build/hooks/dist-hook/install-wheels.py +++ b/build/hooks/dist-hook/install-dist.py @@ -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@", @@ -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)) diff --git a/build/hooks/pyproject-build-hook.sh b/build/hooks/pyproject-build-hook.sh index f14e6f7..9bbacac 100644 --- a/build/hooks/pyproject-build-hook.sh +++ b/build/hooks/pyproject-build-hook.sh @@ -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"