CQCL / guppylang

Pythonic quantum-classical programming language
https://pypi.org/project/guppylang
Apache License 2.0
33 stars 3 forks source link

feat: Use `hugr-cli` for validation #455

Closed aborgna-q closed 2 months ago

aborgna-q commented 2 months ago

Spinoff of #454

Replaces the validator python library with a small binary that calls out to hugr-cli validate.

cargo install lets us download tools like hugr-cli and use them for local development, but the support for locally scoped tools is quite flaky. By default, tools are installed in a global directory using the latest version available. It can be forced to use a local target directory via an env variable / cargo config (which didn't always work while I was testing it), and version selection can only be done by passing explicit arguments to the cmd. As there is no central Cargo.toml (or similar) config for it, this relies on every usage point always passing exactly the same arguments. Updating the tool version / patching in a git ref ends up being quite error prone.

The solution in this PR is inspired by cargo's own xtask- subcrates. These are internal crates meant to run some external tool, while centrally defining the dependency versions and artifact paths.

The new validator bin crate here checks if hugr-cli is installed, and calls cargo install with the appropriate parameters otherwise, before running the tool. The version to install matches the one configured in Cargo.toml. This ensures we control the validation in the same way as all the other hugr dependencies (e.g. the hugr dep used in execute_llvm).

Running cargo run now acts the same as executing a locally-versioned hugr-cli.

drive-by: Created a cargo workspace.

note: I temporarily disabled the tests that required the "collections" extension definition. This will get fixed once we merge #454, I just didn't want to wire in a hacky solution that'll get dropped in the next PR.

Closes #390

codecov-commenter commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.40%. Comparing base (2199b48) to head (201eb0b).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #455 +/- ## ========================================== - Coverage 92.70% 90.40% -2.30% ========================================== Files 49 49 Lines 5525 5525 ========================================== - Hits 5122 4995 -127 - Misses 403 530 +127 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.