Skip to content

Commit

Permalink
chore: switch to poetry for build system (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Jan 11, 2024
1 parent 425e277 commit e17ac31
Show file tree
Hide file tree
Showing 8 changed files with 668 additions and 38 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: pyproject.toml
cache: "poetry"

- name: Build Hugr validator
uses: PyO3/maturin-action@v1
Expand All @@ -29,14 +29,14 @@ jobs:
rust-toolchain: '1.75'
working-directory: validator

- name: Install Hugr validator
run: pip install validator/target/wheels/*

- name: Install Guppy
run: pip install -e '.[dev]'
run: poetry install

- name: Install Hugr validator
run: poetry add validator/target/wheels/*

- name: Type check with mypy
run: mypy guppy
run: poetry run mypy guppy

- name: Check formatting with ruff
uses: chartboost/ruff-action@v1
Expand All @@ -51,4 +51,4 @@ jobs:
args: check

- name: Run tests
run: pytest
run: poetry run pytest
5 changes: 4 additions & 1 deletion devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
{
languages.python = {
enable = true;
venv.enable = true;
poetry = {
enable = true;
activate.enable = true;
};
};

languages.rust = {
Expand Down
4 changes: 2 additions & 2 deletions guppy/cfg/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def visit_FunctionDef(
bb.statements.append(new_node)
return bb

def generic_visit(self, node: ast.AST, bb: BB, jumps: Jumps) -> BB | None: # type: ignore[override]
def generic_visit(self, node: ast.AST, bb: BB, jumps: Jumps) -> BB | None:
# When adding support for new statements, we have to remember to use the
# ExprBuilder to transform all included expressions!
raise GuppyError("Statement is not supported", node)
Expand Down Expand Up @@ -365,7 +365,7 @@ def visit_IfExp(self, node: ast.IfExp, bb: BB, true_bb: BB, false_bb: BB) -> Non
self.visit(node.body, then_bb, true_bb, false_bb)
self.visit(node.orelse, else_bb, true_bb, false_bb)

def generic_visit(self, node: ast.expr, bb: BB, true_bb: BB, false_bb: BB) -> None: # type: ignore[override]
def generic_visit(self, node: ast.expr, bb: BB, true_bb: BB, false_bb: BB) -> None:
# We can always fall back to building the node as a regular expression and using
# the result as a branch predicate
pred, bb = ExprBuilder.build(node, self.cfg, bb)
Expand Down
4 changes: 1 addition & 3 deletions guppy/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ def visit_Call(self, node: ast.Call, ty: GuppyType) -> tuple[ast.expr, Subst]:
else:
raise GuppyTypeError(f"Expected function type, got `{func_ty}`", node.func)

def generic_visit( # type: ignore[override]
self, node: ast.expr, ty: GuppyType
) -> tuple[ast.expr, Subst]:
def generic_visit(self, node: ast.expr, ty: GuppyType) -> tuple[ast.expr, Subst]:
# Try to synthesize and then check if we can unify it with the given type
node, synth = self._synthesize(node, allow_free_vars=False)
subst, inst = check_type_against(synth, ty, node, self._kind)
Expand Down
2 changes: 1 addition & 1 deletion guppy/hugr/hugr.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass, field
from typing import Any, Optional

import networkx as nx # type: ignore[import]
import networkx as nx # type: ignore[import-untyped]

import guppy.hugr.ops as ops
import guppy.hugr.raw as raw
Expand Down
2 changes: 1 addition & 1 deletion guppy/hugr/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections.abc import Iterable
from typing import TYPE_CHECKING

import graphviz as gv # type: ignore[import]
import graphviz as gv # type: ignore[import-untyped]

from guppy.cfg.analysis import (
DefAssignmentDomain,
Expand Down
630 changes: 630 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

41 changes: 20 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
[tool.poetry]
name = "guppy"
authors = [{ name = "Mark Koch", email = "[email protected]" }]
version = "0.1.0"
requires-python = ">=3.9"
dependencies = ["graphviz", "networkx", "ormsgpack", "pydantic==2.5.3"]
description = ""
authors = ["Mark Koch <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
license = { text = "Apache-2.0" }

[project.optional-dependencies]
dev = [
"build",
"maturin>=1.1,<2.0",
"mypy==1.3.0",
"pip-tools", # provides pip-compile
"pre-commit",
"pytest",
"ruff",
]
[tool.poetry.dependencies]
python = "^3.10"
graphviz = "^0.20.1"
networkx = "^3.2.1"
ormsgpack = "^1.4.1"
pydantic = "^2.5.3"

[tool.setuptools]
py-modules = ["guppy"]
[tool.poetry.group.dev.dependencies]
pytest = "^7.4.4"
mypy = "^1.8.0"
pre-commit = "^3.6.0"
ruff = "^0.1.11"
maturin = "^1.4.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
plugins = ["pydantic.mypy"]
Expand Down

0 comments on commit e17ac31

Please sign in to comment.