Skip to content

Commit

Permalink
feat: update lint python workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Sep 26, 2023
1 parent d4037bc commit c14f920
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 31 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/lint_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 15 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
- id: flake8
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
17 changes: 12 additions & 5 deletions scripts/lint.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c14f920

Please sign in to comment.