Compare commits

..

10 commits

Author SHA1 Message Date
bronsen
77512fc73c [tooling] Expose commands that are used; add aliases and default recipe 2024-11-21 12:29:53 +01:00
bronsen
ca09a2916e [settings] remove some empty lines 2024-11-21 12:29:19 +01:00
bronsen
d635b7ba05 [tooling] Create simple justfile
Let's see how well it works out for us
2024-11-21 12:19:37 +01:00
bronsen
71c492c648 [meta] Activate Python Development mode 2024-11-21 12:19:06 +01:00
bronsen
cd0b9d9c96 [pytest] Tell it where tests are
Also tell coverage how to behave
2024-11-21 12:16:59 +01:00
bronsen
f4ed431a94 [meta] Use .envrc to set up env variables and activate the virtualenv 2024-11-21 12:16:17 +01:00
bronsen
3603d26f1e [project] start with minimal project
mainly, so we have a `manage.py` script
2024-11-21 12:04:40 +01:00
bronsen
28f7db8b72 [requirements] Rely on django-configurations to manage Django settings 2024-11-21 12:03:42 +01:00
bronsen
b5663d1bc8 [foo] Add a module so we can test and create a coverage report 2024-11-20 23:39:54 +01:00
bronsen
a7c73f559f [pre-commit] add hook to verify the compiled requirements are up-to-date 2024-11-20 23:39:22 +01:00
12 changed files with 120 additions and 1 deletions

5
.envrc Normal file
View file

@ -0,0 +1,5 @@
export PYTHONDEVMODE=1
export VIRTUAL_ENV=.venv
layout python3
export DJANGO_SETTINGS_MODULE=dx.settings
export DJANGO_CONFIGURATION=Local

4
.pre-commit-config.yaml Normal file
View file

@ -0,0 +1,4 @@
- repo: https://github.com/peterdemin/pip-compile-multi
rev: v2.6.2
hooks:
- id: pip-compile-multi-verify

24
justfile Normal file
View file

@ -0,0 +1,24 @@
default: test
alias tc := test-coverage
alias l := lint
alias lf := lint-fix
alias c := compile-dependencies
test:
# pytest options can be found in pyproject.toml
# look for [tool.pytest.ini_options]
python -m pytest
test-coverage:
# here we allow extra arguments to be passed to pytest
python -m pytest --cov=src --cov-config=pyproject.toml
lint:
ruff check .
lint-fix:
ruff check --fix .
compile-dependencies:
pip-compile-multi

View file

@ -13,3 +13,16 @@ build-backend = "hatchling.build"
[tool.pytest.ini_options] [tool.pytest.ini_options]
pythonpath = ["src"] pythonpath = ["src"]
testpaths = ["tests"]
[tool.coverage.run]
branch = true
data_file = "coverage/.coverage"
source = ["src"]
omit = ["*/migrations/*"]
[tool.coverage.html]
directory = "coverage/htmlcov"
[tool.coverage.report]
skip_empty = true

View file

@ -1,2 +1,3 @@
django-configurations
django>=5.1,<5.2 django>=5.1,<5.2
pip-lock pip-lock

View file

@ -1,4 +1,4 @@
# SHA1:e1677d1f2cf78dc26b96c6f8b02f0a0192f1d402 # SHA1:78e037786a8e05baa81b92ef0373bd8fc1069bd9
# #
# This file is autogenerated by pip-compile-multi # This file is autogenerated by pip-compile-multi
# To update, run: # To update, run:
@ -8,6 +8,10 @@
asgiref==3.8.1 asgiref==3.8.1
# via django # via django
django==5.1.3 django==5.1.3
# via
# -r requirements/base.in
# django-configurations
django-configurations==2.5.1
# via -r requirements/base.in # via -r requirements/base.in
pip-lock==2.12.0 pip-lock==2.12.0
# via -r requirements/base.in # via -r requirements/base.in

0
src/dx/__init__.py Normal file
View file

39
src/dx/settings.py Normal file
View file

@ -0,0 +1,39 @@
from pathlib import Path
from configurations import Configuration
BASE_DIR = Path(__file__).resolve().parent.parent
class Base(Configuration):
DEBUG = False
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
INSTALLED_APPS = [
"dx",
]
ROOT_URLCONF = "dx.urls"
SECRET_KEY = "django-insecure-cbgvn=orgh$&6l-w91pp2=(b#hjwe1z&ijwiafgt(py1lq5i85"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR / "templates"],
"APP_DIRS": True,
},
]
USE_TZ = True
class Dev(Base):
# Dangerous: disable host header validation
ALLOWED_HOSTS = ["*"]
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "db.sqlite3",
},
}
DEBUG = True
INSTALLED_APPS = Base.INSTALLED_APPS + ["django_extensions"]
class Local(Dev):
pass

1
src/dx/urls.py Normal file
View file

@ -0,0 +1 @@
urlpatterns = []

2
src/foo.py Normal file
View file

@ -0,0 +1,2 @@
def dummy():
return (1, 1, 1)

18
src/manage.py Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dx.settings")
os.environ.setdefault("DJANGO_CONFIGURATION", "Base")
from configurations.management import execute_from_command_line
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()

8
tests/test_something.py Normal file
View file

@ -0,0 +1,8 @@
def test_always_true():
assert True
def test_something_in_src():
from foo import dummy
assert dummy() == (1, 1, 1)