From 7949d2eb6cda137adbb02c5e6f0ae6f7a39ebecc Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Mon, 18 Nov 2024 11:20:44 +0000 Subject: [PATCH 1/3] Add helper script to make migrations --- makemigrations.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 makemigrations.py diff --git a/makemigrations.py b/makemigrations.py new file mode 100644 index 0000000..cec02f1 --- /dev/null +++ b/makemigrations.py @@ -0,0 +1,30 @@ +"""Minimal script to make migrations without a manage.py file.""" + +import sys + +import django +from django.conf import settings + +settings.configure( + INSTALLED_APPS=[ + "django.contrib.auth", + "django.contrib.admin", + "django.contrib.contenttypes", + "django.contrib.sites", + "imperial_coldfront_plugin", + ], + # below checks do not need to pass to makemigrations + SILENCED_SYSTEM_CHECKS=[ + "admin.E403", + "admin.E406", + "admin.E408", + "admin.E409", + "admin.E410", + ], +) +django.setup() + +if __name__ == "__main__": + from django.core.management import call_command + + call_command("makemigrations", *sys.argv[1:]) From 8aa535886c56c698778b855b23ebe9e4a1fc1088 Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Mon, 18 Nov 2024 11:27:31 +0000 Subject: [PATCH 2/3] Document how to make migrations in README --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 11695ee..bb7328a 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,23 @@ To upgrade pinned versions, use the `--upgrade` flag with `pip-compile`. Versions can be restricted from updating within the `pyproject.toml` using standard python package version specifiers, i.e. `"black<23"` or `"pip-tools!=6.12.2"` +## Making Migrations + +As a standalone Django application this plugin provides models to extend the +Coldfront data model. A helper script is provided to generate migrations for +these models. To use it, run the following command: + +```bash +python makemigrations.py +``` + +This is equivalent to running `python manage.py makemigrations` in a Django +project and all the same options are available. See options with: + +```bash +python makemigrations.py --help +``` + ## Customising All configuration can be customised to your preferences. The key places to make changes From 204d54f9a2432bf8ca791a176dd411fdf91574be Mon Sep 17 00:00:00 2001 From: Christopher Cave-Ayland Date: Mon, 18 Nov 2024 11:35:12 +0000 Subject: [PATCH 3/3] Make pytest ignore makemigrations.py --- pyproject.toml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1d32add..ff0b804 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "A plugin for the Coldfront HPC management platform." authors = [ { name = "Christopher Cave-Ayland", email = "c.cave-ayland@imperial.ac.uk" }, - { name = "Imperial College London RSE Team", email = "ict-rse-team@imperial.ac.uk" } + { name = "Imperial College London RSE Team", email = "ict-rse-team@imperial.ac.uk" }, ] requires-python = "~=3.11" dependencies = [ @@ -42,7 +42,9 @@ requires = ["setuptools", "setuptools-scm"] build-backend = "setuptools.build_meta" [tool.setuptools.packages.find] -exclude = ["htmlcov"] # Exclude the coverage report file from setuptools package finder +exclude = [ + "htmlcov", +] # Exclude the coverage report file from setuptools package finder [tool.mypy] disallow_any_explicit = true @@ -66,7 +68,7 @@ module = ["imperial_coldfront_plugin.oidc"] disallow_any_explicit = false [tool.pytest.ini_options] -addopts = "-v --mypy -p no:warnings --cov=imperial_coldfront_plugin --cov-report=html --doctest-modules --ignore=docs" +addopts = "-v --mypy -p no:warnings --cov=imperial_coldfront_plugin --cov-report=html --doctest-modules --ignore=docs --ignore=makemigrations.py" [tool.ruff] exclude = ["*/migrations"] @@ -79,12 +81,15 @@ select = [ "F", # Pyflakes "I", # isort "UP", # pyupgrade - "RUF" # ruff + "RUF", # ruff ] pydocstyle.convention = "google" [tool.ruff.lint.per-file-ignores] -"tests/*" = ["D100", "D104"] # Missing docstring in public module, Missing docstring in public package +"tests/*" = [ + "D100", + "D104", +] # Missing docstring in public module, Missing docstring in public package [tool.django-stubs] -django_settings_module = "imperial_coldfront_plugin" # a lie but seems to satisfy +django_settings_module = "imperial_coldfront_plugin" # a lie but seems to satisfy