Skip to content

Commit 6a4840d

Browse files
committed
CAP-ADD: add type checker mypy + refactoring for precommit check pass
1 parent c53c822 commit 6a4840d

9 files changed

Lines changed: 61 additions & 14 deletions

File tree

doc/contribute.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
(contrib_guide)=
22
# Contribute
33

4-
We value all contributions to diffCheck, whether they are bug reports, feature requests, or pull requests. We have a few guidelines to ensure that the process is as smooth as possible.
4+
We welcome pull requests from everyone. Please have a look at the [issue](https://github.com/diffCheckOrg/diffCheck/issues) list to see if there is something you can help with. If you have a new feature in mind, please open an issue to discuss it first.
55

6-
## How to contribute
6+
## Code quality
77

8-
We welcome pull requests from everyone. Please have a look at the [issue](https://github.com/diffCheckOrg/diffCheck/issues) list to see if there is something you can help with. If you have a new feature in mind, please open an issue to discuss it first.
8+
We run [mypy](https://mypy.readthedocs.io/en/stable/index.html) and [] on pre-commit hooks to ensure code quality. Please make sure to run the following commands before submitting a pull request:
99

10-
To contribute, you will need to install your developer's environment to build the project. You can find the instructions in the [development installation guide](dev_documentation).
10+
```console
11+
pre-commit run --all-files
12+
```
13+
14+
## How to contribute
1115

1216
Next, fall the following steps:
1317

@@ -24,4 +28,10 @@ Next, fall the following steps:
2428

2529
```console
2630
git checkout -b my-feature
27-
```
31+
```
32+
33+
4. Add the diffCheck repository as a remote for convinience:
34+
35+
```console
36+
git remote add upstream https://github.com/diffCheckOrg/diffCheck
37+
```

environment.yml

104 Bytes
Binary file not shown.

invokes/versionize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def main(
2828
if manifest_crt_version is not None:
2929
if version <= manifest_crt_version:
3030
print(f"Version {version} is equal or smaller than the current version {manifest_crt_version}. Please provide a version number bigger than the current one.")
31-
return
31+
return False
3232
else:
3333
print("Could not find the current version in the manifest file.")
3434
sys.exit(1)

pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[tool.mypy]
2+
warn_return_any = true
3+
warn_unused_configs = true
4+
exclude = [
5+
"deps",
6+
"src/gh/components/*",
7+
"src/gh/diffCheck/setup.py",
8+
"temp",
9+
"doc"
10+
]
11+
12+
[[tool.mypy.overrides]]
13+
module = [
14+
"Rhino.*",
15+
"rhinoscriptsyntax.*",
16+
"scriptcontext.*",
17+
"Grasshopper.*",
18+
"System.*",
19+
"GH_IO.*",
20+
"clr.*",
21+
"diffcheck_bindings"
22+
]
23+
ignore_missing_imports = true
24+
25+
[[tool.mypy.overrides]]
26+
module = "pefile"
27+
ignore_missing_imports = true

src/gh/diffCheck/diffCheck/df_cvt_bindings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
import scriptcontext as sc
1010
import numpy as np
1111

12-
from diffCheck import diffcheck_bindings
12+
import typing
13+
from typing import List, Dict, Any
1314

14-
def test_bindings() -> bool:
15+
from diffCheck import diffcheck_bindings # type: ignore
16+
17+
def test_bindings() -> Any:
1518
"""
1619
Test the bindings import.
1720

src/gh/diffCheck/diffCheck/df_error_estimation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import numpy as np
7-
from diffCheck import diffcheck_bindings
7+
from diffCheck import diffcheck_bindings # type: ignore
88
import Rhino.Geometry as rg
99

1010

src/gh/diffCheck/diffCheck/df_geometries.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import os
22
from datetime import datetime
33
from dataclasses import dataclass
4+
45
import typing
6+
from typing import Optional
7+
from typing import List, Dict, Any
8+
59
import uuid
610

711
import Rhino
@@ -69,7 +73,7 @@ class DFFace:
6973

7074
# just as breps a first outer loop and then inner loops of DFVertices
7175
all_loops: typing.List[typing.List[DFVertex]]
72-
joint_id: int = None
76+
joint_id: Optional[int] = None
7377

7478
def __post_init__(self):
7579
if len(self.all_loops[0]) < 3:
@@ -106,7 +110,9 @@ def __eq__(self, other):
106110
return False
107111

108112
@classmethod
109-
def from_brep_face(cls, brep_face: rg.BrepFace, joint_id: int = None):
113+
def from_brep_face(cls,
114+
brep_face: rg.BrepFace,
115+
joint_id: Optional[int] = None):
110116
"""
111117
Create a DFFace from a Rhino Brep face
112118
@@ -115,6 +121,7 @@ def from_brep_face(cls, brep_face: rg.BrepFace, joint_id: int = None):
115121
:return face: The DFFace object
116122
"""
117123
all_loops = []
124+
df_face: DFFace = cls([], joint_id)
118125

119126
if brep_face.IsCylinder():
120127
cls.is_cylinder = True

src/gh/diffCheck/diffCheck/df_transformations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _get_lowest_brep_vertex(brep) -> Rhino.Geometry.Point3d:
6363

6464
# find the longest edge of the brep
6565
edges = brep.Edges
66-
longest_edge = None
66+
longest_edge: Rhino.Geometry.Curve = None
6767
longest_edge_length = 0
6868
for edge in edges:
6969
if edge.GetLength() > longest_edge_length:
@@ -73,7 +73,7 @@ def _get_lowest_brep_vertex(brep) -> Rhino.Geometry.Point3d:
7373
# find biggest face
7474
face_indices = longest_edge.AdjacentFaces()
7575
faces = [brep.Faces[face_index] for face_index in face_indices]
76-
biggest_face = None
76+
biggest_face: Rhino.Geometry.BrepFace = None
7777
biggest_face_area = 0
7878
for face in faces:
7979
if rg.AreaMassProperties.Compute(face).Area > biggest_face_area:

src/gh/diffCheck/diffCheck/df_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def compute_ordered_vertices(brep_face) -> typing.List[Rhino.Geometry.Point3d]:
109109
edges = brep_face.DuplicateEdgeCurves()
110110
edges = list(set(edges))
111111

112-
edges_sorted = []
112+
edges_sorted: list[Rhino.Geometry.Curve] = []
113113
while len(edges) > 0:
114114
if len(edges_sorted) == 0:
115115
edges_sorted.append(edges[0])

0 commit comments

Comments
 (0)