djblets.extensions.packaging¶
Packaging support for extensions.
- class BuildStaticFiles(dist, **kw)[source]¶
Bases:
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.
- initialize_options()[source]¶
Set default values for all the options that this command supports. Note that these defaults may be overridden by other commands, by the setup script, by config files, or by the command-line. Thus, this is not the place to code dependencies between options; generally, ‘initialize_options()’ implementations are just a bunch of “self.foo = None” assignments.
This method must be implemented by all command classes.
- finalize_options()[source]¶
Set final values for all the options that this command supports. This is always called as late as possible, ie. after any option assignments from the command-line or from other commands have been done. Thus, this is the place to code option dependencies: if ‘foo’ depends on ‘bar’, then it is safe to set ‘foo’ from ‘bar’ as long as ‘foo’ still has the same value it was assigned in ‘initialize_options()’.
This method must be implemented by all command classes.
- get_lessc_global_vars()[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
andDEBUG
.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 instatic/appname/
.Projects using less.js for the runtime can then define
STATIC_ROOT
tosettings.STATIC_URL
, ensuring lookups work for development and packaged extensions.DEBUG
is set to false. Runtimes using less.js can set this tosettings.DEBUG
for templates. This can be useful for LessCSS guards.This requires LessCSS 1.5.1 or higher.
- get_lessc_include_path()[source]¶
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() str [source]¶
Install dependencies needed for the static media pipelining.
This will install the build tools needed for any static media.
Subclasses can override this to support additional tools.
- Returns:
The path to the resulting
node_modules
directory.- Return type:
- get_bundle_file_matches(bundles, pattern)[source]¶
Return whether there’s any files in a bundle matching a pattern.
- npm_install(package_spec=None)[source]¶
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 readingpackage.json
.- Raises:
distutils.errors.DistutilsExecError – npm could not be found, or there was an error installing the package.
- run()[source]¶
A command’s raison d’etre: carry out the action it exists to perform, controlled by the options initialized in ‘initialize_options()’, customized by other commands, the setup script, the command-line, and config files, and finalized in ‘finalize_options()’. All terminal output and filesystem interaction should be done by ‘run()’.
This method must be implemented by all command classes.