Skip to content

Commit

Permalink
lint: Check Cython code
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcinl committed Nov 27, 2023
1 parent a744450 commit 7ddfe75
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ jobs:
- name: codespell
run: codespell

- name: cython
run: conf/cythonize.sh -Wextra -Werror

type:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions conf/requirements-lint.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
codespell
cython
flake8
flake8-assertive
flake8-bandit
Expand Down
2 changes: 1 addition & 1 deletion src/mpi4py/MPI.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
#cython: binding=True

from __future__ import annotations
cimport cython
cimport cython # no-cython-lint

include "MPI/MPI.pyx"
48 changes: 24 additions & 24 deletions src/mpi4py/MPI/Comm.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2535,12 +2535,12 @@ cdef class Intracomm(Comm):
#
cdef int rank = MPI_UNDEFINED
CHKERR( MPI_Comm_rank(self.ob_mpi, &rank) )
cdef tmp1, tmp2, tmp3
cdef object unused1, unused2, unused3
if root == rank:
tmp1 = asmpistr(command, &cmd)
tmp2 = asarray_argv(args, &argv)
unused1 = asmpistr(command, &cmd)
unused2 = asarray_argv(args, &argv)
if errcodes is not None:
tmp3 = newarray(maxprocs, &ierrcodes)
unused3 = newarray(maxprocs, &ierrcodes)
#
cdef Intercomm comm = <Intercomm>New(Intercomm)
with nogil: CHKERR( MPI_Comm_spawn(
Expand Down Expand Up @@ -2574,20 +2574,20 @@ cdef class Intracomm(Comm):
#
cdef int rank = MPI_UNDEFINED
CHKERR( MPI_Comm_rank(self.ob_mpi, &rank) )
cdef tmp1, tmp2, tmp3, tmp4, tmp5
cdef object unused1, unused2, unused3, unused4, unused5
if root == rank:
tmp1 = asarray_cmds(command, &count, &cmds)
tmp2 = asarray_argvs(args, count, &argvs)
tmp3 = asarray_nprocs(maxprocs, count, &imaxprocs)
tmp4 = asarray_Info(info, count, &infos)
unused1 = asarray_cmds(command, &count, &cmds)
unused2 = asarray_argvs(args, count, &argvs)
unused3 = asarray_nprocs(maxprocs, count, &imaxprocs)
unused4 = asarray_Info(info, count, &infos)
cdef int np = 0
if errcodes is not None:
if root != rank:
count = <int>len(maxprocs)
tmp3 = asarray_nprocs(maxprocs, count, &imaxprocs)
unused3 = asarray_nprocs(maxprocs, count, &imaxprocs)
for i in range(count):
np += imaxprocs[i]
tmp5 = newarray(np, &ierrcodes)
unused5 = newarray(np, &ierrcodes)
#
cdef Intercomm comm = <Intercomm>New(Intercomm)
with nogil: CHKERR( MPI_Comm_spawn_multiple(
Expand Down Expand Up @@ -3046,11 +3046,11 @@ cdef class Cartcomm(Topocomm):
cdef int ndim = 0
CHKERR( MPI_Cartdim_get(self.ob_mpi, &ndim) )
cdef int *idims = NULL
cdef tmp1 = newarray(ndim, &idims)
cdef unused1 = newarray(ndim, &idims)
cdef int *iperiods = NULL
cdef tmp2 = newarray(ndim, &iperiods)
cdef unused2 = newarray(ndim, &iperiods)
cdef int *icoords = NULL
cdef tmp3 = newarray(ndim, &icoords)
cdef unused3 = newarray(ndim, &icoords)
CHKERR( MPI_Cart_get(self.ob_mpi, ndim, idims, iperiods, icoords) )
cdef object dims = [idims[i] for i in range(ndim)]
cdef object periods = [iperiods[i] for i in range(ndim)]
Expand Down Expand Up @@ -3098,7 +3098,7 @@ cdef class Cartcomm(Topocomm):
"""
cdef int ndim = 0, *icoords = NULL
CHKERR( MPI_Cartdim_get(self.ob_mpi, &ndim) )
cdef tmp = newarray(ndim, &icoords)
cdef unused = newarray(ndim, &icoords)
CHKERR( MPI_Cart_coords(self.ob_mpi, rank, ndim, icoords) )
cdef object coords = [icoords[i] for i in range(ndim)]
return coords
Expand Down Expand Up @@ -3142,7 +3142,7 @@ def Compute_dims(int nnodes: int, dims: int | Sequence[int]) -> list[int]:
except:
ndims = dims
dims = [0] * ndims
cdef tmp = chkarray(dims, ndims, &idims)
cdef unused = chkarray(dims, ndims, &idims)
CHKERR( MPI_Dims_create(nnodes, ndims, idims) )
dims = [idims[i] for i in range(ndims)]
return dims
Expand Down Expand Up @@ -3194,9 +3194,9 @@ cdef class Graphcomm(Topocomm):
cdef int nindex = 0, nedges = 0
CHKERR( MPI_Graphdims_get( self.ob_mpi, &nindex, &nedges) )
cdef int *iindex = NULL
cdef tmp1 = newarray(nindex, &iindex)
cdef unused1 = newarray(nindex, &iindex)
cdef int *iedges = NULL
cdef tmp2 = newarray(nedges, &iedges)
cdef unused2 = newarray(nedges, &iedges)
CHKERR( MPI_Graph_get(self.ob_mpi, nindex, nedges, iindex, iedges) )
cdef object index = [iindex[i] for i in range(nindex)]
cdef object edges = [iedges[i] for i in range(nedges)]
Expand Down Expand Up @@ -3241,7 +3241,7 @@ cdef class Graphcomm(Topocomm):
cdef int nneighbors = 0, *ineighbors = NULL
CHKERR( MPI_Graph_neighbors_count(
self.ob_mpi, rank, &nneighbors) )
cdef tmp = newarray(nneighbors, &ineighbors)
cdef unused = newarray(nneighbors, &ineighbors)
CHKERR( MPI_Graph_neighbors(
self.ob_mpi, rank, nneighbors, ineighbors) )
cdef object neighbors = [ineighbors[i] for i in range(nneighbors)]
Expand Down Expand Up @@ -3293,14 +3293,14 @@ cdef class Distgraphcomm(Topocomm):
cdef int *sources = NULL, *destinations = NULL
cdef int *sourceweights = MPI_UNWEIGHTED
cdef int *destweights = MPI_UNWEIGHTED
cdef tmp1, tmp2, tmp3, tmp4
tmp1 = newarray(maxindegree, &sources)
tmp2 = newarray(maxoutdegree, &destinations)
cdef object unused1, unused2, unused3, unused4
unused1 = newarray(maxindegree, &sources)
unused2 = newarray(maxoutdegree, &destinations)
if weighted:
tmp3 = newarray(maxindegree, &sourceweights)
unused3 = newarray(maxindegree, &sourceweights)
for i in range(maxindegree):
sourceweights[i] = 1
tmp4 = newarray(maxoutdegree, &destweights)
unused4 = newarray(maxoutdegree, &destweights)
for i in range(maxoutdegree):
destweights[i] = 1
#
Expand Down
26 changes: 13 additions & 13 deletions src/mpi4py/MPI/Datatype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,10 @@ cdef class Datatype:
cdef MPI_Aint *a = NULL
cdef MPI_Count *c = NULL
cdef MPI_Datatype *d = NULL
cdef tmp1 = allocate(ni, sizeof(int), &i)
cdef tmp2 = allocate(na, sizeof(MPI_Aint), &a)
cdef tmp3 = allocate(nc, sizeof(MPI_Count), &c)
cdef tmp4 = allocate(nd, sizeof(MPI_Datatype), &d)
cdef unused1 = allocate(ni, sizeof(int), &i)
cdef unused2 = allocate(na, sizeof(MPI_Aint), &a)
cdef unused3 = allocate(nc, sizeof(MPI_Count), &c)
cdef unused4 = allocate(nd, sizeof(MPI_Datatype), &d)
CHKERR( MPI_Type_get_contents_c(
self.ob_mpi, ni, na, nc, nd, i, a, c, d) )
cdef object integers = [i[k] for k in range(ni)]
Expand Down Expand Up @@ -616,8 +616,8 @@ cdef class Datatype:
#
cdef void *ibptr = NULL, *obptr = NULL
cdef MPI_Aint iblen = 0, oblen = 0
cdef tmp1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef tmp2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef unused1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef unused2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef MPI_Count icount = iblen // extent
cdef MPI_Count ocount = oblen
#
Expand All @@ -642,8 +642,8 @@ cdef class Datatype:
#
cdef void *ibptr = NULL, *obptr = NULL
cdef MPI_Aint iblen = 0, oblen = 0
cdef tmp1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef tmp2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef unused1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef unused2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef MPI_Count icount = iblen
cdef MPI_Count ocount = oblen // extent
#
Expand Down Expand Up @@ -691,8 +691,8 @@ cdef class Datatype:
#
cdef void *ibptr = NULL, *obptr = NULL
cdef MPI_Aint iblen = 0, oblen = 0
cdef tmp1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef tmp2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef unused1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef unused2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef MPI_Count icount = iblen // extent
cdef MPI_Count ocount = oblen
#
Expand Down Expand Up @@ -721,8 +721,8 @@ cdef class Datatype:
#
cdef void *ibptr = NULL, *obptr = NULL
cdef MPI_Aint iblen = 0, oblen = 0
cdef tmp1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef tmp2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef unused1 = asbuffer_r(inbuf, &ibptr, &iblen)
cdef unused2 = asbuffer_w(outbuf, &obptr, &oblen)
cdef MPI_Count icount = iblen
cdef MPI_Count ocount = oblen // extent
#
Expand Down Expand Up @@ -856,7 +856,7 @@ cdef class Datatype:
"""
cdef const char *s = DatatypeCode(self.ob_mpi)
if s != NULL: return pystr(s)
raise ValueError(f"cannot map to character code or type string")
raise ValueError("cannot map to character code or type string")

@classmethod
def fromcode(cls, code: str) -> Datatype:
Expand Down
12 changes: 6 additions & 6 deletions src/mpi4py/MPI/Group.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ cdef class Group:
cdef MPI_Group group2 = MPI_GROUP_NULL
cdef int n = 0, *iranks1 = NULL, *iranks2 = NULL
#
cdef tmp1 = None
cdef unused1 = None
if ranks is not None:
tmp1 = getarray(ranks, &n, &iranks1)
unused1 = getarray(ranks, &n, &iranks1)
else:
CHKERR( MPI_Group_size(self.ob_mpi, &n) )
tmp1 = newarray(n, &iranks1)
unused1 = newarray(n, &iranks1)
for i in range(n): iranks1[i] = i
cdef tmp2 = newarray(n, &iranks2)
cdef unused2 = newarray(n, &iranks2)
#
group1 = self.ob_mpi
if group is not None:
Expand Down Expand Up @@ -175,7 +175,7 @@ cdef class Group:
cdef int *p = NULL, (*ranges)[3]# = NULL ## XXX cython fails
ranges = NULL
cdef int n = <int>len(ranks)
cdef tmp1 = allocate(n, sizeof(int[3]), &ranges)
cdef unused1 = allocate(n, sizeof(int[3]), &ranges)
for i in range(n):
p = <int*> ranges[i]
p[0], p[1], p[2] = ranks[i]
Expand All @@ -190,7 +190,7 @@ cdef class Group:
cdef int *p = NULL, (*ranges)[3]# = NULL ## XXX cython fails
ranges = NULL
cdef int n = <int>len(ranks)
cdef tmp1 = allocate(n, sizeof(int[3]), &ranges)
cdef unused1 = allocate(n, sizeof(int[3]), &ranges)
for i in range(n):
p = <int*> ranges[i]
p[0], p[1], p[2] = ranks[i]
Expand Down
2 changes: 1 addition & 1 deletion src/mpi4py/MPI/Info.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ cdef class Info:
cdef int buflen = MPI_MAX_INFO_VAL
cdef int flag = 0
key = asmpistr(key, &ckey)
cdef tmp = allocate(buflen+1, sizeof(char), &cvalue)
cdef unused = allocate(buflen+1, sizeof(char), &cvalue)
CHKERR( MPI_Info_get_string(self.ob_mpi, ckey, &buflen, cvalue, &flag) )
if not flag: return None
return mpistr(cvalue)
Expand Down
2 changes: 1 addition & 1 deletion src/mpi4py/MPI/Session.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cdef class Session:
"""
cdef int nlen = MPI_MAX_PSET_NAME_LEN
cdef char *pset_name = NULL
cdef tmp = allocate(nlen+1, sizeof(char), &pset_name)
cdef unused = allocate(nlen+1, sizeof(char), &pset_name)
CHKERR( MPI_Session_get_nth_pset(
self.ob_mpi, info.ob_mpi, n, &nlen, pset_name) )
return mpistr(pset_name)
Expand Down
4 changes: 2 additions & 2 deletions src/mpi4py/MPI/Status.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cdef class Status:
cdef Py_ssize_t n = <int>(sizeof(MPI_Status)//sizeof(int))
cdef MPI_Status *c_status = &status.ob_mpi
cdef MPI_Fint *f_status = NULL
cdef tmp = allocate(n+1, sizeof(MPI_Fint), &f_status)
cdef unused = allocate(n+1, sizeof(MPI_Fint), &f_status)
CHKERR( MPI_Status_c2f(c_status, f_status) )
return [f_status[i] for i in range(n)]

Expand All @@ -197,7 +197,7 @@ cdef class Status:
cdef MPI_Status *c_status = &status
cdef Py_ssize_t n = <int>(sizeof(MPI_Status)//sizeof(int))
cdef MPI_Fint *f_status = NULL
cdef tmp = allocate(n+1, sizeof(MPI_Fint), &f_status)
cdef unused = allocate(n+1, sizeof(MPI_Fint), &f_status)
for i in range(n): f_status[i] = arg[i]
CHKERR( MPI_Status_f2c(f_status, c_status) )
return PyMPIStatus_New(c_status)
Expand Down
9 changes: 7 additions & 2 deletions src/mpi4py/MPI/bufaimpl.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ cdef inline int detach_buffer_set(
PyMPI_attach_buffer_type obj,
object buf,
) except -1:
cdef Py_uintptr_t handle
if PyMPI_attach_buffer_type is Py_uintptr_t:
handle = <Py_uintptr_t>obj; <void>handle; # unused
_mpi_buffer_comm[None] = buf
if PyMPI_attach_buffer_type is Comm:
_mpi_buffer_comm[<Py_uintptr_t>obj.ob_mpi] = buf #~> MPI-4.1
handle = <Py_uintptr_t>obj.ob_mpi #~> MPI-4.1
_mpi_buffer_comm[handle] = buf #~> MPI-4.1
if PyMPI_attach_buffer_type is Session:
_mpi_buffer_session[<Py_uintptr_t>obj.ob_mpi] = buf #~> MPI-4.1
handle = <Py_uintptr_t>obj.ob_mpi #~> MPI-4.1
_mpi_buffer_session[handle] = buf #~> MPI-4.1
return 0

cdef inline object detach_buffer_get(
Expand All @@ -76,6 +80,7 @@ cdef inline object detach_buffer_get(
cdef Py_uintptr_t handle
cdef buffer buf = <buffer>None
if PyMPI_attach_buffer_type is Py_uintptr_t:
handle = <Py_uintptr_t>obj; <void>handle; # unused
buf = <buffer>_mpi_buffer_comm.pop(None, None)
if PyMPI_attach_buffer_type is Comm:
handle = <Py_uintptr_t>obj.ob_mpi #~> MPI-4.1
Expand Down

0 comments on commit 7ddfe75

Please sign in to comment.