Skip to content

Commit

Permalink
IN-X Apply standard Python project linters and pre-commit hooks
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
* We updated our method for managing linters and code
formatting for our Python projects to simplify
configuration and use.

How this addresses that need:
* Apply standard pyproject.toml file
* Deprecate setup.cfg
* Apply linting with Ruff
* Set black, mypy, ruff, and safety as linters
* Add pre-commit hooks
* Update Makefile
* Update Pipfile

Side effects of this change:
* None

Relevant ticket(s):
* TBD
  • Loading branch information
jonavellecuerdo committed Aug 16, 2023
1 parent 987bec0 commit 3d026b9
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 222 deletions.
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default_language_version:
python: python3.11 # set for project python version
repos:
- repo: local
hooks:
- id: black-apply
name: black-apply
entry: pipenv run black
language: system
pass_filenames: true
types: ["python"]
- id: mypy
name: mypy
entry: pipenv run mypy
exclude: tests/
language: system
pass_filenames: true
types: ["python"]
- id: ruff-apply
name: ruff-apply
entry: pipenv run ruff check --fix
language: system
pass_filenames: true
types: ["python"]
- id: safety
name: safety
entry: pipenv check
language: system
pass_filenames: false
47 changes: 28 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
### This is the Terraform-generated header for the timdex-pipeline-lambads Makefile ###
# ---- This is the Terraform-generated header for the timdex-pipeline-lambads Makefile ---- ##
SHELL=/bin/bash
DATETIME:=$(shell date -u +%Y%m%dT%H%M%SZ)

### This is the Terraform-generated header for alma-webhook-lambdas-dev ###
## ---- This is the Terraform-generated header for alma-webhook-lambdas-dev ---- ##
ECR_NAME_DEV:=alma-webhook-lambdas-dev
ECR_URL_DEV:=222053980223.dkr.ecr.us-east-1.amazonaws.com/alma-webhook-lambdas-dev
FUNCTION_DEV:=alma-webhook-lambdas-dev
### End of Terraform-generated header ###
## ---- End of Terraform-generated header ---- ##

help: ## Print this message
@awk 'BEGIN { FS = ":.*##"; print "Usage: make <target>\n\nTargets:" } \
/^[-_[:alpha:]]+:.?*##/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)

### Dependency commands ###
install: ## Install dependencies
## ---- Dependency commands ---- ##
install: # install python dependencies
pipenv install --dev
pipenv run pre-commit install

update: install ## Update all Python dependencies
update: install # update all python dependencies
pipenv clean
pipenv update --dev
pipenv requirements

### Test commands ###
test: ## Run tests and print a coverage report
## ---- Test commands ---- ##
test: # run tests and print coverage report
pipenv run coverage run --source=lambdas -m pytest -vv
pipenv run coverage report -m

coveralls: test
pipenv run coverage lcov -o ./coverage/lcov.info

### Lint commands ###
lint: bandit black flake8 isort mypy ## Lint the repo
## ---- Code quality and safety commands ###

bandit:
pipenv run bandit -r lambdas
# linting commands
lint: black mypy ruff safety

black:
pipenv run black --check --diff .

flake8:
pipenv run flake8 .
mypy:
pipenv run mypy lambdas -v

isort:
pipenv run isort . --diff
ruff:
pipenv run ruff check .

mypy:
pipenv run mypy lambdas
safety:
pipenv check
pipenv verify

# apply changes to resolve any linting errors
lint-apply: black-apply ruff-apply

black-apply:
pipenv run black .

ruff-apply:
pipenv run ruff check --fix .

### Terraform-generated Developer Deploy Commands for Dev environment ###
dist-dev: ## Build docker container (intended for developer-based manual build)
Expand Down
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ requests = "*"
sentry-sdk = "*"

[dev-packages]
bandit = "*"
black = "*"
boto3-stubs = {extras = ["essential"], version = "*"}
coverage = "*"
flake8 = "*"
freezegun = "*"
isort = "*"
mypy = "*"
pre-commit = "*"
pytest = "*"
requests-mock = "*"
ruff = "*"
types-requests = "*"
typing-extensions = "*"

Expand Down

0 comments on commit 3d026b9

Please sign in to comment.