Skip to content

Commit

Permalink
chore!: rename package to guppylang (#108)
Browse files Browse the repository at this point in the history
Closes #80

For some reason some ruff lints (about using `getattr` and `setattr`
only appeared after the package rename so I've resolved those.

BREAKING_CHANGES: package name changed from `guppy` to `guppylang`
  • Loading branch information
ss2165 authored Jan 17, 2024
1 parent 69fac9c commit 888d81d
Show file tree
Hide file tree
Showing 188 changed files with 531 additions and 522 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ jobs:
run: poetry add validator/target/wheels/*

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

- name: Check formatting with ruff
uses: chartboost/ruff-action@v1
with:
src: "./guppy"
src: "./guppylang"
args: format --check

- name: Lint with ruff
uses: chartboost/ruff-action@v1
with:
src: "./guppy"
src: "./guppylang"
args: check

- name: Run tests
Expand Down
10 changes: 5 additions & 5 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"import sys\n",
"sys.path.append(\"..\")\n",
"\n",
"from guppy.hugr.hugr import Hugr\n",
"from guppy.hugr.visualise import hugr_to_graphviz\n",
"from guppy.compiler import GuppyModule, guppy\n",
"from guppylang.hugr.hugr import Hugr\n",
"from guppylang.hugr.visualise import hugr_to_graphviz\n",
"from guppylang.compiler import GuppyModule, guppy\n",
"from typing import Callable\n",
"\n",
"setattr(\n",
Expand Down Expand Up @@ -6732,8 +6732,8 @@
}
],
"source": [
"import guppy.prelude.quantum as quantum\n",
"from guppy.prelude.quantum import Qubit\n",
"import guppylang.prelude.quantum as quantum\n",
"from guppylang.prelude.quantum import Qubit\n",
"\n",
"module = GuppyModule(\"test\")\n",
"module.load(quantum)\n",
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions guppy/ast_util.py → guppylang/ast_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar, cast

if TYPE_CHECKING:
from guppy.gtypes import GuppyType
from guppylang.gtypes import GuppyType

AstNode = (
ast.AST
Expand Down Expand Up @@ -236,9 +236,9 @@ def set_location_from(node: ast.AST, loc: ast.AST) -> None:
def annotate_location(
node: ast.AST, source: str, file: str, line_offset: int, recurse: bool = True
) -> None:
setattr(node, "line_offset", line_offset)
setattr(node, "file", file)
setattr(node, "source", source)
node.line_offset = line_offset # type: ignore[attr-defined]
node.file = file # type: ignore[attr-defined]
node.source = source # type: ignore[attr-defined]

if recurse:
for _field, value in ast.iter_fields(node):
Expand All @@ -253,7 +253,7 @@ def annotate_location(
def get_file(node: AstNode) -> str | None:
"""Tries to retrieve a file annotation from an AST node."""
try:
file = getattr(node, "file")
file = node.file # type: ignore[union-attr]
return file if isinstance(file, str) else None
except AttributeError:
return None
Expand All @@ -262,7 +262,7 @@ def get_file(node: AstNode) -> str | None:
def get_source(node: AstNode) -> str | None:
"""Tries to retrieve a source annotation from an AST node."""
try:
source = getattr(node, "source")
source = node.source # type: ignore[union-attr]
return source if isinstance(source, str) else None
except AttributeError:
return None
Expand All @@ -271,7 +271,7 @@ def get_source(node: AstNode) -> str | None:
def get_line_offset(node: AstNode) -> int | None:
"""Tries to retrieve a line offset annotation from an AST node."""
try:
line_offset = getattr(node, "line_offset")
line_offset = node.line_offset # type: ignore[union-attr]
return line_offset if isinstance(line_offset, int) else None
except AttributeError:
return None
Expand All @@ -288,16 +288,16 @@ def with_loc(loc: ast.AST, node: A) -> A:

def with_type(ty: "GuppyType", node: A) -> A:
"""Annotates an AST node with a type."""
setattr(node, "type", ty)
node.type = ty # type: ignore[attr-defined]
return node


def get_type_opt(node: AstNode) -> Optional["GuppyType"]:
"""Tries to retrieve a type annotation from an AST node."""
from guppy.gtypes import GuppyType
from guppylang.gtypes import GuppyType

try:
ty = getattr(node, "type")
ty = node.type # type: ignore[union-attr]
return ty if isinstance(ty, GuppyType) else None
except AttributeError:
return None
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion guppy/cfg/analysis.py → guppylang/cfg/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Iterable
from typing import Generic, TypeVar

from guppy.cfg.bb import BB
from guppylang.cfg.bb import BB

# Type variable for the lattice domain
T = TypeVar("T")
Expand Down
8 changes: 4 additions & 4 deletions guppy/cfg/bb.py → guppylang/cfg/bb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from typing_extensions import Self

from guppy.ast_util import AstNode, name_nodes_in_ast
from guppy.nodes import DesugaredListComp, NestedFunctionDef, PyExpr
from guppylang.ast_util import AstNode, name_nodes_in_ast
from guppylang.nodes import DesugaredListComp, NestedFunctionDef, PyExpr

if TYPE_CHECKING:
from guppy.cfg.cfg import BaseCFG
from guppylang.cfg.cfg import BaseCFG


@dataclass
Expand Down Expand Up @@ -145,7 +145,7 @@ def visit_PyExpr(self, node: PyExpr) -> None:
def visit_NestedFunctionDef(self, node: NestedFunctionDef) -> None:
# In order to compute the used external variables in a nested function
# definition, we have to run live variable analysis first
from guppy.cfg.analysis import LivenessAnalysis
from guppylang.cfg.analysis import LivenessAnalysis

for bb in node.cfg.bbs:
bb.compute_variable_stats()
Expand Down
16 changes: 8 additions & 8 deletions guppy/cfg/builder.py → guppylang/cfg/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from collections.abc import Iterator
from typing import NamedTuple

from guppy.ast_util import (
from guppylang.ast_util import (
AstVisitor,
ContextAdjuster,
find_nodes,
set_location_from,
template_replace,
with_loc,
)
from guppy.cfg.bb import BB, BBStatement
from guppy.cfg.cfg import CFG
from guppy.checker.core import Globals
from guppy.error import GuppyError, InternalGuppyError
from guppy.gtypes import NoneType
from guppy.nodes import (
from guppylang.cfg.bb import BB, BBStatement
from guppylang.cfg.cfg import CFG
from guppylang.checker.core import Globals
from guppylang.error import GuppyError, InternalGuppyError
from guppylang.gtypes import NoneType
from guppylang.nodes import (
DesugaredGenerator,
DesugaredListComp,
IterEnd,
Expand Down Expand Up @@ -210,7 +210,7 @@ def visit_Pass(self, node: ast.Pass, bb: BB, jumps: Jumps) -> BB | None:
def visit_FunctionDef(
self, node: ast.FunctionDef, bb: BB, jumps: Jumps
) -> BB | None:
from guppy.checker.func_checker import check_signature
from guppylang.checker.func_checker import check_signature

func_ty = check_signature(node, self.globals)
returns_none = isinstance(func_ty.returns, NoneType)
Expand Down
4 changes: 2 additions & 2 deletions guppy/cfg/cfg.py → guppylang/cfg/cfg.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Generic, TypeVar

from guppy.cfg.analysis import (
from guppylang.cfg.analysis import (
AssignmentAnalysis,
DefAssignmentDomain,
LivenessAnalysis,
LivenessDomain,
MaybeAssignmentDomain,
Result,
)
from guppy.cfg.bb import BB, BBStatement
from guppylang.cfg.bb import BB, BBStatement

T = TypeVar("T", bound=BB)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from collections.abc import Sequence
from dataclasses import dataclass

from guppy.ast_util import line_col
from guppy.cfg.bb import BB
from guppy.cfg.cfg import CFG, BaseCFG
from guppy.checker.core import Context, Globals, Locals, Variable
from guppy.checker.expr_checker import ExprSynthesizer, to_bool
from guppy.checker.stmt_checker import StmtChecker
from guppy.error import GuppyError
from guppy.gtypes import GuppyType
from guppylang.ast_util import line_col
from guppylang.cfg.bb import BB
from guppylang.cfg.cfg import CFG, BaseCFG
from guppylang.checker.core import Context, Globals, Locals, Variable
from guppylang.checker.expr_checker import ExprSynthesizer, to_bool
from guppylang.checker.stmt_checker import StmtChecker
from guppylang.error import GuppyError
from guppylang.gtypes import GuppyType

VarRow = Sequence[Variable]

Expand Down
4 changes: 2 additions & 2 deletions guppy/checker/core.py → guppylang/checker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from dataclasses import dataclass
from typing import Any, NamedTuple

from guppy.ast_util import AstNode, name_nodes_in_ast
from guppy.gtypes import (
from guppylang.ast_util import AstNode, name_nodes_in_ast
from guppylang.gtypes import (
BoolType,
FunctionType,
GuppyType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from contextlib import suppress
from typing import Any, NoReturn, cast

from guppy.ast_util import (
from guppylang.ast_util import (
AstNode,
AstVisitor,
breaks_in_loop,
Expand All @@ -36,14 +36,20 @@
with_loc,
with_type,
)
from guppy.checker.core import CallableVariable, Context, DummyEvalDict, Globals, Locals
from guppy.error import (
from guppylang.checker.core import (
CallableVariable,
Context,
DummyEvalDict,
Globals,
Locals,
)
from guppylang.error import (
GuppyError,
GuppyTypeError,
GuppyTypeInferenceError,
InternalGuppyError,
)
from guppy.gtypes import (
from guppylang.gtypes import (
BoolType,
ExistentialTypeVar,
FunctionType,
Expand All @@ -56,7 +62,7 @@
TupleType,
unify,
)
from guppy.nodes import (
from guppylang.nodes import (
DesugaredGenerator,
DesugaredListComp,
GlobalName,
Expand Down Expand Up @@ -807,7 +813,7 @@ def synthesize_comprehension(
node: DesugaredListComp, gens: list[DesugaredGenerator], ctx: Context
) -> tuple[DesugaredListComp, GuppyType]:
"""Helper function to synthesise the element type of a list comprehension."""
from guppy.checker.stmt_checker import StmtChecker
from guppylang.checker.stmt_checker import StmtChecker

def check_linear_use_from_outer_scope(expr: ast.expr, locals: Locals) -> None:
"""Checks if an expression uses a linear variable from an outer scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
import ast
from dataclasses import dataclass

from guppy.ast_util import AstNode, return_nodes_in_ast, with_loc
from guppy.cfg.bb import BB
from guppy.cfg.builder import CFGBuilder
from guppy.checker.cfg_checker import CheckedCFG, check_cfg
from guppy.checker.core import CallableVariable, Context, Globals, Variable
from guppy.checker.expr_checker import check_call, synthesize_call
from guppy.error import GuppyError
from guppy.gtypes import (
from guppylang.ast_util import AstNode, return_nodes_in_ast, with_loc
from guppylang.cfg.bb import BB
from guppylang.cfg.builder import CFGBuilder
from guppylang.checker.cfg_checker import CheckedCFG, check_cfg
from guppylang.checker.core import CallableVariable, Context, Globals, Variable
from guppylang.checker.expr_checker import check_call, synthesize_call
from guppylang.error import GuppyError
from guppylang.gtypes import (
BoundTypeVar,
FunctionType,
GuppyType,
NoneType,
Subst,
type_from_ast,
)
from guppy.nodes import CheckedNestedFunctionDef, GlobalCall, NestedFunctionDef
from guppylang.nodes import CheckedNestedFunctionDef, GlobalCall, NestedFunctionDef


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import ast
from collections.abc import Sequence

from guppy.ast_util import AstVisitor, with_loc
from guppy.cfg.bb import BB, BBStatement
from guppy.checker.core import Context, Variable
from guppy.checker.expr_checker import ExprChecker, ExprSynthesizer
from guppy.error import GuppyError, GuppyTypeError, InternalGuppyError
from guppy.gtypes import GuppyType, NoneType, Subst, TupleType, type_from_ast
from guppy.nodes import NestedFunctionDef
from guppylang.ast_util import AstVisitor, with_loc
from guppylang.cfg.bb import BB, BBStatement
from guppylang.checker.core import Context, Variable
from guppylang.checker.expr_checker import ExprChecker, ExprSynthesizer
from guppylang.error import GuppyError, GuppyTypeError, InternalGuppyError
from guppylang.gtypes import GuppyType, NoneType, Subst, TupleType, type_from_ast
from guppylang.nodes import NestedFunctionDef


class StmtChecker(AstVisitor[BBStatement]):
Expand Down Expand Up @@ -130,7 +130,7 @@ def visit_Return(self, node: ast.Return) -> ast.stmt:
return node

def visit_NestedFunctionDef(self, node: NestedFunctionDef) -> ast.stmt:
from guppy.checker.func_checker import check_nested_func_def
from guppylang.checker.func_checker import check_nested_func_def

if not self.bb:
raise InternalGuppyError("BB required to check nested function def!")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import functools
from typing import TYPE_CHECKING

from guppy.checker.cfg_checker import CheckedBB, CheckedCFG, Signature, VarRow
from guppy.checker.core import Variable
from guppy.compiler.core import (
from guppylang.checker.cfg_checker import CheckedBB, CheckedCFG, Signature, VarRow
from guppylang.checker.core import Variable
from guppylang.compiler.core import (
CompiledGlobals,
DFContainer,
PortVariable,
is_return_var,
return_var,
)
from guppy.compiler.expr_compiler import ExprCompiler
from guppy.compiler.stmt_compiler import StmtCompiler
from guppy.gtypes import SumType, TupleType, type_to_row
from guppy.hugr.hugr import CFNode, Hugr, Node, OutPortV
from guppylang.compiler.expr_compiler import ExprCompiler
from guppylang.compiler.stmt_compiler import StmtCompiler
from guppylang.gtypes import SumType, TupleType, type_to_row
from guppylang.hugr.hugr import CFNode, Hugr, Node, OutPortV

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down
8 changes: 4 additions & 4 deletions guppy/compiler/core.py → guppylang/compiler/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from collections.abc import Iterator
from dataclasses import dataclass

from guppy.ast_util import AstNode
from guppy.checker.core import CallableVariable, Variable
from guppy.gtypes import FunctionType, Inst
from guppy.hugr.hugr import DFContainingNode, Hugr, OutPortV
from guppylang.ast_util import AstNode
from guppylang.checker.core import CallableVariable, Variable
from guppylang.gtypes import FunctionType, Inst
from guppylang.hugr.hugr import DFContainingNode, Hugr, OutPortV


@dataclass
Expand Down
Loading

0 comments on commit 888d81d

Please sign in to comment.