From 63c2e03fcb46310755c586e776220bec60fed016 Mon Sep 17 00:00:00 2001 From: Jake Arkinstall <65358059+jake-arkinstall@users.noreply.github.com> Date: Mon, 30 Oct 2023 15:22:44 +0000 Subject: [PATCH] Add version into setup call (#1104) The core pytket project uses setuptools_scm to extract version information from .git. This would be awkward in Nix as it would involve copying the .git directory into the pytket source. As we already have the version extracted from another file in the project, which is used to set the version number on the Nix side, we can instead hardcode this version number into setup.py when copying it to the derivation source. Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com> --- nix-support/pytket.nix | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nix-support/pytket.nix b/nix-support/pytket.nix index d99d90b98f..9489ea5589 100644 --- a/nix-support/pytket.nix +++ b/nix-support/pytket.nix @@ -6,7 +6,7 @@ let version = if builtins.length versions > 0 then builtins.elemAt versions 0 else - "0.0.0"; + builtins.trace "Warning: Unable to find version. Defaulting to 0.0.0" "0.0.0"; jsonschema-4180 = super.python3Packages.jsonschema.overrideAttrs (_: rec { version = "4.18.0"; @@ -35,7 +35,7 @@ in { ''; }; pytket = super.python3.pkgs.buildPythonPackage { - name = "pytket"; + pname = "pytket"; inherit version; propagatedBuildInputs = with super.python3.pkgs; [ self.binders @@ -53,19 +53,24 @@ in { unpackPhase = '' cp -r ${../pytket/pytket} pytket; - cp -r ${../pytket/setup.py} setup.py; - cp -r ${../pytket/package.md} package.md; + cp ${../pytket/package.md} package.md; cp -r ${../schemas} schemas; + + # The usual build depends on setuptools-scm to extract the version. + # We have already extracted the version within nix, so we can simply + # inject it into setup.py. + cat ${../pytket/setup.py} | sed 's/setup(/setup(version="${version}",/' > setup.py; + mkdir test_root; cp -r ${../pytket/tests} test_root/tests; + # hardcode the version extracted from docs/conf.py. + chmod 755 pytket + echo '__version__ = "${version}"' > pytket/_version.py; ''; preBuild = '' export USE_NIX=1; ''; postFixup = '' - # hardcode the version extracted from docs/conf.py. - echo '__version__ = "${version}"' > $out/lib/python3.10/site-packages/pytket/_version.py; - # these directories aren't copied by setup.py, so we do it manually cp -r ${ ../pytket/pytket/circuit/display/js