Search code examples
cythonpylintpep8flake8

running pep8 or pylint on cython code


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 '('

Solution

  • 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