Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMckee4 committed Feb 23, 2025
1 parent 84adf8f commit 36dd05c
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 70 deletions.
31 changes: 13 additions & 18 deletions .github/workflows/test_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,23 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Test pre-commit hooks
run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit run -a
test_code:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

test:
runs-on: ${{ matrix.os }}
container: ghcr.io/gdsfactory/gdsfactory:main
strategy:
max-parallel: 12
matrix:
python-version: ["3.11"]
python-version: ["3.11", "3.12", "3.13"]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
make dev
- name: Test with pytest
run: pytest tests/
- uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: uv sync --all-extras
- name: Run Tests
run: make test
2 changes: 1 addition & 1 deletion .github/write_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

filepath = PATH.repo / "docs" / "cells.rst"

skip = {}
skip: set[str] = set()

skip_plot: tuple[str, ...] = ("add_fiber_array_siepic",)
skip_settings: tuple[str, ...] = ("flatten", "safe_cell_names")
Expand Down
11 changes: 10 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
rev: "v0.4.1"
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
Expand All @@ -39,3 +39,12 @@ repos:
types: [file]
files: \.(j2|yml|yaml)$
exclude: .github/.*

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
args: [--strict]
additional_dependencies:
- gdsfactory
- pytest
11 changes: 2 additions & 9 deletions examples/python/tutorial-5.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@gf.cell
def arm():
def arm() -> gf.Component:
c = gf.Component(name="arm")

straight = gf.components.straight(length=10)
Expand Down Expand Up @@ -35,7 +35,7 @@ def arm():


@gf.cell
def mzi():
def mzi() -> gf.Component:
c = gf.Component("mzi")
a1 = c << arm()
a2 = c << arm()
Expand Down Expand Up @@ -74,11 +74,4 @@ def mzi():
p2.dxmin = die.dxmax - die.info["frame_margin"]
p2.dy = 250

routes = gf.routing.route_bundle_all_angle(
[mymzi.ports["o1"], mymzi.ports["o2"]], [p1.ports["o1"], p2.ports["o1"]]
)

for route in routes:
c.add(route.references)

c.show()
5 changes: 3 additions & 2 deletions gvtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from gdsfactory.get_factories import get_cells
from gdsfactory.pdk import Pdk, constants
from gdsfactory.technology import LayerViews
from gdsfactory.typings import Layer

from gvtt import components
from gvtt.config import PATH
Expand All @@ -19,7 +20,7 @@
LAYER.WG_ARCO_ADD: 100.0,
}

FRAME_LAYERS = {}
FRAME_LAYERS: dict[Layer, str] = {}

PORT_MARKER_LAYER_TO_TYPE = {
LAYER.PORT: "optical",
Expand Down Expand Up @@ -53,7 +54,7 @@
layers=LAYER,
layer_stack=None,
layer_views=LAYER_VIEWS,
layer_transitions=LAYER_TRANSITIONS,
layer_transitions=LAYER_TRANSITIONS, # type: ignore[arg-type]
constants=constants,
)

Expand Down
4 changes: 2 additions & 2 deletions gvtt/components/bend_euler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _eulerR_1550(angle: float) -> float:
if angle == 0:
return 0.0
p, v, a0 = 0.79, 2093.0, 18.75 # for 1550 nm, TE, 1.875 um
return (v / max(abs(angle), a0)) ** (1.0 / p)
return float((v / max(abs(angle), a0)) ** (1.0 / p))


@gf.cell
Expand Down Expand Up @@ -84,7 +84,7 @@ def bend_euler(
if with_bbox and dx.bbox_layers:
padding: list[list[Coordinate]] = []
angle = int(angle)
for offset in dx.bbox_offsets:
for offset in dx.bbox_offsets or []:
top = offset if angle in {180, -180, -90} else 0
bottom = 0 if angle in {-90} else offset
points = get_padding_points(
Expand Down
27 changes: 14 additions & 13 deletions gvtt/components/die.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import gdsfactory as gf
from gdsfactory.components import text
from gdsfactory.typings import ComponentSpec, Float2, LayerSpec
from gdsfactory.typings import ComponentSpec, Coordinate, Float2, LayerSpec

import gvtt
from gvtt.layers import LAYER


def box(x0: float, y0: float, w: float, h: float) -> list[list[float]]:
def box(x0: float, y0: float, w: float, h: float) -> list[Coordinate]:
dw = w / 2.0
dh = h / 2.0
return [
[x0 + dw, y0 + dh],
[x0 + dw, y0 - dh],
[x0 - dw, y0 - dh],
[x0 - dw, y0 + dh],
(x0 + dw, y0 + dh),
(x0 + dw, y0 - dh),
(x0 - dw, y0 - dh),
(x0 - dw, y0 + dh),
]


Expand All @@ -33,20 +34,20 @@ def die(
c = gf.Component(name="die")
w, h = size[0], size[1]

for layer, size in gvtt.frame_dimensions.items():
c.add_polygon(box(w / 2.0 - size / 2.0, 0.0, size, h), layer=layer)
c.add_polygon(box(-w / 2.0 + size / 2.0, 0.0, size, h), layer=layer)
for layer_, size_ in gvtt.frame_dimensions.items():
c.add_polygon(box(w / 2.0 - size_ / 2.0, 0.0, size_, h), layer=layer_)
c.add_polygon(box(-w / 2.0 + size_ / 2.0, 0.0, size_, h), layer=layer_)

c.add_polygon(box(0.0, h / 2.0 - size / 2.0, w, size), layer=layer)
c.add_polygon(box(0.0, -h / 2.0 + size / 2.0, w, size), layer=layer)
c.add_polygon(box(0.0, h / 2.0 - size_ / 2.0, w, size_), layer=layer_)
c.add_polygon(box(0.0, -h / 2.0 + size_ / 2.0, w, size_), layer=layer_)

if bbox_layer:
c.add_polygon(
[[w / 2, h / 2], [w / 2, -h / 2], [-w / 2, -h / 2], [-w / 2, h / 2]],
[(w / 2, h / 2), (w / 2, -h / 2), (-w / 2, -h / 2), (-w / 2, h / 2)],
layer=bbox_layer,
)

c.info["frame_margin"] = gvtt.frame_dimensions[gvtt.LAYER.WG_SNGL_ADD] + 1.5
c.info["frame_margin"] = gvtt.frame_dimensions[LAYER.WG_SNGL_ADD] + 1.5

# c.info["port_x_position_west"] = (
# -w / 2.0 + gvtt.frame_dimensions[gvtt.LAYER.WG_SNGL_ADD] + 1.5
Expand Down
2 changes: 1 addition & 1 deletion gvtt/components/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def xs_rib_strip(
width_trench: float = 10.0,
width_deep: float = 10.75,
dist_deep: float = 3.0,
wg_marking_layer: LayerSpec | None = None,
wg_marking_layer: LayerSpec = LAYER.TYPE_STRIP,
**kwargs: Any,
) -> CrossSection:
"""Return CrossSection of strip waveguide defined by trenches.
Expand Down
6 changes: 3 additions & 3 deletions gvtt/layers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from gdsfactory.technology import LayerMap
from gdsfactory.technology import LayerMap as GFLayerMap
from gdsfactory.typings import Layer


class LayerMap(LayerMap):
class LayerMap(GFLayerMap):
# waveguide types
TYPE_RIB: Layer = (89, 0)
TYPE_STRIP: Layer = (89, 1)
Expand Down Expand Up @@ -105,7 +105,7 @@ class LayerMap(LayerMap):
# LAYER_VIEWS.to_yaml(PATH.lyp_yaml, default_hatch_pattern_name='coarsely dotted')
t = KLayoutTechnology(
name="VTT",
layer_map=LAYER,
layer_map=LAYER, # type: ignore[arg-type]
layer_views=LAYER_VIEWS,
# layer_stack=LAYER_STACK,
# connectivity=connectivity,
Expand Down
2 changes: 1 addition & 1 deletion gvtt/tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def strip(
def vttstrip(
width: float = TECH.width_strip,
width_trench: float = 10.0,
wg_marking_layer: LayerSpec | None = LAYER.TYPE_STRIP,
wg_marking_layer: LayerSpec = LAYER.TYPE_STRIP,
**kwargs: Any,
) -> CrossSection:
"""Return CrossSection of strip waveguide defined by trenches.
Expand Down
4 changes: 2 additions & 2 deletions install_tech.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import sys


def remove_path_or_dir(dest: pathlib.Path):
def remove_path_or_dir(dest: pathlib.Path) -> None:
if dest.is_dir():
os.unlink(dest)
else:
os.remove(dest)


def make_link(src, dest, overwrite: bool = True) -> None:
def make_link(src: pathlib.Path, dest: pathlib.Path, overwrite: bool = True) -> None:
dest = pathlib.Path(dest)
if dest.exists() and not overwrite:
print(f"{dest} already exists")
Expand Down
20 changes: 5 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Operating System :: OS Independent"
]
dependencies = [
"gdsfactory~=9.0.1"
]
dependencies = ["gdsfactory~=9.0.1"]
description = "gdsfactory VTT PDK"
keywords = ["python"]
license = {file = "LICENSE"}
Expand All @@ -23,23 +21,15 @@ requires-python = ">=3.11"
version = "0.1.0"

[project.optional-dependencies]
dev = [
"pre-commit",
"pytest",
"pytest-cov",
"pytest_regressions"
]
docs = [
"autodoc_pydantic",
"jupytext",
"jupyter-book>=0.15.1,<1.1"
]
dev = ["pre-commit", "pytest", "pytest-cov", "pytest_regressions"]
docs = ["autodoc_pydantic", "jupytext", "jupyter-book>=0.15.1,<1.1"]

[tool.codespell]
ignore-words-list = "te, te/tm, te, ba, fpr, fpr_spacing, ro, nd, donot, schem"

[tool.mypy]
python_version = "3.10"
ignore_missing_imports = true
python_version = "3.11"
strict = true

[tool.pylsp-mypy]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from gvtt import cells

skip_test = {}
skip_test: set[str] = set()
cell_names = set(cells.keys()) - set(skip_test)
dirpath_ref = pathlib.Path(__file__).absolute().parent / "ref"


@pytest.fixture(params=cell_names, scope="function")
def component(request) -> Component:
def component(request: pytest.FixtureRequest) -> Component:
return cells[request.param]()


Expand Down

0 comments on commit 36dd05c

Please sign in to comment.