diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3b8f6ca8e03b87..51b8364793d112 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,9 @@ jobs: - uses: actions/checkout@v2 - name: Build docker image run: docker build -t cereal . + - name: Static analysis + run: | + docker run cereal bash -c "git init && git add -A && pre-commit run --all" - name: Unit Tests run: | docker run cereal bash -c "scons --test --asan -j$(nproc) && messaging/test_runner" @@ -20,4 +23,3 @@ jobs: - name: Test MSGQ run: | docker run cereal bash -c "MSGQ=1 python -m unittest discover ." - diff --git a/.gitignore b/.gitignore index e90f8c750f9b26..9e2fec81dc159e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ libmessaging_shared.* services.h .sconsign.dblite libcereal_shared.* - +.mypy_cache/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000000..314a2886d6bd79 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: master + hooks: + - id: check-ast + - id: check-json + - id: check-xml + - id: check-yaml +- repo: https://github.com/pre-commit/mirrors-mypy + rev: master + hooks: + - id: mypy +- repo: https://gitlab.com/PyCQA/flake8 + rev: master + hooks: + - id: flake8 + args: + - --select=F +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + - --disable=R,C,W diff --git a/Dockerfile b/Dockerfile index c399e19a64e5ea..acf5ae3df73d35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,12 @@ ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}" RUN pyenv install 3.7.3 RUN pyenv global 3.7.3 RUN pyenv rehash -RUN pip3 install pyyaml==5.1.2 Cython==0.29.14 scons==3.1.1 pycapnp==0.6.4 +RUN pip3 install pyyaml==5.1.2 Cython==0.29.14 scons==3.1.1 pycapnp==0.6.4 pre-commit==2.4.0 pylint==2.5.2 WORKDIR /project/cereal ENV PYTHONPATH=/project COPY . . +RUN rm -rf .git RUN scons -c && scons -j$(nproc) diff --git a/__init__.py b/__init__.py index 2d3b48526b2c34..88a181cbc51da4 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,4 @@ +# pylint: skip-file import os import capnp diff --git a/messaging/__init__.py b/messaging/__init__.py index b53d6fb7ab6247..31b9147eec5d8f 100644 --- a/messaging/__init__.py +++ b/messaging/__init__.py @@ -155,7 +155,7 @@ def __init__(self, services, ignore_alive=None, addr="127.0.0.1"): try: data = new_message(s) - except capnp.lib.capnp.KjException: + except capnp.lib.capnp.KjException: # pylint: disable=c-extension-no-member # lists data = new_message(s, 0)