Skip to content

Commit

Permalink
[feature] Add mypy support to nix builds of pytket (#1138)
Browse files Browse the repository at this point in the history
* Nix: added pyi interface files to pytket output, and added mypy checks on pytket and the tests into the checkPhase of the pytket nix derivation. Added result directory to .gitignore incase anyone runs nix build in the source directory.

* Removed unnecessary print statement from setup.py in nix builds

* Added space between loops in setup.py to keep the linter happy

* Additional lint fix

---------

Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
  • Loading branch information
jake-arkinstall and cqc-alec authored Nov 22, 2023
1 parent 49db4be commit 8d84e19
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ pytket/tests/qasm_test_files/testout6.qasm
# IDEs
.idea
.vscode

#nix
result
7 changes: 7 additions & 0 deletions nix-support/pytket.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ in {
cp -r ${../pytket/pytket} pytket;
cp ${../pytket/package.md} package.md;
cp -r ${../schemas} schemas;
cp -r ${../pytket/mypy.ini} mypy.ini;
# The usual build depends on setuptools-scm to extract the version.
# We have already extracted the version within nix, so we can simply
Expand All @@ -80,6 +81,7 @@ in {
} $out/lib/python${super.python3.pythonVersion}/site-packages/pytket/circuit/display/static;
'';
checkInputs = with super.python3.pkgs; [
mypy
pytest
pytest-cov
pytest-benchmark
Expand All @@ -90,6 +92,11 @@ in {
] ++ [jsonschema-4180];
checkPhase = ''
export HOME=$TMPDIR;
# run mypy
python -m mypy --config-file=mypy.ini --no-incremental -p pytket -p test_root.tests;
# run tests
chmod 700 $TMPDIR/test_root/tests/qasm_test_files;
cd test_root/tests;
python -m pytest -s .
Expand Down
4 changes: 4 additions & 0 deletions pytket/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def run(self):
if not os.path.isdir(libpath):
shutil.copy(libpath, extdir)

for interface_file in os.listdir("pytket/_tket"):
if interface_file.endswith(".pyi") or interface_file.endswith(".py"):
shutil.copy(os.path.join("pytket/_tket", interface_file), extdir)


plat_name = os.getenv("WHEEL_PLAT_NAME")

Expand Down

0 comments on commit 8d84e19

Please sign in to comment.