Skip to content

Commit 4d0e825

Browse files
authored
add check for E221,E222,E227,E228 to the linter and extend it to dev/ (#53)
1 parent 572c71e commit 4d0e825

File tree

11 files changed

+131
-116
lines changed

11 files changed

+131
-116
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ jobs:
2020
- name: Run pycodestyle
2121
shell: bash -l {0}
2222
# We currently only check for some warnings. We should enable & fix more of them.
23-
run: pycodestyle --select=E111,E225,E302,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 spherogram_src/
23+
run: pycodestyle --select=E111,E221,E222,E225,E227,E228,E302,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 spherogram_src/
24+
run: pycodestyle --select=E111,E221,E222,E225,E227,E228,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 dev/
2425
- name: Run cython-lint
2526
shell: bash -l {0}
2627
run: cython-lint .

dev/DTcodes.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def next(self):
144144

145145
__next__ = next
146146

147+
147148
class DTFatEdge(FatEdge):
148149
"""
149150
A fat edge which can be marked and belongs to a link component.
@@ -161,17 +162,17 @@ def PD_index(self):
161162
This method returns the edge label.
162163
"""
163164
v = self[0]
164-
if self.slot(v)%2 == 0:
165+
if self.slot(v) % 2 == 0:
165166
return v[0]
166-
else:
167-
return v[1]
167+
return v[1]
168+
168169

169170
class DTFatGraph(FatGraph):
170171
edge_class = DTFatEdge
171172

172173
def __init__(self, pairs=[], singles=[]):
173174
FatGraph.__init__(self, pairs, singles)
174-
self.marked_valences = dict( (v,0) for v in self.vertices )
175+
self.marked_valences = {v: 0 for v in self.vertices}
175176
self.stack = []
176177
self.pushed = False
177178

@@ -290,7 +291,7 @@ def marked_arc(self, vertex):
290291
raise ValueError('Marked graph is a circle')
291292
edges = [e for e in self(V) if e.marked and e != edge]
292293
if len(edges) == 0:
293-
raise ValueError('Marked graph has a dead end at %s.'%V)
294+
raise ValueError('Marked graph has a dead end at %s.' % V)
294295
if len(edges) > 1:
295296
break
296297
else:
@@ -402,7 +403,6 @@ def _boundary_slots(self, edge, side):
402403
"""
403404
if not edge.marked:
404405
raise ValueError('Must begin at a marked edge.')
405-
result = set()
406406
first_vertex = vertex = edge[1]
407407
while True:
408408
end = 0 if edge[0] is vertex else 1
@@ -412,7 +412,7 @@ def _boundary_slots(self, edge, side):
412412
interior_edge = self(vertex)[slot]
413413
if not interior_edge.marked:
414414
# For lookups, slot values must be in 0,1,2,3
415-
yield vertex, slot%4
415+
yield vertex, slot % 4
416416
else:
417417
break
418418
if k == 0:
@@ -441,9 +441,8 @@ def flip(self, vertex):
441441
Move the edge at the North slot to the South slot, and
442442
move the edge in the South slot to the North slot.
443443
"""
444-
#print 'flipping %s'%vertex
445444
if self.marked_valences[vertex] > 2:
446-
msg = 'Cannot flip %s with marked valence %d.'%(
445+
msg = 'Cannot flip %s with marked valence %d.' % (
447446
vertex, self.marked_valences[vertex])
448447
raise FlippingError(msg)
449448
self.reorder(vertex, (North, East, South, West))
@@ -462,7 +461,7 @@ def flipped(self, vertex):
462461
Has this vertex been flipped?
463462
"""
464463
return bool(len([e for e in self(vertex)
465-
if e[1] is vertex and e.slots[1] in (2,3)])%2)
464+
if e[1] is vertex and e.slots[1] in (2, 3)]) % 2)
466465

467466
def sign(self, vertex):
468467
"""
@@ -507,14 +506,14 @@ def KLP_dict(self, vertex, indices):
507506
edges = self(vertex)
508507
neighbors = self[vertex]
509508
strands = [self.KLP_strand(vertex, edge) for edge in edges]
510-
ids = [ indices[v] for v in neighbors ]
509+
ids = [indices[v] for v in neighbors]
511510

512511
KLP['sign'] = 'R' if self.sign(vertex) == 1 else 'L'
513512
slot = 1 if flipped else 0
514513
KLP['Xbackward_neighbor'] = ids[slot]
515514
KLP['Xbackward_strand'] = strands[slot]
516515
slot = 3 if flipped else 2
517-
KLP['Xforward_neighbor'] = ids[slot]
516+
KLP['Xforward_neighbor'] = ids[slot]
518517
KLP['Xforward_strand'] = strands[slot]
519518
KLP['Xcomponent'] = edges[slot].component
520519
slot = 2 if flipped else 1
@@ -568,7 +567,7 @@ def decode(self, dt, flips=None):
568567
if dt[:2] == '0x':
569568
dt_bytes = [int(dt[n:n+2], 16) for n in range(2,len(dt),2)]
570569
self.code, self.flips = self.unpack_signed_DT(dt_bytes)
571-
elif ord(dt[-1]) & 1<<7:
570+
elif ord(dt[-1]) & 1 << 7:
572571
dt_bytes = bytearray(dt)
573572
self.code, self.flips = self.unpack_signed_DT(dt)
574573
else:
@@ -628,12 +627,12 @@ def unpack_signed_DT(self, signed_dt):
628627
component = []
629628
flips = []
630629
for byte in bytearray(signed_dt):
631-
flips.append(bool(byte & 1<<6))
632-
label = (1 + byte & 0x1f)<<1
633-
if byte & 1<<5:
630+
flips.append(bool(byte & 1 << 6))
631+
label = (1 + byte & 0x1f) << 1
632+
if byte & 1 << 5:
634633
label = -label
635634
component.append(label)
636-
if byte & 1<<7:
635+
if byte & 1 << 7:
637636
dt.append(tuple(component))
638637
component = []
639638
return dt, flips
@@ -642,7 +641,7 @@ def convert_alpha(self, code):
642641
code = string_to_ints(code)
643642
num_crossings, components = code[:2]
644643
comp_lengths = code[2:2+components]
645-
crossings = [x<<1 for x in code[2+components:]]
644+
crossings = [x << 1 for x in code[2+components:]]
646645
assert len(crossings) == num_crossings
647646
return partition_list(crossings, comp_lengths)
648647

@@ -810,20 +809,20 @@ def signed_DT(self):
810809
for component in self.code:
811810
for label in component:
812811
byte = abs(label)
813-
byte = (byte>>1) - 1
812+
byte = (byte >> 1) - 1
814813
if label < 0:
815-
byte |= 1<<5
814+
byte |= 1 << 5
816815
if next_flip():
817-
byte |= 1<<6
816+
byte |= 1 << 6
818817
code_bytes.append(byte)
819-
code_bytes[-1] |= 1<<7
818+
code_bytes[-1] |= 1 << 7
820819
return bytes(code_bytes)
821820

822821
def hex_signed_DT(self):
823822
"""
824823
Return the hex encoding of the signed DT byte sequence.
825824
"""
826-
return '0x'+''.join('%.2x'%b for b in bytearray(self.signed_DT()))
825+
return '0x' + ''.join('%.2x' % b for b in bytearray(self.signed_DT()))
827826

828827
def PD(self, KnotTheory=False):
829828
G = self.fat_graph

dev/dev_malik/mutation/tangle_patch.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def add_random_crossing(self,label):
4646
new_strand = randint(0,3)
4747
old_crossing[old_strand] = new_crossing[new_strand]
4848
for i in range(1,4):
49-
adj.insert(old_position,(new_crossing,(new_strand-i)%4))
49+
adj.insert(old_position,(new_crossing,(new_strand-i) % 4))
5050
adj[len(adj)/2:] = reversed(adj[len(adj)/2:])
5151
tangle_copy.crossings.append(new_crossing)
5252
tangle_copy.n = self.n+1
@@ -299,13 +299,13 @@ def _is_injection(pairs):
299299
a strand on the boundary of a tangle and moving to the other
300300
end of that strand.
301301
"""
302-
def cross_strand(self,i):
302+
def cross_strand(self, i):
303303
if i >= 2*self.n:
304304
raise Exception("Not a valid start position for strand")
305305
cs = self.adjacent[i]
306306
strand = [cs]
307-
while (cs[0],(cs[1]+2)%4) not in self.adjacent:
308-
cs = cs[0].adjacent[(cs[1]+2)%4]
307+
while (cs[0], (cs[1] + 2) % 4) not in self.adjacent:
308+
cs = cs[0].adjacent[(cs[1] + 2) % 4]
309309
strand.append(cs)
310310
return strand
311311

@@ -314,11 +314,11 @@ def cross_strand(self,i):
314314
"""
315315
def loop_strand(cs):
316316
strand = [cs]
317-
cs = cs[0].adjacent[(cs[1]+2)%4]
317+
cs = cs[0].adjacent[(cs[1] + 2) % 4]
318318
while cs not in strand:
319319
# print(strand)
320320
strand.append(cs)
321-
cs = cs[0].adjacent[(cs[1]+2)%4]
321+
cs = cs[0].adjacent[(cs[1] + 2) % 4]
322322
return strand
323323

324324
"""
@@ -337,7 +337,7 @@ def all_cross_strands(self):
337337
if i not in other_ends_seen:
338338
strand = self.cross_strand(i)
339339
cs = strand[-1]
340-
end = self.adjacent.index((cs[0],(cs[1]+2)%4))
340+
end = self.adjacent.index((cs[0],(cs[1]+2) % 4))
341341
if end not in other_ends_seen:
342342
strands.append(strand)
343343
strands_with_ends.append((strand,end))
@@ -350,7 +350,7 @@ def all_cross_strands(self):
350350
for strand in strands:
351351
for cs in strand:
352352
if cs[0] in seen_once:
353-
loop = loop_strand((cs[0],(cs[1]+1)%4))
353+
loop = loop_strand((cs[0],(cs[1]+1) % 4))
354354
loops.append(loop)
355355
cs_seen.extend(loop)
356356
for loop_cs in loop:
@@ -370,14 +370,14 @@ def all_cross_strands(self):
370370
for loop in loops:
371371
for cs in loop:
372372
if cs[0] in seen_once:
373-
loop = loop_strand((cs[0],(cs[1]+1)%4))
373+
loop = loop_strand((cs[0],(cs[1]+1) % 4))
374374
loops.append(loop)
375375
cs_seen.extend(loop)
376376
for loop_cs in loop:
377377
if loop_cs[0] in seen_once:
378378
for seen_cs in cs_seen:
379379
if loop_cs[0] == seen_cs[0]:
380-
orientation = (loop_cs[1]-seen_cs[1])%4
380+
orientation = (loop_cs[1]-seen_cs[1]) % 4
381381
if orientation == 3:
382382
orientation = -1
383383
orientations[loop_cs[0]] = orientation
@@ -413,9 +413,10 @@ def cycle_basis(G):
413413
vert_cycles = nx.cycle_basis(Gx)
414414
return [edge_cycle(vert_cycle,G) for vert_cycle in vert_cycles]
415415

416+
416417
def is_trivial(four_cycle):
417418
crossings = map(lambda x: map(lambda y: y.crossing,x.interface), four_cycle)
418-
return len(set(crossings[0])&set(crossings[1])&set(crossings[2])&set(crossings[3])) != 0
419+
return bool(len(set(crossings[0]) & set(crossings[1]) & set(crossings[2]) & set(crossings[3])))
419420

420421

421422
def all_four_cycles_at_vertex(G, start_vertex):
@@ -813,12 +814,12 @@ def tangle_cut(link, cycle):
813814
clear_orientations(crossings0)
814815
clear_orientations(crossings1)
815816

816-
#One of the tangles is the 'outside', and needs to be flipped
817-
#Just check side0
817+
# One of the tangles is the 'outside', and needs to be flipped
818+
# Just check side0
818819
side0_needs_flip = False
819-
c,i = side0[0]
820+
c, i = side0[0]
820821
while True:
821-
next_cep = c.crossing_strands()[(i+1)%4]
822+
next_cep = c.crossing_strands()[(i+1) % 4]
822823
c,i = next_cep.crossing,next_cep.strand_index
823824
# print(c,i)
824825
# print(side0)

dev/dev_malik/petal_diagram/random_petaluma.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,23 @@ def petaluma_knot(height_perm):
5757
visited_dict[a,b] = True
5858
old_crossing = next_crossing
5959

60-
first = crossing_dict[0,1]
61-
last = crossing_dict[size-2,size-1]
62-
first_open = first.adjacent.index(None) #last open spot
60+
first = crossing_dict[0, 1]
61+
last = crossing_dict[size-2, size-1]
62+
first_open = first.adjacent.index(None) # last open spot
6363
last_open = last.adjacent.index(None)
6464
first[first_open] = last[last_open]
6565
return sg.Link(crossing_dict.values())
6666

67-
def strands_to_cross(size,i):
68-
mid = (size-1)/2
67+
68+
def strands_to_cross(size, i):
69+
mid = (size - 1) / 2
6970
L = []
7071
for j in range(mid):
71-
L.insert(0,(i-(2*(j+1)))%size)
72-
L.append( (i+(2*(j+1)))%size )
72+
L.insert(0, (i-(2*(j+1))) % size)
73+
L.append((i+(2*(j+1))) % size)
7374
return L
7475

76+
7577
def permutation(size):
7678
L = range(size)
7779
random.shuffle(L)

dev/dev_malik/random_knot.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def random_knot(n, method='close_under', alternate=False,
3030
available = available_strands(loose_cs)
3131
strand_to_cross = choice(available)
3232
if alternate:
33-
over_or_under = 1-(i%2)
33+
over_or_under = 1 - (i % 2)
3434
else:
35-
over_or_under = randint(0,1)
35+
over_or_under = randint(0, 1)
3636
loose_cs = cross_strand(crossings, loose_cs,
3737
strand_to_cross, str(i+1), over_or_under)
3838
same_face = set(available_strands(loose_cs)) == set(available_strands(final_cs))
@@ -57,17 +57,18 @@ def random_open_string(n, alternate=False, bias=False):
5757
else:
5858
strand_to_cross = choice(available)
5959
if alternate:
60-
over_or_under = 1-(i%2)
60+
over_or_under = 1 - (i % 2)
6161
else:
62-
over_or_under = randint(0,1)
62+
over_or_under = randint(0, 1)
6363
loose_cs = cross_strand(crossings, loose_cs,
6464
strand_to_cross, str(i+1), over_or_under)
6565
return crossings, loose_cs, final_cs
6666

67+
6768
def bias_middle(start_list):
6869
biased_list = []
6970
num_copies = range(len(start_list)/2)
70-
if len(start_list)%2 == 1:
71+
if len(start_list) % 2:
7172
num_copies.append(len(start_list)/2)
7273
num_copies.extend(reversed(range(len(start_list)/2)))
7374
for i, x in enumerate(num_copies):
@@ -159,12 +160,13 @@ def function_evolution(n, function, simplify='level', skip_first=0):
159160
values.append(open_string_evaluation(crossings, function, simplify))
160161
return values
161162

163+
162164
def turn_list_from_open_string(crossings, loose_cs, final_cs):
163165
turn_list = []
164166
while len(crossings) > 1:
165167
# print(turn_list)
166-
old_position_crossing, old_position_index = loose_cs.crossing.adjacent[(loose_cs.strand_index-1)%4]
167-
old_crossing_sign = loose_cs.strand_index%2
168+
old_position_crossing, old_position_index = loose_cs.crossing.adjacent[(loose_cs.strand_index-1) % 4]
169+
old_crossing_sign = loose_cs.strand_index % 2
168170
if old_crossing_sign == 0:
169171
old_crossing_sign = -1
170172
else:
@@ -480,6 +482,7 @@ def knot_from_turn_list(turn_list):
480482
# if c != loose_cs.crossing and c != final_cs.crossing:
481483
# c.rotate(randint(0,1))
482484

485+
483486
def cross_strand(crossings, loose_cs, strand_to_cross, new_label, over_vs_under):
484487
opposite = strand_to_cross.opposite()
485488
new_crossing = Crossing(new_label)
@@ -492,7 +495,7 @@ def cross_strand(crossings, loose_cs, strand_to_cross, new_label, over_vs_under)
492495
css = new_crossing.crossing_strands()
493496
connect_crossing_strands(css[0+over_vs_under], loose_cs)
494497
connect_crossing_strands(css[1+over_vs_under], strand_to_cross)
495-
connect_crossing_strands(css[(3+over_vs_under)%4], opposite)
498+
connect_crossing_strands(css[(3+over_vs_under) % 4], opposite)
496499

497500
return css[2+over_vs_under]
498501

0 commit comments

Comments
 (0)