From c14f920f50b4ced1e545207c546c08a1e8f03a24 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Tue, 26 Sep 2023 20:35:29 -0300 Subject: [PATCH] feat: update lint python workflow --- .github/workflows/lint_python.yaml | 28 +++++++++++++++------------- .pre-commit-config.yaml | 27 +++++++++++++++------------ Makefile | 13 +++++++++++++ pyproject.toml | 4 +++- scripts/lint.py | 17 ++++++++++++----- 5 files changed, 58 insertions(+), 31 deletions(-) create mode 100644 Makefile diff --git a/.github/workflows/lint_python.yaml b/.github/workflows/lint_python.yaml index b57cbe5d1..26e1e2b07 100644 --- a/.github/workflows/lint_python.yaml +++ b/.github/workflows/lint_python.yaml @@ -8,22 +8,24 @@ jobs: name: Lint Python runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + - name: Set up Python uses: actions/setup-python@v2 with: python-version: "3.8.x" - - name: Set up Poetry and upgrade pip + + - name: Set up poetry and upgrade pip run: | pip install -U pip poetry - - name: Install flows - run: | - pip install --prefer-binary . - - name: Install pylint - run: pip install pylint - - name: Lint flows - run: pylint --rc-file pyproject.toml pipelines/* - - name: Install Pytest - run: pip install pytest - - name: Lint tests - run: pylint --rc-file pyproject.toml tests/* + pip install isort + pip install black + pip install autoflake8 + pip install flake8 + + - name: Install this package + run: poetry install + + - name: Lint source code + run: poetry run lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0060bee4e..7e8763bee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,20 +1,23 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - - id: check-added-large-files # prevents adding large files - - id: detect-private-key # detects private keys - - id: fix-byte-order-marker # fixes BOM - - id: fix-encoding-pragma # fixes encoding pragma - - id: no-commit-to-branch # prevents committing to protected branches - - id: trailing-whitespace # prevents trailing whitespace -- repo: https://github.com/psf/black + - id: check-added-large-files # prevents adding large files + - id: detect-private-key # detects private keys + - id: fix-byte-order-marker # fixes BOM + - id: fix-encoding-pragma # fixes encoding pragma + - id: no-commit-to-branch # prevents committing to protected branches + - id: trailing-whitespace # prevents trailing whitespace + - repo: https://github.com/psf/black rev: 23.9.1 hooks: - - id: black - + - id: black exclude: 'pipelines\/\{\{cookiecutter\.project_name\}\}.*' -- repo: https://github.com/PyCQA/flake8 + - repo: https://github.com/PyCQA/autoflake + rev: v2.2.1 + hooks: + - id: autoflake + - repo: https://github.com/PyCQA/flake8 rev: 6.1.0 hooks: - - id: flake8 \ No newline at end of file + - id: flake8 diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..5c2d9c2ca --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +# Get the executables we're using +POETRY=$(shell which poetry) +PYTHON=$(shell poetry run which python) + +# `make install`: installs dependencies +.PHONY: install +install: + $(POETRY) install + +# `make install`: installs pre-commit +.PHONY: install_precommit +install_precommit: + $(POETRY) run pre-commit install --install-hooks diff --git a/pyproject.toml b/pyproject.toml index 0817a9bb6..ed4c3e919 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,10 +107,12 @@ fastparquet = "^2023.7.0" geopandas = "0.13.2" shapely = "2.0.1" - [tool.poetry.dev-dependencies] pytest_cov = "^3.0.0" +[tool.poetry.scripts] +lint = "scripts.lint:main" + [build-system] build-backend = "poetry.core.masonry.api" requires = ["poetry-core>=1.0.0"] diff --git a/scripts/lint.py b/scripts/lint.py index 254492492..9d9f18534 100644 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -1,10 +1,17 @@ # -*- coding: utf-8 -*- -from pylint.lint import Run +from subprocess import run as _run -def main(): - Run(["pipelines/"]) +def run(*args): + process = _run(*args) + return process.returncode -if __name__ == "__main__": - main() +def main(): + """Lint all python files in the project""" + code = 0 + code |= run(["isort", "--check-only", "."]) + code |= run(["black", "--check", "."]) + code |= run(["autoflake", "--check", "--recursive", "--quiet", "."]) + code |= run(["flake8", "."]) + exit(code)