From 7c69dbf83307599b53a5afa417275d529713534a Mon Sep 17 00:00:00 2001 From: Axel Tillequin Date: Sun, 15 Mar 2020 16:27:45 +0100 Subject: [PATCH] get rid of python2 support --- grandalf/graphs.py | 4 +-- grandalf/layouts.py | 54 +++++++++++++++----------------------- grandalf/utils/dot.py | 2 ++ grandalf/utils/geometry.py | 11 +++----- grandalf/utils/linalg.py | 26 ++++++++++++------ setup.py | 5 ++-- tests/test_layouts.py | 2 +- tests/test_recurs.py | 2 +- tests/test_utils.py | 5 +--- 9 files changed, 51 insertions(+), 60 deletions(-) diff --git a/grandalf/graphs.py b/grandalf/graphs.py index b3dd936..b008b78 100644 --- a/grandalf/graphs.py +++ b/grandalf/graphs.py @@ -113,7 +113,7 @@ class Vertex(vertex_core): """ def __init__(self,data=None): - vertex_core.__init__(self) + super().__init__() # by default, a new vertex belongs to its own component # but when the vertex is added to a graph, c points to the # connected component where it belongs. @@ -160,7 +160,7 @@ class Edge(edge_core): """ def __init__(self,x,y,w=1,data=None,connect=False): - edge_core.__init__(self,x,y) + super().__init__(x,y) # w is an optional weight associated with the edge. self.w = w self.data = data diff --git a/grandalf/layouts.py b/grandalf/layouts.py index 48adb3b..4f70d82 100644 --- a/grandalf/layouts.py +++ b/grandalf/layouts.py @@ -24,16 +24,6 @@ from grandalf.utils import * -try: - xrange -except NameError: - xrange = range - -try: - from itertools import izip -except ImportError: - izip = zip - #------------------------------------------------------------------------------ class VertexViewer(object): @@ -114,7 +104,7 @@ class DummyVertex(_sugiyama_vertex_attr): def __init__(self,r=None,viewclass=VertexViewer): self.view = viewclass() self.ctrl = None - _sugiyama_vertex_attr.__init__(self,r,d=1) + super().__init__(r,d=1) def N(self,dir): assert dir==+1 or dir==-1 @@ -304,7 +294,7 @@ def _ordering_reduce_crossings(self): g = self.layout.grx N = len(self) X=0 - for i,j in izip(xrange(N-1),xrange(1,N)): + for i,j in zip(range(N-1),range(1,N)): vi = self[i] vj = self[j] ni = [g[v].bar for v in self._neighbors(vi)] @@ -338,6 +328,11 @@ class SugiyamaLayout(object): Attributes: dirvh (int): the current aligment state + for alignment policy: + dirvh=0 -> dirh=+1, dirv=-1: leftmost upper + dirvh=1 -> dirh=-1, dirv=-1: rightmost upper + dirvh=2 -> dirh=+1, dirv=+1: leftmost lower + dirvh=3 -> dirh=-1, dirv=+1: rightmost lower order_inter (int): the default number of layer placement iterations order_attr (str): set attribute name used for layer ordering xspace (int): horizontal space between vertices in a layer @@ -430,12 +425,6 @@ def _edge_inverter(self): for e in self.g.degenerated_edges: self.g.add_edge(e) - - # internal state for alignment policy: - # dirvh=0 -> dirh=+1, dirv=-1: leftmost upper - # dirvh=1 -> dirh=-1, dirv=-1: rightmost upper - # dirvh=2 -> dirh=+1, dirv=+1: leftmost lower - # dirvh=3 -> dirh=-1, dirv=+1: rightmost lower @property def dirvh(self): return self.__dirvh @property @@ -557,7 +546,7 @@ def setdummies(self,e): ctrl=self.ctrls[e]={} ctrl[r0]=v0 ctrl[r1]=v1 - for r in xrange(r0+1,r1): + for r in range(r0+1,r1): self.dummyctrl(r,ctrl) def draw_step(self): @@ -607,7 +596,7 @@ def setxy(self): self.grx[v].X = None self.grx[v].x = [0.0]*4 curvh = self.dirvh # save current dirvh value - for dirvh in xrange(4): + for dirvh in range(4): self.dirvh = dirvh self._coord_vertical_alignment() self._coord_horizontal_compact() @@ -765,9 +754,9 @@ def draw_edges(self): D = self.ctrls[e] r0,r1 = self.grx[e.v[0]].rank,self.grx[e.v[1]].rank if r0=2 Q = [] T = [] - for k in xrange(0,n-1): + for k in range(0,n-1): q = P[k+1]-P[k] t = q/sqrt(q.dot(q)) Q.append(q) diff --git a/grandalf/utils/linalg.py b/grandalf/utils/linalg.py index 0bab4bd..e1e8fc4 100644 --- a/grandalf/utils/linalg.py +++ b/grandalf/utils/linalg.py @@ -2,12 +2,13 @@ from math import sqrt from array import array as _array +constants = (int,float) + def coerce_(types): if types is None: types = [] if str in types: raise TypeError if complex in types: raise TypeError dtype = ('i',int) - if long in types: dtype = ('l',long) if float in types: dtype = ('d',float) return dtype @@ -29,12 +30,6 @@ def wrapper(self,ij,*args): return f(self,(I,J),*args) return wrapper -if sys.version_info < (3,): - constants = (int,long,float) - -else: - long = int - constants = (int,long,float) # minimalistic numpy.array replacement class used as fallback # when numpy is not found in geometry module class array(object): @@ -142,7 +137,7 @@ def __iter__(self): for x in self.data: yield x def __setitem__(self,i,v): - assert isinstance(i,(int,long)) + assert isinstance(i,int) self.data[i] = self.dtype(v) def __getitem__(self,i): @@ -279,3 +274,18 @@ def __iter__(self): for l in self.data: for v in l: yield v + +class SimplexMin(object): + def __init__(self,A,b,c): + self.A=A + self.b=b + self.c=c + self.tableau() + + def tableau(self): + self.T=[] + + def setup(self): + self.enter = [] + delf.outer = [] + diff --git a/setup.py b/setup.py index 0470622..b1cc4cf 100755 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ setup( name='grandalf', - version='0.6', + version='0.7', description='Graph and drawing algorithms framework', long_description=long_descr, @@ -59,7 +59,6 @@ # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', ], @@ -78,7 +77,7 @@ setup_requires=['pytest-runner',], tests_require=['pytest',], - install_requires=['pyparsing','future'], + install_requires=['pyparsing'], # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax, diff --git a/tests/test_layouts.py b/tests/test_layouts.py index 35e75b7..86d7616 100644 --- a/tests/test_layouts.py +++ b/tests/test_layouts.py @@ -38,7 +38,7 @@ def create_scenario(): data_to_vertex = {} vertices = [] - for i in xrange(6): + for i in range(6): data = 'v%s' % (i,) v = Vertex(data) data_to_vertex[data] = v diff --git a/tests/test_recurs.py b/tests/test_recurs.py index 67e88f2..8946fe6 100644 --- a/tests/test_recurs.py +++ b/tests/test_recurs.py @@ -10,7 +10,7 @@ def test_recurs(): # TODO: reimplement the recursive parts of SugiyamaLayout in iterative form. v = range(1001) V = [Vertex(x) for x in v] - E = [Edge(V[x],V[x+1]) for x in xrange(1000)] + E = [Edge(V[x],V[x+1]) for x in range(1000)] gr = graph_core(V,E) for v in gr.V(): v.view = VertexViewer(10,10) diff --git a/tests/test_utils.py b/tests/test_utils.py index 3567e88..29ad911 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,10 +13,7 @@ def test_linalg_001(): def test_linalg_001(): v1 = array([1,2,3]) assert v1.dim==3 - if sys.version_info < (3,): - assert v1.typecode=='i' - else: - assert v1.typecode=='l' + assert v1.typecode=='i' assert v1.dtype==int assert len(v1)==3 assert v1[1]==2