running pep8 or pylint on cython code
Asked Answered
A

2

13

Is there any way to use pep8 with cython files?

pep8 does not work with operators for example.

getline(& line)

produces error:

E225 missing whitespace around operator

Now if i try to fix it and run this:

getline( & line)

produces error:

 E201 whitespace after '('
Aime answered 7/7, 2015 at 13:11 Comment(7)
pep8 is a code checker for python code. cython is a different language. I don't think this is possible.Totality
It really only fails on operatorsAime
Well, you can write weird c stuff in cython. I am pretty sure that operators are not the only problem.Totality
its the only errors I am seeing. Most people write a pxd or .h files and extern from thereAime
the only way I see would be to write python compatible code, using decorators and other functions (eg reference or similar) provided by cython.Chicory
Did you ever get an answer?Ophelia
no, I haven't heard from anyone on this.Aime
Z
2

You can use cython-lint

Installation

$ pip install cython-lint

Usage as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/MarcoGorelli/cython-lint
    rev: v0.10.1  # put most recent version here
    hooks:
    -   id: cython-lint
    -   id: double-quote-cython-strings

Command-line example

$ cython-lint my_file_1.pyx my_file_2.pyx
my_file_1.pyx:54:5: 'get_conversion_factor' imported but unused
my_file_2.pyx:1112:38: 'mod' defined but unused
my_file_3.pyx:4:9: dangerous default value!
my_file_3.pyx:5:9: comma after base type in definition
Zigrang answered 17/1, 2023 at 18:20 Comment(0)
R
5

The neural network library Chainer has a pretty handy flake8 config for Cython:

[flake8]
filename = *.pyx,*.px*
exclude = .eggs,*.egg,build
ignore = E901,E225,E226,E227
Risa answered 24/10, 2016 at 21:1 Comment(0)
Z
2

You can use cython-lint

Installation

$ pip install cython-lint

Usage as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/MarcoGorelli/cython-lint
    rev: v0.10.1  # put most recent version here
    hooks:
    -   id: cython-lint
    -   id: double-quote-cython-strings

Command-line example

$ cython-lint my_file_1.pyx my_file_2.pyx
my_file_1.pyx:54:5: 'get_conversion_factor' imported but unused
my_file_2.pyx:1112:38: 'mod' defined but unused
my_file_3.pyx:4:9: dangerous default value!
my_file_3.pyx:5:9: comma after base type in definition
Zigrang answered 17/1, 2023 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.