Skip to content

Commit fff414d

Browse files
committed
Lint check on source code
1 parent 590e091 commit fff414d

24 files changed

+2211
-1845
lines changed

bundle.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
from shutil import make_archive
55
from cq_editor import __version__ as version
66

7-
out_p = Path('dist/CQ-editor')
7+
out_p = Path("dist/CQ-editor")
88
out_p.rmtree_p()
99

10-
build_p = Path('build')
10+
build_p = Path("build")
1111
build_p.rmtree_p()
1212

1313
system("pyinstaller pyinstaller.spec")
1414

15-
if platform == 'linux':
15+
if platform == "linux":
1616
with out_p:
17-
p = Path('.').glob('libpython*')[0]
18-
p.symlink(p.split(".so")[0]+".so")
19-
20-
make_archive(f'CQ-editor-{version}-linux64','bztar', out_p / '..', 'CQ-editor')
21-
22-
elif platform == 'win32':
23-
24-
make_archive(f'CQ-editor-{version}-win64','zip', out_p / '..', 'CQ-editor')
17+
p = Path(".").glob("libpython*")[0]
18+
p.symlink(p.split(".so")[0] + ".so")
19+
20+
make_archive(f"CQ-editor-{version}-linux64", "bztar", out_p / "..", "CQ-editor")
21+
22+
elif platform == "win32":
23+
24+
make_archive(f"CQ-editor-{version}-win64", "zip", out_p / "..", "CQ-editor")

collect_icons.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,28 @@
22
from subprocess import call
33
from os import remove
44

5-
TEMPLATE = \
6-
'''<RCC>
5+
TEMPLATE = """<RCC>
76
<qresource prefix="/images">
87
{}
98
</qresource>
10-
</RCC>'''
9+
</RCC>"""
1110

12-
ITEM_TEMPLATE = '<file>{}</file>'
11+
ITEM_TEMPLATE = "<file>{}</file>"
1312

14-
QRC_OUT = 'icons.qrc'
15-
RES_OUT = 'src/icons_res.py'
16-
TOOL = 'pyrcc5'
13+
QRC_OUT = "icons.qrc"
14+
RES_OUT = "src/icons_res.py"
15+
TOOL = "pyrcc5"
1716

1817
items = []
1918

20-
for i in glob('icons/*.svg'):
19+
for i in glob("icons/*.svg"):
2120
items.append(ITEM_TEMPLATE.format(i))
22-
23-
24-
qrc_text = TEMPLATE.format('\n'.join(items))
2521

26-
with open(QRC_OUT,'w') as f:
22+
23+
qrc_text = TEMPLATE.format("\n".join(items))
24+
25+
with open(QRC_OUT, "w") as f:
2726
f.write(qrc_text)
28-
29-
call([TOOL,QRC_OUT,'-o',RES_OUT])
27+
28+
call([TOOL, QRC_OUT, "-o", RES_OUT])
3029
remove(QRC_OUT)

cq_editor/__main__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33

44
from PyQt5.QtWidgets import QApplication
55

6-
NAME = 'CQ-editor'
6+
NAME = "CQ-editor"
77

8-
#need to initialize QApp here, otherewise svg icons do not work on windows
9-
app = QApplication(sys.argv,
10-
applicationName=NAME)
8+
# need to initialize QApp here, otherewise svg icons do not work on windows
9+
app = QApplication(sys.argv, applicationName=NAME)
1110

1211
from .main_window import MainWindow
1312

13+
1414
def main():
1515

1616
parser = argparse.ArgumentParser(description=NAME)
17-
parser.add_argument('filename',nargs='?',default=None)
17+
parser.add_argument("filename", nargs="?", default=None)
1818

1919
args = parser.parse_args(app.arguments()[1:])
2020

cq_editor/cq_utils.py

+60-41
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
from OCP.XCAFPrs import XCAFPrs_AISObject
99
from OCP.TopoDS import TopoDS_Shape
1010
from OCP.AIS import AIS_InteractiveObject, AIS_Shape
11-
from OCP.Quantity import \
12-
Quantity_TOC_RGB as TOC_RGB, Quantity_Color, Quantity_NOC_GOLD as GOLD
11+
from OCP.Quantity import (
12+
Quantity_TOC_RGB as TOC_RGB,
13+
Quantity_Color,
14+
Quantity_NOC_GOLD as GOLD,
15+
)
1316
from OCP.Graphic3d import Graphic3d_NOM_JADE, Graphic3d_MaterialAspect
1417

1518
from PyQt5.QtGui import QColor
@@ -25,48 +28,66 @@ def is_cq_obj(obj):
2528
return isinstance(obj, (Workplane, Shape, Assembly, Sketch))
2629

2730

28-
def find_cq_objects(results : dict):
31+
def find_cq_objects(results: dict):
2932

30-
return {k:SimpleNamespace(shape=v,options={}) for k,v in results.items() if is_cq_obj(v)}
33+
return {
34+
k: SimpleNamespace(shape=v, options={})
35+
for k, v in results.items()
36+
if is_cq_obj(v)
37+
}
3138

3239

33-
def to_compound(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Sketch]):
40+
def to_compound(
41+
obj: Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Sketch],
42+
):
3443

3544
vals = []
3645

37-
if isinstance(obj,cq.Workplane):
46+
if isinstance(obj, cq.Workplane):
3847
vals.extend(obj.vals())
39-
elif isinstance(obj,cq.Shape):
48+
elif isinstance(obj, cq.Shape):
4049
vals.append(obj)
41-
elif isinstance(obj,list) and isinstance(obj[0],cq.Workplane):
42-
for o in obj: vals.extend(o.vals())
43-
elif isinstance(obj,list) and isinstance(obj[0],cq.Shape):
50+
elif isinstance(obj, list) and isinstance(obj[0], cq.Workplane):
51+
for o in obj:
52+
vals.extend(o.vals())
53+
elif isinstance(obj, list) and isinstance(obj[0], cq.Shape):
4454
vals.extend(obj)
4555
elif isinstance(obj, TopoDS_Shape):
4656
vals.append(cq.Shape.cast(obj))
47-
elif isinstance(obj,list) and isinstance(obj[0],TopoDS_Shape):
57+
elif isinstance(obj, list) and isinstance(obj[0], TopoDS_Shape):
4858
vals.extend(cq.Shape.cast(o) for o in obj)
4959
elif isinstance(obj, cq.Sketch):
5060
if obj._faces:
5161
vals.append(obj._faces)
5262
else:
5363
vals.extend(obj._edges)
5464
else:
55-
raise ValueError(f'Invalid type {type(obj)}')
65+
raise ValueError(f"Invalid type {type(obj)}")
5666

5767
return cq.Compound.makeCompound(vals)
5868

5969

60-
def to_workplane(obj : cq.Shape):
70+
def to_workplane(obj: cq.Shape):
6171

62-
rv = cq.Workplane('XY')
63-
rv.objects = [obj,]
72+
rv = cq.Workplane("XY")
73+
rv.objects = [
74+
obj,
75+
]
6476

6577
return rv
6678

6779

68-
def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Shape], cq.Assembly, AIS_InteractiveObject],
69-
options={}):
80+
def make_AIS(
81+
obj: Union[
82+
cq.Workplane,
83+
List[cq.Workplane],
84+
cq.Shape,
85+
List[cq.Shape],
86+
cq.Assembly,
87+
AIS_InteractiveObject,
88+
],
89+
options={},
90+
):
7091

7192
shape = None
7293

@@ -82,28 +103,29 @@ def make_AIS(obj : Union[cq.Workplane, List[cq.Workplane], cq.Shape, List[cq.Sha
82103
set_material(ais, DEFAULT_MATERIAL)
83104
set_color(ais, DEFAULT_FACE_COLOR)
84105

85-
if 'alpha' in options:
86-
set_transparency(ais, options['alpha'])
87-
if 'color' in options:
88-
set_color(ais, to_occ_color(options['color']))
89-
if 'rgba' in options:
90-
r,g,b,a = options['rgba']
91-
set_color(ais, to_occ_color((r,g,b)))
106+
if "alpha" in options:
107+
set_transparency(ais, options["alpha"])
108+
if "color" in options:
109+
set_color(ais, to_occ_color(options["color"]))
110+
if "rgba" in options:
111+
r, g, b, a = options["rgba"]
112+
set_color(ais, to_occ_color((r, g, b)))
92113
set_transparency(ais, a)
93114

94-
return ais,shape
115+
return ais, shape
95116

96117

97-
def export(obj : Union[cq.Workplane, List[cq.Workplane]], type : str,
98-
file, precision=1e-1):
118+
def export(
119+
obj: Union[cq.Workplane, List[cq.Workplane]], type: str, file, precision=1e-1
120+
):
99121

100122
comp = to_compound(obj)
101123

102-
if type == 'stl':
124+
if type == "stl":
103125
comp.exportStl(file, tolerance=precision)
104-
elif type == 'step':
126+
elif type == "step":
105127
comp.exportStep(file)
106-
elif type == 'brep':
128+
elif type == "brep":
107129
comp.exportBrep(file)
108130

109131

@@ -116,17 +138,14 @@ def to_occ_color(color) -> Quantity_Color:
116138
elif isinstance(color[0], float):
117139
color = QColor.fromRgbF(*color)
118140
else:
119-
raise ValueError('Unknown color format')
141+
raise ValueError("Unknown color format")
120142
else:
121143
color = QColor(color)
122144

123-
return Quantity_Color(color.redF(),
124-
color.greenF(),
125-
color.blueF(),
126-
TOC_RGB)
145+
return Quantity_Color(color.redF(), color.greenF(), color.blueF(), TOC_RGB)
127146

128147

129-
def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
148+
def get_occ_color(obj: Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
130149

131150
if isinstance(obj, AIS_InteractiveObject):
132151
color = Quantity_Color()
@@ -137,7 +156,7 @@ def get_occ_color(obj : Union[AIS_InteractiveObject, Quantity_Color]) -> QColor:
137156
return QColor.fromRgbF(color.Red(), color.Green(), color.Blue())
138157

139158

140-
def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
159+
def set_color(ais: AIS_Shape, color: Quantity_Color) -> AIS_Shape:
141160

142161
drawer = ais.Attributes()
143162
drawer.SetupOwnShadingAspect()
@@ -146,7 +165,7 @@ def set_color(ais : AIS_Shape, color : Quantity_Color) -> AIS_Shape:
146165
return ais
147166

148167

149-
def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Shape:
168+
def set_material(ais: AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Shape:
150169

151170
drawer = ais.Attributes()
152171
drawer.SetupOwnShadingAspect()
@@ -155,7 +174,7 @@ def set_material(ais : AIS_Shape, material: Graphic3d_MaterialAspect) -> AIS_Sha
155174
return ais
156175

157176

158-
def set_transparency(ais : AIS_Shape, alpha: float) -> AIS_Shape:
177+
def set_transparency(ais: AIS_Shape, alpha: float) -> AIS_Shape:
159178

160179
drawer = ais.Attributes()
161180
drawer.SetupOwnShadingAspect()
@@ -184,13 +203,13 @@ def reload_cq():
184203
reload(cq.occ_impl.exporters.dxf)
185204
reload(cq.occ_impl.exporters.amf)
186205
reload(cq.occ_impl.exporters.json)
187-
#reload(cq.occ_impl.exporters.assembly)
206+
# reload(cq.occ_impl.exporters.assembly)
188207
reload(cq.occ_impl.exporters)
189208
reload(cq.assembly)
190209
reload(cq)
191210

192211

193-
def is_obj_empty(obj : Union[cq.Workplane,cq.Shape]) -> bool:
212+
def is_obj_empty(obj: Union[cq.Workplane, cq.Shape]) -> bool:
194213

195214
rv = False
196215

cq_editor/cqe_run.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import os, sys, asyncio
22

3-
if 'CASROOT' in os.environ:
4-
del os.environ['CASROOT']
3+
if "CASROOT" in os.environ:
4+
del os.environ["CASROOT"]
55

6-
if sys.platform == 'win32':
6+
if sys.platform == "win32":
77
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
88

99
from cq_editor.__main__ import main
1010

1111

12-
if __name__ == '__main__':
13-
main()
12+
if __name__ == "__main__":
13+
main()

0 commit comments

Comments
 (0)