Skip to content

Commit

Permalink
fix and activate the cython-lint checker workflow (#51)
Browse files Browse the repository at this point in the history
* fix and activate the cython-lint checker workflow

* wider check
  • Loading branch information
fchapoton authored Aug 2, 2023
1 parent 1867798 commit 06a5ace
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ jobs:
run: |
sudo apt-get install -y codespell
sudo apt-get install -y pycodestyle
sudo pip install cython-lint
- name: Run codespell
shell: bash -l {0}
run: codespell -L pres,ans spherogram_src
- name: Run pycodestyle
shell: bash -l {0}
# We currently only check for some warnings. We should enable & fix more of them.
run: pycodestyle --select=E111,E302,E306,E401,E701,E702,E703,E704,W391,W605,E711,E713,E721 spherogram_src/
- name: Run cython-lint
shell: bash -l {0}
run: cython-lint .

env:
MAKEFLAGS: -j2
16 changes: 8 additions & 8 deletions planarity_src/planarity.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#cython: language_level=3
# cython: language_level=3
"""
Wrapper for Boyer's (C) planarity algorithm.
"""
Expand All @@ -23,16 +23,17 @@ cdef extern from "c/graph.h":
int N
int M
ctypedef baseGraphStructure * graphP

cdef int OK, EMBEDFLAGS_PLANAR, NOTOK, NONEMBEDDABLE

cdef graphP gp_New()
cdef void gp_Free(graphP *pGraph)
cdef int gp_InitGraph(graphP theGraph, int N)
cdef int gp_AddEdge(graphP theGraph, int u, int ulink, int v, int vlink)
cdef int gp_Embed(graphP theGraph, int embedFlags)
cdef int gp_SortVertices(graphP theGraph)



def planar(fatgraph):
if len(fatgraph.edges) == 0:
return True, None
Expand Down Expand Up @@ -60,13 +61,12 @@ def planar(fatgraph):
if status == NONEMBEDDABLE:
return False, None
embedding = {}
for i from 0 <= i < theGraph.N:
for i in range(theGraph.N):
adjacency_list = []
j = theGraph.V[i].link[0] # the first edge
last = theGraph.V[i].link[1] # the last edge
j = theGraph.V[i].link[0] # the first edge
while j >= 0:
adjacency_list.append(vertices[theGraph.E[j].neighbor])
j = theGraph.E[j].link[0] # the next edge
j = theGraph.E[j].link[0] # the next edge
embedding[vertices[i]] = adjacency_list
gp_Free(&theGraph)
return True, embedding
23 changes: 11 additions & 12 deletions planarmap_src/planarmap.pyx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#cython: language_level=3
#cython: legacy_implicit_noexcept=True
# cython: language_level=3
# cython: legacy_implicit_noexcept=True
#
# The above line is for Cython 3; to remove, need to declare
# "randrange_callback" via:
#
# cdef long randrange_callback(long n) noexcept:

from libc.stdlib cimport malloc, free
import random

cdef extern from 'PMdef.h':
ctypedef struct pmSize:
char m, b # map and basic map type
long e, v, f # edges, vertices, faces
char m, b # map and basic map type
long e, v, f # edges, vertices, faces
long r, g, d # red and black vertices, max degree
long t # tolerance on e
long *dgArr # pt on vertex list
Expand All @@ -32,7 +31,7 @@ cdef extern from 'PMdef.h':
long mark
short type
long label

ctypedef struct pm_edge:
pm_vertex* c_from "from"
pm_vertex* face
Expand Down Expand Up @@ -92,11 +91,11 @@ def random_map(num_vertices, int edge_connectivity=4,
cdef pm_edge *edge
cdef pm_vertex *vert

if edge_connectivity==2:
if edge_connectivity == 2:
size.m, size.b = 4, 4
elif edge_connectivity==4:
elif edge_connectivity == 4:
size.m, size.b = 5, 5
elif edge_connectivity==6:
elif edge_connectivity == 6:
size.m, size.b = 6, 5
else:
raise ValueError("Invalid edge_connectivity parameter")
Expand All @@ -117,8 +116,8 @@ def random_map(num_vertices, int edge_connectivity=4,
pmPlanMap(&size, &method, &memory, &the_map)
tries += 1

if tries==max_tries:
return
if tries == max_tries:
return

ans = []
vert = the_map.root.c_from
Expand All @@ -129,7 +128,7 @@ def random_map(num_vertices, int edge_connectivity=4,
edges_at_vert.append(edge.label)
edge = edge.next
edges_at_vert.append(edge.label)
ans.append( (vert.label, tuple(edges_at_vert)) )
ans.append((vert.label, tuple(edges_at_vert)))
vert = vert.next
pmFreeMap(&the_map)
return ans

0 comments on commit 06a5ace

Please sign in to comment.