Skip to content

Commit

Permalink
IN-894 Update project configuration and linting defaults
Browse files Browse the repository at this point in the history
Why these changes are being introduced:
* Simplify and harmonize project configuration and linting methods
with modern and active libraries that augment one another.

How this addresses that need:
* Add new files based on our Python project templates:
   * Makefile
   * pyproject.toml
   * .pre-commit-config.yaml
* Update Pipfile to include default dependencies for 'dev-packages'
* Update Pipfile to resolve issues with 'psycopg2' by installing binary package from PyPI
* Update dependencies
* Update Python version to 3.11 in Pipfile and workflows test.yml

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/IN-894
  • Loading branch information
jonavellecuerdo committed Nov 20, 2023
1 parent 5a0a773 commit d1a53fc
Show file tree
Hide file tree
Showing 6 changed files with 1,148 additions and 580 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.11'
architecture: x64
- name: Install
run: |
Expand Down
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
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
language: system
pass_filenames: true
types: ["python"]
exclude: "tests/"
- 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
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SHELL=/bin/bash
DATETIME:=$(shell date -u +%Y%m%dT%H%M%SZ)

## ---- Dependency commands ---- ##

install: # install dependencies
pipenv install --dev
pipenv run pre-commit install

update: install # update all Python dependencies
pipenv clean
pipenv update --dev

## ---- Unit test commands ---- ##

test: # run tests and print a coverage report
pipenv run coverage run --source=my_app -m pytest -vv
pipenv run coverage report -m

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


## ---- Code quality and safety commands ---- ##

# linting commands
lint: black mypy ruff safety

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

mypy:
pipenv run mypy .

ruff:
pipenv run ruff check .

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 .
11 changes: 8 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ verify_ssl = true
name = "pypi"

[requires]
python_version = "3.9"
python_version = "3.11"

[dev-packages]
black = "*"
coveralls = "*"
freezegun = "*"
pytest-cov = "*"
mypy = "*"
pre-commit = "*"
pytest = "*"
pytest-django = "*"
ruff = "*"
#pytest-cov = "*"
requests-mock = "*"

[packages]
Expand All @@ -31,7 +36,7 @@ django-libsass = "*"
gunicorn = "*"
newrelic = "*"
Pillow = "*"
psycopg2 = "*"
psycopg2-binary = "*"
python-dotenv = "*"
pyyaml = "*"
redis = "*"
Expand Down
Loading

0 comments on commit d1a53fc

Please sign in to comment.