Skip to content

Commit

Permalink
Add version into setup call (#1104)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jake-arkinstall and cqc-alec authored Oct 30, 2023
1 parent 026cdb6 commit 63c2e03
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nix-support/pytket.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -35,7 +35,7 @@ in {
'';
};
pytket = super.python3.pkgs.buildPythonPackage {
name = "pytket";
pname = "pytket";
inherit version;
propagatedBuildInputs = with super.python3.pkgs; [
self.binders
Expand All @@ -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
Expand Down

0 comments on commit 63c2e03

Please sign in to comment.