Skip to content

Commit

Permalink
lint: Add support for cython-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcinl committed Apr 15, 2024
1 parent e252e9f commit 2bb509c
Show file tree
Hide file tree
Showing 47 changed files with 1,235 additions and 967 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Expand Up @@ -14,4 +14,4 @@ source =
[report]
exclude_lines =
.*#\s*(pragma)[:\s]?\s*(no)\s*(cover)
.*#~>\s*
.*#\s*~>\s*
9 changes: 9 additions & 0 deletions .cython-lint.toml
@@ -0,0 +1,9 @@
[tool.cython-lint]
exclude = "libmpi\\.pxd"
ignore = [
"E201", # whitespace after '('
"E202", # whitespace before ')'
"E221", # multiple spaces before operator
"E222", # multiple spaces after operator
"E701", # multiple statements on one line (colon)
]
3 changes: 3 additions & 0 deletions .github/workflows/ci-check.yml
Expand Up @@ -116,6 +116,9 @@ jobs:
- name: cython
run: conf/cythonize.sh -Wextra -Werror

- name: cython-lint
run: cython-lint .

- name: yamllint
run: yamllint .

Expand Down
1 change: 1 addition & 0 deletions conf/cythonize.sh
@@ -1,4 +1,5 @@
#!/bin/sh
set -eu
topdir=$(cd $(dirname "$0")/.. && pwd)
python "$topdir/conf/cythonize.py" \
--working "$topdir" $@ \
Expand Down
1 change: 1 addition & 0 deletions conf/requirements-lint.txt
@@ -1,5 +1,6 @@
codespell
cython
cython-lint
flake8
flake8-assertive
flake8-bandit
Expand Down
9 changes: 1 addition & 8 deletions demo/cython/helloworld.pyx
Expand Up @@ -2,7 +2,6 @@ cdef extern from "mpi-compat.h": pass

# ---------


# Python-level module import
# (file: mpi4py/MPI.so)

Expand All @@ -17,11 +16,8 @@ pname = MPI.Get_processor_name()
hwmess = "Hello, World! I am process %d of %d on %s."
print (hwmess % (rank, size, pname))



# ---------


# Cython-level cimport
# this make available mpi4py's Python extension types
# (file: mpi4py/include/mpi4py/MPI.pxd)
Expand All @@ -34,10 +30,8 @@ from mpi4py.MPI cimport Intracomm as IntracommType
cdef MPI.Comm WORLD = MPI.COMM_WORLD
cdef IntracommType SELF = MPI.COMM_SELF


# ---------


# Cython-level cimport with PXD file
# this make available the native MPI C API
# with namespace-protection (stuff accessed as mpi.XXX)
Expand All @@ -58,10 +52,9 @@ ierr1 = mpi.MPI_Comm_rank(mpi.MPI_COMM_WORLD, &rank1)
cdef int rlen1=0
cdef char pname1[mpi.MPI_MAX_PROCESSOR_NAME]
ierr1 = mpi.MPI_Get_processor_name(pname1, &rlen1)
pname1[rlen1] = 0 # just in case ;-)
pname1[rlen1] = 0 # just in case ;-)

hwmess = "Hello, World! I am process %d of %d on %s."
print (hwmess % (rank1, size1, pname1))


# ---------
8 changes: 5 additions & 3 deletions demo/wrap-cython/helloworld.pyx
@@ -1,10 +1,11 @@
cdef extern from "mpi-compat.h": pass
cdef extern from "mpi-compat.h":
pass
cdef extern from "stdio.h":
int printf(char*, ...)

cimport mpi4py.MPI as MPI
from mpi4py.libmpi cimport *

cdef extern from "stdio.h":
int printf(char*, ...)

cdef void c_sayhello(MPI_Comm comm):
cdef int size, rank, plen
Expand All @@ -18,6 +19,7 @@ cdef void c_sayhello(MPI_Comm comm):
printf(b"Hello, World! I am process %d of %d on %s.\n",
rank, size, pname)


def sayhello(MPI.Comm comm not None ):
cdef MPI_Comm c_comm = comm.ob_mpi
c_sayhello(c_comm)
40 changes: 20 additions & 20 deletions src/mpi4py/MPI.pxd
Expand Up @@ -29,23 +29,23 @@ cdef extern from *:
ctypedef public api class Datatype [
type PyMPIDatatype_Type,
object PyMPIDatatypeObject,
]:
]:
cdef MPI_Datatype ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Status [
type PyMPIStatus_Type,
object PyMPIStatusObject,
]:
]:
cdef MPI_Status ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Request [
type PyMPIRequest_Type,
object PyMPIRequestObject,
]:
]:
cdef MPI_Request ob_mpi
cdef unsigned flags
cdef object __weakref__
Expand All @@ -54,19 +54,19 @@ ctypedef public api class Request [
ctypedef public api class Prequest(Request) [
type PyMPIPrequest_Type,
object PyMPIPrequestObject,
]:
]:
pass

ctypedef public api class Grequest(Request) [
type PyMPIGrequest_Type,
object PyMPIGrequestObject,
]:
]:
cdef MPI_Request ob_grequest

ctypedef public api class Message [
type PyMPIMessage_Type,
object PyMPIMessageObject,
]:
]:
cdef MPI_Message ob_mpi
cdef unsigned flags
cdef object __weakref__
Expand All @@ -75,7 +75,7 @@ ctypedef public api class Message [
ctypedef public api class Op [
type PyMPIOp_Type,
object PyMPIOpObject,
]:
]:
cdef MPI_Op ob_mpi
cdef unsigned flags
cdef object __weakref__
Expand All @@ -84,83 +84,83 @@ ctypedef public api class Op [
ctypedef public api class Group [
type PyMPIGroup_Type,
object PyMPIGroupObject,
]:
]:
cdef MPI_Group ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Info [
type PyMPIInfo_Type,
object PyMPIInfoObject,
]:
]:
cdef MPI_Info ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Errhandler [
type PyMPIErrhandler_Type,
object PyMPIErrhandlerObject,
]:
]:
cdef MPI_Errhandler ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Session [
type PyMPISession_Type,
object PyMPISessionObject,
]:
]:
cdef MPI_Session ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Comm [
type PyMPIComm_Type,
object PyMPICommObject,
]:
]:
cdef MPI_Comm ob_mpi
cdef unsigned flags
cdef object __weakref__

ctypedef public api class Intracomm(Comm) [
type PyMPIIntracomm_Type,
object PyMPIIntracommObject,
]:
]:
pass

ctypedef public api class Topocomm(Intracomm) [
type PyMPITopocomm_Type,
object PyMPITopocommObject,
]:
]:
pass

ctypedef public api class Cartcomm(Topocomm) [
type PyMPICartcomm_Type,
object PyMPICartcommObject,
]:
]:
pass

ctypedef public api class Graphcomm(Topocomm) [
type PyMPIGraphcomm_Type,
object PyMPIGraphcommObject,
]:
]:
pass

ctypedef public api class Distgraphcomm(Topocomm) [
type PyMPIDistgraphcomm_Type,
object PyMPIDistgraphcommObject,
]:
]:
pass

ctypedef public api class Intercomm(Comm) [
type PyMPIIntercomm_Type,
object PyMPIIntercommObject,
]:
]:
pass

ctypedef public api class Win [
type PyMPIWin_Type,
object PyMPIWinObject,
]:
]:
cdef MPI_Win ob_mpi
cdef unsigned flags
cdef object __weakref__
Expand All @@ -169,7 +169,7 @@ ctypedef public api class Win [
ctypedef public api class File [
type PyMPIFile_Type,
object PyMPIFileObject,
]:
]:
cdef MPI_File ob_mpi
cdef unsigned flags
cdef object __weakref__
Expand Down
24 changes: 12 additions & 12 deletions src/mpi4py/MPI.pyx
@@ -1,15 +1,15 @@
#cython: language_level=3str
#cython: embedsignature=True
#cython: embedsignature.format=python
#cython: annotation_typing=False
#cython: cdivision=True
#cython: auto_pickle=False
#cython: always_allow_keywords=True
#cython: allow_none_for_extension_args=False
#cython: autotestdict=False
#cython: warn.multiple_declarators=False
#cython: optimize.use_switch=False
#cython: binding=True
# cython: language_level=3str
# cython: embedsignature=True
# cython: embedsignature.format=python
# cython: annotation_typing=False
# cython: cdivision=True
# cython: auto_pickle=False
# cython: always_allow_keywords=True
# cython: allow_none_for_extension_args=False
# cython: autotestdict=False
# cython: warn.multiple_declarators=False
# cython: optimize.use_switch=False
# cython: binding=True

from __future__ import annotations
cimport cython # no-cython-lint
Expand Down
6 changes: 4 additions & 2 deletions src/mpi4py/MPI/CAPI.pxi
Expand Up @@ -17,9 +17,11 @@ cdef api MPI_Datatype* PyMPIDatatype_Get(object arg) except NULL:

cdef api object PyMPIStatus_New(MPI_Status *arg):
cdef Status obj = Status.__new__(Status)
if (arg != NULL and
if (
arg != NULL and
arg != MPI_STATUS_IGNORE and
arg != MPI_STATUSES_IGNORE):
arg != MPI_STATUSES_IGNORE
):
obj.ob_mpi = arg[0]
return obj

Expand Down

0 comments on commit 2bb509c

Please sign in to comment.