From c1158583dd6bc5ec0a5f4aaf953f5d5bf30152f6 Mon Sep 17 00:00:00 2001 From: Charles Roelli Date: Thu, 30 Apr 2026 16:10:50 +0200 Subject: Remove output-directory setting which duplicates STATIC_ROOT --- README.md | 4 ---- src/hatch_django_collectstatic/plugin.py | 29 ++++++++--------------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 53a8253..a0d8b2f 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,6 @@ settings = "my_django_package.project.settings" # Default value of require-runtime-dependencies = false # require-runtime-dependencies = true -# Output directory where static files are collected in the target. -# Default value of output-directory = "static" -# output-directory = "custom-static-directory" - [tool.hatch.build.targets.wheel.shared-data] # Mapping from output directory to the distribution path. The # following configuration will place the files in the .data directory diff --git a/src/hatch_django_collectstatic/plugin.py b/src/hatch_django_collectstatic/plugin.py index ec3c4dd..f8bf759 100644 --- a/src/hatch_django_collectstatic/plugin.py +++ b/src/hatch_django_collectstatic/plugin.py @@ -1,7 +1,9 @@ -import importlib +import os import sys from pathlib import Path +import django.core.management + from django import setup from django.contrib.staticfiles.management.commands.collectstatic import Command from hatchling.builders.hooks.plugin.interface import BuildHookInterface @@ -11,25 +13,10 @@ 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=self.config.get("output-directory", "static"), - STATIC_URL=project_settings.STATIC_URL, + sys.path.extend( + str(Path(package).parent) + for package in self.build_config.default_packages() ) + os.environ["DJANGO_SETTINGS_MODULE"] = self.config["settings"] 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, - ) + django.core.management.call_command(Command()) -- cgit v1.3