Skip to content

Commit 40237a5

Browse files
Merge pull request #8 from MITLibraries/IN-894-update-config-and-linting-defaults
IN-894 Update project configuration and linting defaults
2 parents 6a61d6b + ef197b5 commit 40237a5

File tree

10 files changed

+287
-50
lines changed

10 files changed

+287
-50
lines changed

.dockerignore

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
coverage/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
106+
__pypackages__/
107+
108+
# Celery stuff
109+
celerybeat-schedule
110+
celerybeat.pid
111+
112+
# SageMath parsed files
113+
*.sage.py
114+
115+
# Environments
116+
.env
117+
.venv
118+
env/
119+
venv/
120+
ENV/
121+
env.bak/
122+
venv.bak/
123+
124+
# Spyder project settings
125+
.spyderproject
126+
.spyproject
127+
128+
# Rope project settings
129+
.ropeproject
130+
131+
# mkdocs documentation
132+
/site
133+
134+
# mypy
135+
.mypy_cache/
136+
.dmypy.json
137+
dmypy.json
138+
139+
# Pyre type checker
140+
.pyre/
141+
142+
# pytype static type analyzer
143+
.pytype/
144+
145+
# Cython debug symbols
146+
cython_debug/
147+
148+
# IDEs
149+
.idea/
150+
.vscode/
151+
152+
# Local directories
153+
output/
154+
155+
# MacOS files
156+
.DS_Store

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
default_language_version:
2+
python: python3.11 # set for project python version
3+
repos:
4+
- repo: local
5+
hooks:
6+
- id: black-apply
7+
name: black-apply
8+
entry: pipenv run black
9+
language: system
10+
pass_filenames: true
11+
types: ["python"]
12+
- id: mypy
13+
name: mypy
14+
entry: pipenv run mypy
15+
language: system
16+
pass_filenames: true
17+
types: ["python"]
18+
exclude: "tests/"
19+
- id: ruff-apply
20+
name: ruff-apply
21+
entry: pipenv run ruff check --fix
22+
language: system
23+
pass_filenames: true
24+
types: ["python"]
25+
- id: safety
26+
name: safety
27+
entry: pipenv check
28+
language: system
29+
pass_filenames: false

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.9.12
1+
3.11.4

Makefile

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,48 @@
11
SHELL=/bin/bash
22
DATETIME:=$(shell date -u +%Y%m%dT%H%M%SZ)
33

4-
### Dependency commands ###
4+
## ---- Dependency commands ---- ##
55

6-
install: ## Install dependencies and CLI app
6+
install: # install dependencies
77
pipenv install --dev
8+
pipenv run pre-commit install
89

9-
update: install ## Update all Python dependencies
10+
update: install # update all Python dependencies
1011
pipenv clean
1112
pipenv update --dev
1213

13-
### Test commands ###
14+
## ---- Unit test commands ---- ##
1415

15-
test: ## Run tests and print a coverage report
16+
test: # run tests and print a coverage report
1617
pipenv run coverage run --source=lambdas -m pytest -vv
1718
pipenv run coverage report -m
1819

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

22-
### Code quality and safety commands ###
23+
## ---- Code quality and safety commands ---- ##
2324

24-
lint: bandit black mypy pylama safety ## Run linting, code quality, and safety checks
25-
26-
bandit:
27-
pipenv run bandit -r lambdas
25+
# linting commands
26+
lint: black mypy ruff safety
2827

2928
black:
3029
pipenv run black --check --diff .
3130

3231
mypy:
33-
pipenv run mypy lambdas
32+
pipenv run mypy .
3433

35-
pylama:
36-
pipenv run pylama --options setup.cfg
34+
ruff:
35+
pipenv run ruff check .
3736

3837
safety:
3938
pipenv check
4039
pipenv verify
40+
41+
# apply changes to resolve any linting errors
42+
lint-apply: black-apply ruff-apply
43+
44+
black-apply:
45+
pipenv run black .
46+
47+
ruff-apply:
48+
pipenv run ruff check --fix .

Pipfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ name = "pypi"
77
sentry-sdk = "*"
88

99
[dev-packages]
10-
bandit = "*"
1110
black = "*"
12-
coverage = "*"
1311
coveralls = "*"
1412
mypy = "*"
15-
pylama = {extras = ["all"], version = "*"}
13+
pre-commit = "*"
1614
pytest = "*"
15+
ruff = "*"
1716

1817
[requires]
19-
python_version = "3.9"
18+
python_version = "3.11"

lambdas/my_function.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
logger.info("No Sentry DSN found, exceptions will not be sent to Sentry")
2424

2525

26-
def lambda_handler(event: dict, context: object) -> str: # noqa
26+
def lambda_handler(event: dict) -> str:
2727
if not os.getenv("WORKSPACE"):
28-
raise RuntimeError("Required env variable WORKSPACE is not set")
28+
unset_workspace_error_message = "Required env variable WORKSPACE is not set"
29+
raise RuntimeError(unset_workspace_error_message)
2930

3031
logger.debug(json.dumps(event))
3132

pyproject.toml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# We do our best to sync this template with the latest version in our internal documentation.
2+
# For MIT developers, we strongly recommend copying the pyproject.toml template from:
3+
# https://mitlibraries.atlassian.net/wiki/spaces/IN/pages/3432415247/Python+Project+Linters#Template-for-pyproject.toml
4+
5+
[tool.black]
6+
line-length = 90
7+
8+
[tool.mypy]
9+
disallow_untyped_calls = true
10+
disallow_untyped_defs = true
11+
exclude = ["tests/"]
12+
13+
[tool.pytest.ini_options]
14+
log_level = "INFO"
15+
16+
[tool.ruff]
17+
target-version = "py311"
18+
select = ["ALL", "PT"]
19+
20+
ignore = [
21+
# default
22+
"ANN101",
23+
"ANN102",
24+
"COM812",
25+
"D107",
26+
"N812",
27+
"PTH",
28+
29+
# project-specific
30+
"C90",
31+
"D100",
32+
"D101",
33+
"D102",
34+
"D103",
35+
"D104",
36+
"PLR0912",
37+
"PLR0913",
38+
"PLR0915",
39+
"S320",
40+
"S321",
41+
]
42+
43+
# allow autofix behavior for specified rules
44+
fixable = ["E", "F", "I", "Q"]
45+
46+
# set max line length
47+
line-length = 90
48+
49+
# enumerate all fixed violations
50+
show-fixes = true
51+
52+
[tool.ruff.flake8-annotations]
53+
mypy-init-return = true
54+
55+
[tool.ruff.flake8-pytest-style]
56+
fixture-parentheses = false
57+
58+
[tool.ruff.per-file-ignores]
59+
"tests/**/*" = [
60+
"ANN",
61+
"ARG001",
62+
"S101",
63+
]
64+
65+
[tool.ruff.pycodestyle]
66+
max-doc-length = 90
67+
68+
[tool.ruff.pydocstyle]
69+
convention = "google"

setup.cfg

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/conftest.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import os
2-
31
import pytest
42

53

64
@pytest.fixture(autouse=True)
7-
def test_env():
8-
os.environ = {"WORKSPACE": "test"}
9-
yield
5+
def _test_env(monkeypatch):
6+
monkeypatch.setenv("WORKSPACE", "test")

0 commit comments

Comments
 (0)