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 27, 2023
1 parent 71eccfd commit aec63c1
Show file tree
Hide file tree
Showing 7 changed files with 945 additions and 579 deletions.
5 changes: 2 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[flake8]
ignore = E203,F401,F403,W503,E501,E266
exclude =
*cookiecutter*
max-line-length = 100
exclude = *cookiecutter*
max-line-length = 100
30 changes: 16 additions & 14 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
python-version: "3.9.x"

- 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 autoflake
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
1,392 changes: 851 additions & 541 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +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"]

[tool.pylint.'MESSAGES CONTROL']
disable = ["invalid-name"]
50 changes: 45 additions & 5 deletions scripts/lint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
# -*- 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",
"--skip",
"pipelines/{{cookiecutter.project_name}}",
"--check-only",
".",
]
)
code |= run(
[
"black",
"--exclude",
"pipelines/{{cookiecutter.project_name}}",
"--check",
".",
]
)
code |= run(
[
"autoflake",
"--exclude",
"pipelines/{{cookiecutter.project_name}}",
"--check",
"--recursive",
"--quiet",
".",
]
)
code |= run(
[
"flake8",
"--exclude",
"pipelines/{{cookiecutter.project_name}}",
".",
]
)
exit(code)

0 comments on commit aec63c1

Please sign in to comment.