Skip to content

Commit

Permalink
In 896 app stabilization (#145)
Browse files Browse the repository at this point in the history
* IN-896 App stabilization:  Update Python version and dependencies

Why these changes are being introduced:
* Keeping our Python version and dependencies updated
is good practice and allows us to take advantage
of the latest security updates and bug fixes for Python.

How this addresses that need:
* Update Dockerfile
* Update Pipfile
* Update .python-version

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/IN-896

* IN-896 App stabilization: add linters and pre-commit hooks

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):
* https://mitlibraries.atlassian.net/browse/IN-896

* Updates after merge of #144

* Update imports, type hinting, and datetime calls in webhook modules
* Update mypy command in Makefile
* Update dependencies
* Update _test_env fixture and datetime calls in conftest module
* Update test_validate_missing_signature_returns_false with more explicit error check

---------

Co-authored-by: Eric Hanson <ehanson@mit.edu>
  • Loading branch information
jonavellecuerdo and ehanson8 committed Aug 18, 2023
1 parent a8d1a58 commit f8f7d96
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 274 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
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.10.10
3.11.2
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM public.ecr.aws/lambda/python:3.10
FROM public.ecr.aws/lambda/python:3.11

# Copy function code
COPY . ${LAMBDA_TASK_ROOT}/
Expand Down
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 .

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
8 changes: 4 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ 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 = "*"
pytest-mock = "*"

[requires]
python_version = "3.10"
python_version = "3.11"
Loading

0 comments on commit f8f7d96

Please sign in to comment.