Jump to >

This documentation covers the in-development release of Djblets. You can see the latest stable docs or all previous versions.


Packaging support for extensions.

class BuildStaticFiles(dist, **kw)[source]

Bases: setuptools.Command

Builds static files for the extension.

This will build the static media files used by the extension. JavaScript bundles will be minified and versioned. CSS bundles will be processed through lesscss (if using .less files), minified and versioned.

This must be subclassed by the project offering the extension support. The subclass must provide the extension_entrypoint_group and django_settings_module parameters.

extension_entrypoint_group is the group name that entry points register into.

django_settings_module is the Python module path for the project’s settings module, for use in the DJANGO_SETTINGS_MODULE environment variable.

description = u'Build static media files'[source]
extension_entrypoint_group = None[source]
django_settings_module = None[source]
user_options = [('remove-source-files', None, u'remove source files from the package')][source]
boolean_options = ['remove-source-files'][source]

Returns a dictionary of LessCSS global variables and their values.

This can be implemented by subclasses to provide global variables for .less files for processing.

By default, this defines two variables: STATIC_ROOT and DEBUG.

STATIC_ROOT is set to /static/. Any imports using @{STATIC_ROOT} will effectively look up the requested file in <import_path>/@{STATIC_ROOT}. This assumes that the project serving the static files keeps them in static/appname/.

Projects using less.js for the runtime can then define STATIC_ROOT to settings.STATIC_URL, ensuring lookups work for development and packaged extensions.

DEBUG is set to false. Runtimes using less.js can set this to settings.DEBUG for templates. This can be useful for LessCSS guards.

This requires LessCSS 1.5.1 or higher.


Returns the include path for LessCSS imports.

By default, this will include the parent directory of every path in STATICFILES_DIRS, plus the static directory of the extension.

install_pipeline_deps(extension, css_bundles, js_bundles)[source]

Install dependencies needed for the static media pipelining.

This will install the LessCSS and UglifyJS tools, if needed for the packaging process. These will only be installed if they’d be used, which is determined based on the contents of the bundles.

Subclasses can override this to support additional tools.

  • extension (djblets.extensions.extension.Extension) – The extension being packaged.
  • css_bundles (dict) – A dictionary of CSS bundles being built for the package.
  • js_bundles (dict) – A dictionary of JavaScript bundles being built for the package.
get_bundle_file_matches(bundles, pattern)[source]

Return whether there’s any files in a bundle matching a pattern.

  • bundles (dict) – A dictionary of bundles.
  • pattern (unicode) – The filename pattern to match against.

True if a filename in one or more bundles matches the pattern. False if no filenames match.

Return type:



Install a package via npm.

This will first determine if npm is available, and then attempt to install the given package.

Parameters:package_spec (unicode, optional) – The package specification (name and optional version range) to install. If not specified, this will use the default behavior of reading package.json.
Raises:distutils.errors.DistutilsExecErrornpm could not be found, or there was an error installing the package.
class BuildPy(dist, **kw)[source]

Bases: setuptools.command.build_py.build_py


Builds a cmdclass to pass to setup.

This is passed a subclass of BuildStaticFiles, and returns something that can be passed to setup().