diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..1b51213 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +export PYTHONDEVMODE=1 +export VIRTUAL_ENV=.venv +layout python3 +export DJANGO_SETTINGS_MODULE=dx.settings +export DJANGO_CONFIGURATION=Local diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4dd1b78 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,4 @@ +- repo: https://github.com/peterdemin/pip-compile-multi + rev: v2.6.2 + hooks: + - id: pip-compile-multi-verify diff --git a/justfile b/justfile new file mode 100644 index 0000000..3fe2aed --- /dev/null +++ b/justfile @@ -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 diff --git a/pyproject.toml b/pyproject.toml index e87510d..c17d348 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,3 +13,16 @@ build-backend = "hatchling.build" [tool.pytest.ini_options] 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 diff --git a/requirements/base.in b/requirements/base.in index 54d157a..797b722 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,2 +1,3 @@ +django-configurations django>=5.1,<5.2 pip-lock diff --git a/requirements/base.txt b/requirements/base.txt index 66a8864..3ea6a65 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,4 +1,4 @@ -# SHA1:e1677d1f2cf78dc26b96c6f8b02f0a0192f1d402 +# SHA1:78e037786a8e05baa81b92ef0373bd8fc1069bd9 # # This file is autogenerated by pip-compile-multi # To update, run: @@ -8,6 +8,10 @@ asgiref==3.8.1 # via django django==5.1.3 + # via + # -r requirements/base.in + # django-configurations +django-configurations==2.5.1 # via -r requirements/base.in pip-lock==2.12.0 # via -r requirements/base.in diff --git a/src/dx/__init__.py b/src/dx/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/dx/settings.py b/src/dx/settings.py new file mode 100644 index 0000000..2ff9590 --- /dev/null +++ b/src/dx/settings.py @@ -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 diff --git a/src/dx/urls.py b/src/dx/urls.py new file mode 100644 index 0000000..637600f --- /dev/null +++ b/src/dx/urls.py @@ -0,0 +1 @@ +urlpatterns = [] diff --git a/src/foo.py b/src/foo.py new file mode 100644 index 0000000..7dbdb99 --- /dev/null +++ b/src/foo.py @@ -0,0 +1,2 @@ +def dummy(): + return (1, 1, 1) diff --git a/src/manage.py b/src/manage.py new file mode 100755 index 0000000..22d839f --- /dev/null +++ b/src/manage.py @@ -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() diff --git a/tests/test_something.py b/tests/test_something.py new file mode 100644 index 0000000..c448d64 --- /dev/null +++ b/tests/test_something.py @@ -0,0 +1,8 @@ +def test_always_true(): + assert True + + +def test_something_in_src(): + from foo import dummy + + assert dummy() == (1, 1, 1)