Add flexible support for packaging static media for extensions.

Review Request #13662 — Created March 24, 2024 and submitted

Information

Djblets
release-5.x

Reviewers

The old Djblets extension packaging code made a number of assumptions
about how extension static media would be packaged. It had some
capabilities to override settings (such as providing custom LessCSS
global variables), but made assumptions on the environmental setup and
the usage of setuptools.

This change redoes much of this, splitting
djblets.extensions.packaging into submodules for static_media and
setuptools_backend.

The static_media module contains two classes:

  • StaticMediaBuildContext: Manages state and general configuration for
    building static media.

  • StaticMediaBuilder: Sets up a Django and Pipeline environment and
    initiates the build process.

This can then be driven by a packaging backend. The setuptools_backend
module contains the original functions and classes comprising the
setuptools-based backend, though wrapping the new static_media
classes. Subclasses can set a custom class for either of the
static_media classes on the Setuptools backend in order to customize
behavior.

One of the features of the new backend is support for defining a
.npm-workspaces directory, which contains symlinks to other trees that
may provide static media files that may be needed by the build system.
This defaults to a djblets symlink, but subclasses can add additional
backends.

Down the road, the expectation is that we'll have better support for
using modern pyproject.toml-configured build backends for
extensions, and this change would help get us there.

The original classes can still be imported and used as before, but are
now deprecated, with useful information on moving to the modern classes.

Unit tests pass.

Tested building rbintegrations with this change, both with legacy
usage in Review Board and with updated usage.

Summary ID
Add flexible support for packaging static media for extensions.
The old Djblets extension packaging code made a number of assumptions about how extension static media would be packaged. It had some capabilities to override settings (such as providing custom LessCSS global variables), but made assumptions on the environmental setup and the usage of setuptools. This change redoes much of this, splitting `djblets.extensions.packaging` into submodules for `static_media` and `setuptools_backend`. The `static_media` module contains two classes: * `StaticMediaBuildContext`: Manages state and general configuration for building static media. * `StaticMediaBuilder`: Sets up a Django and Pipeline environment and initiates the build process. This can then be driven by a packaging backend. The `setuptools_backend` module contains the original functions and classes comprising the setuptools-based backend, though wrapping the new `static_media` classes. Subclasses can set a custom class for either of the `static_media` classes on the Setuptools backend in order to customize behavior. One of the features of the new backend is support for defining a `.npm-workspaces` directory, which contains symlinks to other trees that may provide static media files that may be needed by the build system. This defaults to a `djblets` symlink, but subclasses can add additional backends. Down the road, the expectation is that we'll have better support for using modern `pyproject.toml`-configured build backends for extensions, and this change would help get us there. The original classes can still be imported and used as before, but are now deprecated, with useful information on moving to the modern classes.
b1c45f8afaa5eff976393a7ddca4d8d1cce02daa
Description From Last Updated

undefined name '_StaticMediaBuilder' Column: 40 Error code: F821

reviewbotreviewbot

'django.test.utils.override_settings' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

'djblets.extensions.extension.Extension' imported but unused Column: 1 Error code: F401

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-5.x (a4936f1)