diff options
| -rw-r--r-- | LICENSE.txt | 21 | ||||
| -rw-r--r-- | README.md | 18 | ||||
| -rw-r--r-- | pyproject.toml | 33 | ||||
| -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 |
6 files changed, 115 insertions, 0 deletions
diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..7989fd2 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Charles Roelli + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..44d074b --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# hatch-django-collectstatic + +Collect a django project's static files into its binary distribution +archive. + +Example usage: + +``` +[build-system] +requires = ["hatchling >= 1.26", "hatch-django-collectstatic"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel.hooks.django-collectstatic] +settings = "ppr.project.settings" + +[tool.hatch.build.targets.wheel.shared-data] +"static" = "share/static" +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..feb40e8 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +requires = ["hatchling >= 1.26"] +build-backend = "hatchling.build" + +[project] +dependencies = [ + "django", "hatchling" +] +name = "hatch-django-collectstatic" +version = "0.0.2" +authors = [ + { name="Charles Roelli", email="charles@adnoto.net" }, +] +description = "Build, collect and distribute django static files" +keywords = ["django", "collectstatic", "hatch", "hatchling"] +readme = "README.md" +requires-python = ">=3.11" +classifiers = [ + "Development Status :: 4 - Beta", + "Topic :: Software Development :: Build Tools", + "Framework :: Hatch", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +license = "MIT" +license-files = ["LICEN[CS]E*"] + +[project.urls] +Homepage = "https://adnoto.net/" +Issues = "https://adnoto.net/" + +[project.entry-points.hatch] +django-collectstatic = "hatch_django_collectstatic.hooks" 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, + ) |
