Skip to content

Commit 326b7b6

Browse files
authored
feat: Add healthcheck views + urls, typing, ruff linting, src layout (#13)
1 parent 71e244c commit 326b7b6

File tree

25 files changed

+1028
-233
lines changed

25 files changed

+1028
-233
lines changed
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: Linting & formatting
1+
name: Python Checks and Unit Tests
22

33
on:
44
pull_request:
55

66
jobs:
77
test:
88
runs-on: ubuntu-latest
9-
name: Linting and Formatting
9+
name: Python Checks and Unit Tests
1010

1111
steps:
1212
- name: Cloning repo
@@ -20,10 +20,13 @@ jobs:
2020
python-version: 3.12
2121

2222
- name: Install Dependencies
23-
run: poetry install
23+
run: poetry install --with dev
2424

25-
- name: Run Linters
26-
run: |
27-
poetry run black --check .
28-
poetry run isort --check-only --diff .
29-
poetry run flake8
25+
- name: Check for missing migrations
26+
run: poetry run python manage.py makemigrations --no-input --dry-run --check
27+
28+
- name: Check for new typing errors
29+
run: poetry run mypy .
30+
31+
- name: Run Tests
32+
run: poetry run pytest

.pre-commit-config.yaml

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
repos:
2-
- repo: https://github.com/PyCQA/isort
3-
rev: 5.13.2
4-
hooks:
5-
- id: isort
6-
name: isort (python)
7-
- repo: https://github.com/psf/black
8-
rev: 24.4.2
9-
hooks:
10-
- id: black
11-
language_version: python3
12-
- repo: https://github.com/pycqa/flake8
13-
rev: 7.1.0
14-
hooks:
15-
- id: flake8
16-
- repo: https://github.com/python-poetry/poetry
17-
rev: 1.7.1
18-
hooks:
19-
- id: poetry-check
20-
- id: poetry-lock
21-
args: ['--check']
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.11.0
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [--fix]
9+
# Run the formatter.
10+
- id: ruff-format
11+
- repo: https://github.com/python-poetry/poetry
12+
rev: 2.1.1
13+
hooks:
14+
- id: poetry-check
15+
- id: poetry-lock
16+
- repo: local
17+
hooks:
18+
- id: python-typecheck
19+
name: python-typecheck
20+
language: system
21+
entry: poetry run mypy .
22+
require_serial: true
23+
pass_filenames: false
24+
types: [python]
25+
26+
ci:
27+
skip: [python-typecheck]
28+
autoupdate_commit_msg: "ci: pre-commit autoupdate"

manage.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.dev")
7+
8+
try:
9+
from django.core.management import execute_from_command_line
10+
except ImportError:
11+
raise ImportError(
12+
"Couldn't import Django. Are you sure it's installed and "
13+
"available on your PYTHONPATH environment variable? Did you "
14+
"forget to activate a virtual environment?"
15+
)
16+
17+
execute_from_command_line(sys.argv)

poetry.lock

Lines changed: 500 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[tool.poetry]
22
name = "flagsmith_common"
3-
version = "1.4.2"
3+
version = "1.5.0"
44
description = "A repository for including code that is required in multiple flagsmith repositories"
55
authors = ["Matthew Elwell <[email protected]>"]
66
readme = "README.md"
7-
packages = [{ include = "common"}]
7+
packages = [{ include = "common", from = "src" }]
88

99
[tool.poetry.dependencies]
1010
python = "^3.10"
@@ -13,49 +13,66 @@ djangorestframework = "*"
1313
drf-writable-nested = "*"
1414
flagsmith-flag-engine = "*"
1515
djangorestframework-recursive = "*"
16+
django-health-check = "^3.18.3"
1617

1718
[tool.poetry.group.dev.dependencies]
1819
pre-commit = "*"
19-
flake8 = "*"
20-
black = "*"
21-
isort = "*"
20+
ruff = "*"
21+
pytest = "^8.3.4"
22+
pyfakefs = "^5.7.4"
23+
pytest-django = "^4.10.0"
24+
mypy = "^1.15.0"
25+
django-stubs = "^5.1.3"
26+
djangorestframework-stubs = "^3.15.3"
2227

2328
[build-system]
2429
requires = ["poetry-core"]
2530
build-backend = "poetry.core.masonry.api"
2631

27-
[tool.black]
32+
[tool.pytest.ini_options]
33+
addopts = ['--ds=settings.dev', '-vvvv', '-p', 'no:warnings']
34+
console_output_style = 'count'
35+
36+
[tool.ruff]
2837
line-length = 88
29-
target-version = ['py311', 'py312']
30-
include = '\.pyi?$'
31-
exclude = '''
32-
/(
33-
\.eggs
34-
| \.git
35-
| \.hg
36-
| \.mypy_cache
37-
| \.tox
38-
| \.venv
39-
| _build
40-
| buck-out
41-
| build
42-
| dist
43-
| migrations
44-
)/
45-
'''
46-
47-
[tool.isort]
48-
use_parentheses=true
49-
multi_line_output=3
50-
include_trailing_comma=true
51-
line_length=79
52-
known_first_party=['flagsmith','api','app','core','features','environments']
53-
known_third_party=[
54-
'django',
55-
'rest_framework',
56-
'saml2',
57-
'drf_yasg2',
58-
'pytest',
59-
'rest_framework_recursive',
60-
]
61-
skip = ['migrations', '.venv']
38+
indent-width = 4
39+
target-version = "py311"
40+
extend-exclude = ["migrations"]
41+
42+
[tool.ruff.format]
43+
# Like Black, use double quotes for strings.
44+
quote-style = "double"
45+
46+
# Like Black, indent with spaces, rather than tabs.
47+
indent-style = "space"
48+
49+
# Like Black, respect magic trailing commas.
50+
skip-magic-trailing-comma = false
51+
52+
# Like Black, automatically detect the appropriate line ending.
53+
line-ending = "auto"
54+
55+
# Enable auto-formatting of code examples in docstrings. Markdown,
56+
# reStructuredText code/literal blocks and doctests are all supported.
57+
docstring-code-format = true
58+
59+
# Set the line length limit used when formatting code snippets in
60+
# docstrings.
61+
docstring-code-line-length = "dynamic"
62+
63+
[tool.ruff.lint]
64+
# Establish parity with flake8 + isort
65+
select = ["C901", "E4", "E7", "E9", "F", "I", "W"]
66+
ignore = []
67+
fixable = ["ALL"]
68+
unfixable = []
69+
70+
[tool.mypy]
71+
plugins = ["mypy_django_plugin.main"]
72+
strict = true
73+
74+
[tool.django-stubs]
75+
django_settings_module = "settings.dev"
76+
77+
[tool.drf-stubs]
78+
enabled = true
File renamed without changes.

settings/dev.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Settings expected by `mypy_django_plugin`
2+
SENDGRID_API_KEY: str
3+
AWS_SES_REGION_ENDPOINT: str
4+
SEGMENT_RULES_CONDITIONS_LIMIT: int
5+
6+
# Settings required for tests
7+
INSTALLED_APPS = [
8+
"django.contrib.auth",
9+
"django.contrib.contenttypes",
10+
]
11+
DATABASES = {
12+
"default": {
13+
"ENGINE": "django.db.backends.sqlite3",
14+
"NAME": "common",
15+
}
16+
}
File renamed without changes.
File renamed without changes.

src/common/app/urls.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.urls import include, re_path
2+
3+
from common.app import views
4+
5+
urlpatterns = [
6+
re_path(r"^version/?", views.version_info),
7+
re_path(r"^health/liveness/?", views.version_info),
8+
re_path(r"^health/readiness/?", include("health_check.urls", namespace="health")),
9+
re_path(r"^health", include("health_check.urls", namespace="health-deprecated")),
10+
# Aptible health checks must be on /healthcheck and cannot redirect
11+
# see https://www.aptible.com/docs/core-concepts/apps/connecting-to-apps/app-endpoints/https-endpoints/health-checks
12+
re_path(r"^healthcheck", include("health_check.urls", namespace="health-aptible")),
13+
]

0 commit comments

Comments
 (0)