Skip to content

Commit

Permalink
sanitize code before black
Browse files Browse the repository at this point in the history
  • Loading branch information
bdcht committed Mar 15, 2020
1 parent 7c69dbf commit 781884d
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 24 deletions.
9 changes: 7 additions & 2 deletions grandalf/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# published under GPLv2 license or EPLv1 license

from .utils import Poset
from operator import attrgetter

#------------------------------------------------------------------------------

Expand Down Expand Up @@ -133,6 +132,9 @@ def index(self):
def __lt__(self,v):
return 0

def __gt__(self,v):
return 0

def __getstate__(self):
return (self.index,self.data)

Expand Down Expand Up @@ -165,7 +167,7 @@ def __init__(self,x,y,w=1,data=None,connect=False):
self.w = w
self.data = data
self.feedback = False
if connect and (x.c==None or y.c==None):
if connect and (x.c is None or y.c is None):
c = x.c or y.c
c.add_edge(self)

Expand All @@ -187,6 +189,9 @@ def detach(self):
def __lt__(self,v):
return 0

def __gt__(self,v):
return 0

def __getstate__(self):
xi,yi = (self.v[0].index,self.v[1].index)
return (xi,yi,self.w,self.data,self.feedback)
Expand Down
15 changes: 8 additions & 7 deletions grandalf/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import importlib
from bisect import bisect
from sys import getrecursionlimit,setrecursionlimit
from operator import attrgetter

from grandalf.utils import *

Expand Down Expand Up @@ -154,6 +153,9 @@ class Layer(list):
__x = 1.
ccount = None

def __eq__(self,other):
return super().__eq__(other)

def __str__(self):
s = '<Layer %d'%self.__r
s += ', len=%d'%len(self)
Expand Down Expand Up @@ -383,10 +385,10 @@ def init_all(self,roots=None,inverted_edges=None,optimize=False):
if self.initdone: return
# For layered sugiyama algorithm, the input graph must be acyclic,
# so we must provide a list of root nodes and a list of inverted edges.
if roots==None:
if roots is None:
roots = [v for v in self.g.sV if len(v.e_in())==0]
if inverted_edges==None:
L = self.g.get_scs_with_feedback(roots)
if inverted_edges is None:
_ = self.g.get_scs_with_feedback(roots)
inverted_edges = [x for x in self.g.sE if x.feedback]
self.alt_e = inverted_edges
# assign rank to all vertices:
Expand Down Expand Up @@ -664,7 +666,7 @@ def _coord_vertical_alignment(self):
else: vpair = (um,vk)
# if vk<->um link is used for alignment
if (vpair not in self.conflicts) and \
(r==None or dirh*r<dirh*m):
((r is None) or (dirh*r<dirh*m)):
g[um].align = vk
g[vk].root = g[um].root
g[vk].align = g[vk].root
Expand Down Expand Up @@ -713,7 +715,7 @@ def _coord_horizontal_compact(self):
# TODO: rewrite in iterative form to avoid recursion limit...
def __place_block(self,v):
g = self.grx
if g[v].X==None:
if g[v].X is None:
# every block is initially placed at x=0
g[v].X = 0.0
# place block in which v belongs:
Expand Down Expand Up @@ -749,7 +751,6 @@ def draw_edges(self):
for e in self.g.E():
if hasattr(e,'view'):
l=[]
r0,r1 = None,None
if e in self.ctrls:
D = self.ctrls[e]
r0,r1 = self.grx[e.v[0]].rank,self.grx[e.v[1]].rank
Expand Down
4 changes: 2 additions & 2 deletions grandalf/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def _round_corners(pts, round_at_distance):
continue
generated = _gen_smoother_middle_points_from_3_points(
[p1, p2, p3], calc_with_distance)
for i in generated:
new_lst.append(i)
for j in generated:
new_lst.append(j)
new_lst.append(pts[-1])
pts = new_lst
calc_with_distance /= 2.
Expand Down
4 changes: 2 additions & 2 deletions grandalf/utils/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def p_E(self,p):
try:
L = p[1]
L.append(Dot.edge(L[-1].n2,p[2]))
except:
except Exception:
L = []
L.append(Dot.edge(p[1],p[2]))
p[0] = L
Expand Down Expand Up @@ -389,7 +389,7 @@ def parse(self,data):
except AttributeError:
self.lexer.build(reflags=lex.re.UNICODE)
self.parser.build()
except:
except Exception:
print('unexpected error')
return None
try:
Expand Down
2 changes: 1 addition & 1 deletion grandalf/utils/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .poset import *
from .dot import *

from math import atan,atan2,degrees,sqrt
from math import atan2,sqrt
from random import SystemRandom

#------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion grandalf/utils/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _mkslice(i,n):

def make_ij_slices(f):
def wrapper(self,ij,*args):
I = slice(0,self.n,1)
#I = slice(0,self.n,1)
J = slice(0,self.p,1)
if isinstance(ij,tuple):
I = _mkslice(ij[0],self.n)
Expand Down
4 changes: 4 additions & 0 deletions grandalf/utils/nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# published under GPLv2 license or EPLv1 license
# Contributor(s): Fabio Zadrozny

__all__=['convert_grandalf_graph_to_networkx_graph',
'convert_nextworkx_graph_to_grandalf',
]

#Some utilities to interact with networkx.

#Converts a grandalf graph to a networkx graph.
Expand Down
2 changes: 2 additions & 0 deletions grandalf/utils/poset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from collections import OrderedDict

__all__ = ['Poset']

#------------------------------------------------------------------------------
# Poset class implements a set but allows to interate over the elements in a
# deterministic way and to get specific objects in the set.
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from setuptools import setup, find_packages
from codecs import open
from os import path
from setuptools import setup

long_descr = '''
Grandalf is a python package made for experimentations with graphs and drawing
Expand Down
13 changes: 7 additions & 6 deletions tests/test_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def create_scenario():

class CustomRankingSugiyamaLayout(SugiyamaLayout):

def init_all(self, roots=None, inverted_edges=None, initial_ranking=None):
def init_all(self, roots=None, inverted_edges=None, optimize=False,
initial_ranking=None):
'''
:param dict{vertex:int} initial_ranking:
The initial ranking of each vertex if passed
Expand All @@ -92,13 +93,13 @@ def init_all(self, roots=None, inverted_edges=None, initial_ranking=None):
nblayers = max(initial_ranking.keys())+1
self.layers = [Layer([]) for l in range(nblayers)]

SugiyamaLayout.init_all(self, roots=roots, inverted_edges=inverted_edges)
super().init_all(roots, inverted_edges, False)

def _rank_init(self,unranked):
assert self.dag

if not hasattr(self, 'initial_ranking'):
SugiyamaLayout._rank_init(self, unranked)
super()._rank_init(unranked)
else:
for rank, vertices in sorted(self.initial_ranking.items()):
for v in vertices:
Expand All @@ -120,7 +121,7 @@ def test_sugiyama_ranking():
gr, data_to_vertex = create_scenario()
sug = SugiyamaLayout(gr)
sug.route_edge = route_with_rounded_corners
sug.init_all()
sug.init_all(None,None,False)
# rank 0: v4 v0
# \ / |
# rank 1: \ v1 |
Expand Down Expand Up @@ -151,7 +152,7 @@ def test_sugiyama_custom_ranking():
3: [data_to_vertex['v2']],
4: [data_to_vertex['v3']],
}
sug.init_all(initial_ranking=rank_to_data)
sug.init_all(None,None,False,initial_ranking=rank_to_data)
# rank 0: v4 v0
# \ / |
# rank 1: \ v1 |
Expand Down Expand Up @@ -182,6 +183,6 @@ def test_sugiyama_custom_ranking2():
3: [data_to_vertex['v3']],
}
try:
sug.init_all(initial_ranking=rank_to_data)
sug.init_all(None,None,False,initial_ranking=rank_to_data)
except ValueError as e:
assert e.message == 'bad ranking'

0 comments on commit 781884d

Please sign in to comment.