diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/hatch_django_collectstatic/__init__.py | 0 | ||||
| -rw-r--r-- | src/hatch_django_collectstatic/hooks.py | 8 | ||||
| -rw-r--r-- | src/hatch_django_collectstatic/plugin.py | 35 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/hatch_django_collectstatic/__init__.py b/src/hatch_django_collectstatic/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/hatch_django_collectstatic/__init__.py diff --git a/src/hatch_django_collectstatic/hooks.py b/src/hatch_django_collectstatic/hooks.py new file mode 100644 index 0000000..e36006e --- /dev/null +++ b/src/hatch_django_collectstatic/hooks.py @@ -0,0 +1,8 @@ +from hatchling.plugin import hookimpl + +from .plugin import DjangoCollectstaticBuildHook + + +@hookimpl +def hatch_register_build_hook(): + return DjangoCollectstaticBuildHook 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, + ) |
