Skip to content

Commit 6cd59aa

Browse files
thoradeaothms
authored andcommitted
autopep8 aggressive
autopep8 --in-place --recursive --max-line-length=200 --aggressive --aggressive --aggressive ifcopenshell
1 parent 8439e5b commit 6cd59aa

9 files changed

Lines changed: 61 additions & 35 deletions

File tree

src/ifcopenshell-python/ifcopenshell/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
if int(python_version_tuple[0]) == 2:
5050
# Only for py2, as py3 has exception chaining
5151
import traceback
52+
5253
traceback.print_exc()
5354
print('-' * 64)
5455
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)

src/ifcopenshell-python/ifcopenshell/entity_instance.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ def wrap_value(v):
6565
def wrap(e): return entity_instance(e)
6666

6767
def is_instance(e): return isinstance(e, ifcopenshell_wrapper.entity_instance)
68+
6869
return entity_instance.walk(is_instance, wrap, v)
6970

7071
@staticmethod
7172
def unwrap_value(v):
7273
def unwrap(e): return e.wrapped_data
7374

7475
def is_instance(e): return isinstance(e, entity_instance)
76+
7577
return entity_instance.walk(is_instance, unwrap, v)
7678

7779
def attribute_type(self, attr):
@@ -99,12 +101,13 @@ def __setitem__(self, idx, value):
99101
try:
100102
if isinstance(value, unicode):
101103
value = value.encode("utf-8")
102-
except:
104+
except BaseException:
103105
pass
104106
try:
105107
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
106-
except:
107-
raise ValueError("Expected %s for attribute %s.%s, got %r" % (real_attr_type, self.is_a(), self.attribute_name(idx), value))
108+
except BaseException:
109+
raise ValueError("Expected %s for attribute %s.%s, got %r" % (
110+
real_attr_type, self.is_a(), self.attribute_name(idx), value))
108111
return value
109112

110113
def __len__(self):
@@ -120,7 +123,7 @@ def id(self):
120123
return self.wrapped_data.id()
121124

122125
def __eq__(self, other):
123-
if type(self) != type(other):
126+
if not isinstance(self, type(other)):
124127
return False
125128
return self.wrapped_data == other.wrapped_data
126129

@@ -140,7 +143,7 @@ def _():
140143
if include_identifier:
141144
yield "id", self.id()
142145
yield "type", self.is_a()
143-
except:
146+
except BaseException:
144147
logging.exception("unhandled exception while getting id / type info on {}".format(self))
145148
for i in range(len(self)):
146149
try:
@@ -160,10 +163,12 @@ def get_info_(inst):
160163
return_type=return_type,
161164
ignore=ignore
162165
)
166+
163167
attr_value = entity_instance.walk(is_instance, get_info_, attr_value)
164168
yield self.attribute_name(i), attr_value
165-
except:
169+
except BaseException:
166170
logging.exception("unhandled exception occured setting attribute name for {}".format(self))
171+
167172
return return_type(_())
168173

169174
__dict__ = property(get_info)

src/ifcopenshell-python/ifcopenshell/file.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ def __getitem__(self, key):
6161
elif isinstance(key, basestring):
6262
return entity_instance(self.wrapped_data.by_guid(str(key)))
6363

64-
def by_id(self, id): return self[id]
64+
def by_id(self, id):
65+
return self[id]
6566

66-
def by_guid(self, guid): return self[guid]
67+
def by_guid(self, guid):
68+
return self[guid]
6769

6870
def add(self, inst):
6971
inst.wrapped_data.this.disown()

src/ifcopenshell-python/ifcopenshell/geom/app.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
os.environ['QT_API'] = 'pyqt4'
1616
try:
1717
from pyqode.qt import QtCore
18-
except:
18+
except BaseException:
1919
pass
2020

2121
from PyQt4 import QtGui, QtCore
@@ -24,22 +24,21 @@
2424

2525
try:
2626
from OCC.Display.pyqt4Display import qtViewer3d
27-
except:
27+
except BaseException:
2828
import OCC.Display
2929

3030
try:
3131
import OCC.Display.backend
32-
except:
32+
except BaseException:
3333
pass
3434

3535
try:
3636
OCC.Display.backend.get_backend("qt-pyqt4")
37-
except:
37+
except BaseException:
3838
OCC.Display.backend.load_backend("qt-pyqt4")
3939

4040
from OCC.Display.qtDisplay import qtViewer3d
4141

42-
4342
from .main import settings, iterator
4443
from .occ_utils import display_shape
4544

@@ -58,10 +57,11 @@ def __init__(self):
5857
try:
5958
import ConfigParser
6059
Cfg = ConfigParser.RawConfigParser
61-
except:
60+
except BaseException:
6261
import configparser
6362

64-
def Cfg(): return configparser.ConfigParser(interpolation=None)
63+
def Cfg():
64+
return configparser.ConfigParser(interpolation=None)
6565

6666
conf_file = os.path.expanduser(os.path.join("~", ".ifcopenshell", "app", "snippets.conf"))
6767
if conf_file.startswith("~"):
@@ -114,7 +114,6 @@ def options(self, s):
114114

115115

116116
class application(QtGui.QApplication):
117-
118117
"""A pythonOCC, PyQt based IfcOpenShell application
119118
with two tree views and a graphical 3d view"""
120119

@@ -165,7 +164,8 @@ def select(self, product):
165164
itm = self.product_to_item.get(product)
166165
if itm is None:
167166
return
168-
self.selectionModel().setCurrentIndex(itm, QtGui.QItemSelectionModel.SelectCurrent | QtGui.QItemSelectionModel.Rows)
167+
self.selectionModel().setCurrentIndex(itm,
168+
QtGui.QItemSelectionModel.SelectCurrent | QtGui.QItemSelectionModel.Rows)
169169

170170
class decomposition_treeview(abstract_treeview):
171171

@@ -233,6 +233,7 @@ def add(t):
233233
itm = items[t2] = QtGui.QTreeWidgetItem(items.get(s2, self), [t2])
234234
itm.setData(0, QtCore.Qt.UserRole, t2)
235235
self.children[s2].append(t2)
236+
236237
add(t)
237238

238239
for p in products:
@@ -379,6 +380,7 @@ def yield_shapes():
379380
shp = OCC.AIS.Handle_AIS_Shape.DownCast(li.Value(i + 1))
380381
if not shp.IsNull():
381382
yield shp
383+
382384
return tuple(shp.HashCode(1 << 24) for shp in yield_shapes())
383385

384386
def __init__(self, widget):
@@ -528,6 +530,7 @@ def handler(inst):
528530
for c in self.components:
529531
if c != component:
530532
c.select(inst)
533+
531534
return handler
532535

533536
def __init__(self, settings=None):
@@ -582,7 +585,8 @@ def start(self):
582585
sys.exit(self.exec_())
583586

584587
def browse(self):
585-
filename = QtGui.QFileDialog.getOpenFileName(self.window, 'Open file', ".", "Industry Foundation Classes (*.ifc)")
588+
filename = QtGui.QFileDialog.getOpenFileName(self.window, 'Open file', ".",
589+
"Industry Foundation Classes (*.ifc)")
586590
self.load(filename)
587591

588592
def clear(self):

src/ifcopenshell-python/ifcopenshell/geom/code_editor_pane.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
try:
1313
from PyQt4 import QtWidgets
14-
except:
14+
except BaseException:
1515
QtWidgets = QtGui
1616

1717
try:
@@ -24,14 +24,14 @@
2424
from pyqode.python.backend import server
2525
from pyqode.python import modes as pymodes, panels as pypanels, widgets
2626
from pyqode.python.widgets import PyInteractiveConsole
27+
2728
has_pyqode = True
28-
except:
29+
except BaseException:
2930
has_pyqode = False
3031
CodeEdit = QtWidgets.QPlainTextEdit
3132

3233

3334
class StdoutRedirector(object):
34-
3535
'''A class for redirecting stdout to this Text widget.'''
3636

3737
def __init__(self, widget):
@@ -49,7 +49,6 @@ def write(self, str):
4949

5050

5151
class code_edit(QtGui.QWidget):
52-
5352
class Console(InteractiveConsole):
5453
def __init__(*args):
5554
InteractiveConsole.__init__(*args)

src/ifcopenshell-python/ifcopenshell/geom/main.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,25 @@
3232
def has_occ():
3333
try:
3434
import OCC.BRepTools
35-
except:
35+
except BaseException:
3636
return False
3737
return True
3838

3939

4040
has_occ = has_occ()
4141

4242

43-
def wrap_shape_creation(settings, shape): return shape
43+
def wrap_shape_creation(settings, shape):
44+
return shape
4445

4546

4647
if has_occ:
4748
from . import occ_utils as utils
4849

49-
def wrap_shape_creation(settings, shape): return utils.create_shape_from_serialization(shape) if getattr(settings, 'use_python_opencascade', False) else shape
50+
def wrap_shape_creation(settings, shape): return utils.create_shape_from_serialization(shape) if getattr(settings,
51+
'use_python_opencascade',
52+
False) else shape
53+
5054

5155
# Subclass the settings module to provide an additional
5256
# setting to enable pythonOCC when available
@@ -83,6 +87,7 @@ def __init__(self, settings, file_or_filename):
8387
else:
8488
file_or_filename = os.path.abspath(file_or_filename)
8589
_iterator.__init__(self, settings, file_or_filename)
90+
8691
if has_occ:
8792
def get(self):
8893
return wrap_shape_creation(self.settings, _iterator.get(self))
@@ -108,6 +113,7 @@ def unwrap(value):
108113
elif all(map(lambda v: hasattr(value, v), "XYZ")):
109114
return value.X(), value.Y(), value.Z()
110115
return value
116+
111117
args = [self, unwrap(value)]
112118
if isinstance(value, entity_instance):
113119
args.append(kwargs.get("completely_within", False))
@@ -124,6 +130,7 @@ def unwrap(value):
124130
elif hasattr(value, "Get"):
125131
return value.Get()[:3], value.Get()[3:]
126132
return value
133+
127134
args = [self, unwrap(value)]
128135
if "extend" in kwargs or "completely_within" in kwargs:
129136
args.append(kwargs.get("completely_within", False))
@@ -152,7 +159,9 @@ def iterate(settings, filename):
152159

153160

154161
def make_shape_function(fn):
155-
def entity_instance_or_none(e): return None if e is None else entity_instance(e)
162+
def entity_instance_or_none(e):
163+
return None if e is None else entity_instance(e)
164+
156165
if has_occ:
157166
import OCC.TopoDS
158167

src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def lights():
6161
while True:
6262
try:
6363
active_light = viewer.ActiveLight()
64-
except:
64+
except BaseException:
6565
break
6666
yield active_light
6767
viewer.NextActiveLights()
@@ -115,7 +115,8 @@ def display_shape(shape, clr=None, viewer_handle=None):
115115
ais.SetMaterial(material)
116116

117117
if isinstance(clr, str):
118-
qclr = getattr(OCC.Quantity, "Quantity_NOC_%s" % clr.upper(), getattr(OCC.Quantity, "Quantity_NOC_%s1" % clr.upper(), None))
118+
qclr = getattr(OCC.Quantity, "Quantity_NOC_%s" % clr.upper(),
119+
getattr(OCC.Quantity, "Quantity_NOC_%s1" % clr.upper(), None))
119120
if qclr is None:
120121
raise Exception("No color named '%s'" % clr.upper())
121122
elif isinstance(clr, Iterable):
@@ -146,7 +147,8 @@ def display_shape(shape, clr=None, viewer_handle=None):
146147
for shp, stl in zip(subshapes, representation.styles):
147148
subshape = OCC.AIS.AIS_Shape(shp)
148149
if min(stl) < 0. or max(stl) > 1.:
149-
default_style_applied = stl = DEFAULT_STYLES.get(representation.data.type, DEFAULT_STYLES["DEFAULT"])
150+
default_style_applied = stl = DEFAULT_STYLES.get(representation.data.type,
151+
DEFAULT_STYLES["DEFAULT"])
150152
subshape.SetColor(OCC.Quantity.Quantity_Color(stl[0], stl[1], stl[2], OCC.Quantity.Quantity_TOC_RGB))
151153
subshape.SetMaterial(material)
152154
if len(stl) == 4 and stl[3] < 1.:
@@ -171,7 +173,9 @@ def display_shape(shape, clr=None, viewer_handle=None):
171173
ais = OCC.AIS.AIS_Shape(shape)
172174
ais.SetMaterial(material)
173175

174-
def r(): return random.random() * 0.3 + 0.7
176+
def r():
177+
return random.random() * 0.3 + 0.7
178+
175179
clr = OCC.Quantity.Quantity_Color(r(), r(), r(), OCC.Quantity.Quantity_TOC_RGB)
176180
ais.SetColor(clr)
177181

@@ -211,12 +215,12 @@ def create_shape_from_serialization(brep_object):
211215
try:
212216
brep_data = brep_object.geometry.brep_data
213217
styles = brep_object.geometry.surface_styles
214-
except:
218+
except BaseException:
215219
try:
216220
brep_data = brep_object.brep_data
217221
styles = brep_object.surface_styles
218222
is_product_shape = False
219-
except:
223+
except BaseException:
220224
pass
221225

222226
styles = tuple(styles[i:i + 4] for i in range(0, len(styles), 4))
@@ -228,7 +232,7 @@ def create_shape_from_serialization(brep_object):
228232
ss = OCC.BRepTools.BRepTools_ShapeSet()
229233
ss.ReadFromString(brep_data)
230234
occ_shape = ss.Shape(ss.NbShapes())
231-
except:
235+
except BaseException:
232236
pass
233237

234238
if is_product_shape:

src/ifcopenshell-python/ifcopenshell/guid.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def compress(g):
3333
bs = [int(g[i:i + 2], 16) for i in range(0, len(g), 2)]
3434

3535
def b64(v, l=4):
36-
return ''.join([chars[(v // (64**i)) % 64] for i in range(l)][::-1])
36+
return ''.join([chars[(v // (64 ** i)) % 64] for i in range(l)][::-1])
37+
3738
return ''.join([b64(bs[0], 2)] + [b64((bs[i] << 16) + (bs[i + 1] << 8) + bs[i + 2]) for i in range(1, 16, 3)])
3839

3940

4041
def expand(g):
4142
def b64(v):
4243
return reduce(lambda a, b: a * 64 + b, map(lambda c: chars.index(c), v))
44+
4345
bs = [b64(g[0:2])]
4446
for i in range(5):
4547
d = b64(g[2 + 4 * i:6 + 4 * i])

src/ifcopenshell-python/ifcopenshell/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@
7474
def create(filename=None, timestring=None, organization=None, creator=None,
7575
schema_identifier=None, application_version=None, timestamp=None,
7676
application=None, project_globalid=None, project_name=None):
77-
7877
d = dict(locals())
7978

8079
def _():
8180
for var, value in d.items():
8281
if value is None:
8382
yield var, DEFAULTS.get(var, lambda *args: '')(d)
83+
8484
d.update(dict(_()))
8585

8686
return file.from_string(TEMPLATE % d)

0 commit comments

Comments
 (0)