From 4c12b29ef228c2cf5d5fd0b5964060935907d987 Mon Sep 17 00:00:00 2001 From: Charles Roelli Date: Thu, 5 Feb 2026 16:10:03 +0100 Subject: Version 0.0.2 --- src/hatch_django_collectstatic/plugin.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/hatch_django_collectstatic/plugin.py (limited to 'src/hatch_django_collectstatic/plugin.py') diff --git a/src/hatch_django_collectstatic/plugin.py b/src/hatch_django_collectstatic/plugin.py new file mode 100644 index 0000000..5f3ba68 --- /dev/null +++ b/src/hatch_django_collectstatic/plugin.py @@ -0,0 +1,35 @@ +import importlib +import sys +from pathlib import Path + +from django import setup +from django.contrib.staticfiles.management.commands.collectstatic import Command +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + + +class DjangoCollectstaticBuildHook(BuildHookInterface): + PLUGIN_NAME = "django-collectstatic" + + def initialize(self, version, build_data): + from django.conf import settings + + sys.path.insert(0, str(Path(self.root) / "src")) + project_settings = importlib.import_module(self.config["settings"]) + + settings.configure( + INSTALLED_APPS=project_settings.INSTALLED_APPS, + STATIC_ROOT="static", + STATIC_URL=project_settings.STATIC_URL, + ) + setup() + collectstatic_command = Command() + collectstatic_command.handle( + interactive=False, + verbosity=1, + link=False, + clear=False, + dry_run=False, + ignore_patterns=[], + use_default_ignore_patterns=True, + post_process=True, + ) -- cgit v1.3