Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,19 @@ jobs:
codecov:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff pytest coverage
pip install .
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff check --output-format=github --select=E9,F63,F7,F82 --target-version=py310 .
# default set of ruff rules with GitHub Annotations
ruff check --output-format=github --target-version=py310 .
- name: Test with pytest
pip install .[dev]
- name: Codecov with pytest
run: |
coverage run -m pytest
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lint

on:
- push
- pull_request

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python 3.10
uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Lint with ruff
run: |
ruff check --output-format=github .
7 changes: 3 additions & 4 deletions .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ jobs:
- "3.12"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
pip install .
pip install .[dev]
- name: Typecheck with mypy
run: |
mypy --ignore-missing-imports ocpsvg
14 changes: 4 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,21 @@ jobs:
- "3.12"
os:
- macos-latest
- macos-15-intel
- ubuntu-latest
- windows-latest

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff pytest
pip install .
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff check --output-format=github --select=E9,F63,F7,F82 --target-version=py310 .
# default set of ruff rules with GitHub Annotations
ruff check --output-format=github --target-version=py310 .
pip install .[dev]
- name: Test with pytest
run: |
pytest
4 changes: 2 additions & 2 deletions ocpsvg/hlr.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ def compute_edges(self, shapes: Iterable[TopoDS_Shape], with_hidden: bool = True
yield HlrEdge(
type=type,
is_hidden=not is_visible,
projected_edge=TopoDS.Edge_s(edge_in_2d),
edge_in_3d=TopoDS.Edge_s(edge_in_3d),
projected_edge=TopoDS.Edge(edge_in_2d),
edge_in_3d=TopoDS.Edge(edge_in_3d),
shape_index=shape_index,
)

Expand Down
6 changes: 3 additions & 3 deletions ocpsvg/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def face_outer_wire(face: TopoDS_Face) -> TopoDS_Wire:
def face_inner_wires(face: TopoDS_Face) -> list[TopoDS_Wire]:
"""Find the inner wires of a face."""
outer = face_outer_wire(face)
return [TopoDS.Wire_s(w) for w in topoDS_iterator(face) if not w.IsSame(outer)]
return [TopoDS.Wire(w) for w in topoDS_iterator(face) if not w.IsSame(outer)]


def face_from_wires(
Expand Down Expand Up @@ -252,10 +252,10 @@ def closed_wire(wire: TopoDS_Wire) -> TopoDS_Wire:
# wire has no edges
return wire

adaptor = BRepAdaptor_Curve(TopoDS.Edge_s(first_edge))
adaptor = BRepAdaptor_Curve(TopoDS.Edge(first_edge))
start = adaptor.Value(adaptor.FirstParameter())

adaptor = BRepAdaptor_Curve(TopoDS.Edge_s(last_edge))
adaptor = BRepAdaptor_Curve(TopoDS.Edge(last_edge))
end = adaptor.Value(adaptor.LastParameter())

if not start.IsEqual(end, _TOLERANCE):
Expand Down
16 changes: 8 additions & 8 deletions ocpsvg/svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def transform_f(shape: FaceOrWire) -> FaceOrWire:
if flip_y:
mirrored.Reverse()
if isinstance(shape, TopoDS_Face):
return TopoDS.Face_s(mirrored)
return TopoDS.Face(mirrored)
elif isinstance(shape, TopoDS_Wire):
return TopoDS.Wire_s(mirrored)
return TopoDS.Wire(mirrored)
else:
raise AssertionError(f"somehow got unexpected shape {shape}")

Expand Down Expand Up @@ -344,7 +344,7 @@ def transform_if_needed(wire: TopoDS_Wire):
*(element.transform.b, element.transform.d, 0.0, element.transform.f), # type: ignore
*(0.0, 0.0, 1.0, 0.0), # type: ignore
)
return TopoDS.Wire_s(BRepBuilderAPI_Transform(wire, trsf).Shape())
return TopoDS.Wire(BRepBuilderAPI_Transform(wire, trsf).Shape())
else:
gtrsf = gp_GTrsf()
gtrsf.SetValue(1, 1, element.transform.a) # type: ignore
Expand All @@ -353,7 +353,7 @@ def transform_if_needed(wire: TopoDS_Wire):
gtrsf.SetValue(2, 2, element.transform.d) # type: ignore
gtrsf.SetValue(1, 4, element.transform.e) # type: ignore
gtrsf.SetValue(1, 4, element.transform.f) # type: ignore
return TopoDS.Wire_s(BRepBuilderAPI_GTransform(wire, gtrsf).Shape())
return TopoDS.Wire(BRepBuilderAPI_GTransform(wire, gtrsf).Shape())

if isinstance(element, (svgelements.Circle, svgelements.Ellipse)):
cx = float(element.cx) # type: ignore
Expand Down Expand Up @@ -498,7 +498,7 @@ def face_to_svg_path(
for wire in topoDS_iterator(face):
cmd = None
for cmd in wire_to_svg_path(
TopoDS.Wire_s(wire),
TopoDS.Wire(wire),
tolerance=tolerance,
use_cubics=use_cubics,
use_quadratics=use_quadratics,
Expand Down Expand Up @@ -527,7 +527,7 @@ def wire_to_svg_path(

yield from chain.from_iterable(
edge_to_svg_path(
TopoDS.Edge_s(edge),
TopoDS.Edge(edge),
tolerance=tolerance,
use_cubics=use_cubics,
use_quadratics=use_quadratics,
Expand All @@ -543,15 +543,15 @@ def wire_to_svg_path(
# We'll add remaining edges individually

# TODO use a set if/when OCP implements `__eq__`
all_edges = {hash(e): e for e in map(TopoDS.Edge_s, topoDS_iterator(wire))}
all_edges = {hash(e): e for e in map(TopoDS.Edge, topoDS_iterator(wire))}

if len(ordered_edges) < len(all_edges):
for e in ordered_edges:
all_edges.pop(hash(e))

yield from chain.from_iterable(
edge_to_svg_path(
TopoDS.Edge_s(edge),
TopoDS.Edge(edge),
tolerance=tolerance,
use_cubics=use_cubics,
use_quadratics=use_quadratics,
Expand Down
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,37 @@
[project]
name = "ocpsvg"
readme = "readme-pypi.md"
version = "0.5.0"
version = "0.6.0"
requires-python = ">=3.10"
dependencies = [
"cadquery-ocp >= 7.8.1, < 7.9.0",
"cadquery_ocp_proxy >= 7.9, < 8.0",
"svgelements >= 1.9.1, <2",
]


[project.optional-dependencies]
dev = [
"cadquery_ocp_novtk >=7.9, < 8.0",
"pytest",
"coverage",
"mypy",
"ruff",
]

[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.ruff]
target-version = "py310"

[tool.ruff.lint]
select = ["E4", "E7", "E9", "F"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]

Expand Down
8 changes: 4 additions & 4 deletions tests/test_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_arc_to_cubic_transformed():

t = gp_Trsf()
t.SetTranslationPart(gp_Vec(8, 4, 0))
transformed_edge = TopoDS.Edge_s(
transformed_edge = TopoDS.Edge(
BRepBuilderAPI_Transform(edge, t, False, False).Shape()
)

Expand Down Expand Up @@ -319,7 +319,7 @@ def test_nonmanifold_wire():
],
)
def test_wire_to_svg(wire: TopoDS_Wire, svg_d: str, opts: dict[str, Any]):
path = SvgPath(wire_to_svg_path(TopoDS.Wire_s(wire), tolerance=1e-5, **opts))
path = SvgPath(wire_to_svg_path(TopoDS.Wire(wire), tolerance=1e-5, **opts))
assert svg_path_tokens(path) == approx(svg_path_tokens(svg_d), abs=1e-4), str(path)


Expand Down Expand Up @@ -982,7 +982,7 @@ def test_fix_closing_lines_str():
)
for wire in wires_from_svg_path(d):
for edge in topoDS_iterator(wire):
curve = edge_to_curve(TopoDS.Edge_s(edge))
curve = edge_to_curve(TopoDS.Edge(edge))
assert curve.GetType() != GeomAbs_CurveType.GeomAbs_Line


Expand Down Expand Up @@ -1027,7 +1027,7 @@ def test_circles_and_ellipses(
assert isinstance(imported[0], TopoDS_Wire)

curves = [
edge_to_curve(TopoDS.Edge_s(e)).Curve().Curve()
edge_to_curve(TopoDS.Edge(e)).Curve().Curve()
for e in topoDS_iterator(imported[0])
]
assert len(curves) == 1
Expand Down