djblets.extensions.packaging¶
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.
-
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
(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.
Parameters: - 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.
Parameters: Returns: True
if a filename in one or more bundles matches the pattern.False
if no filenames match.Return type:
-
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 reading package.json
.Raises: distutils.errors.DistutilsExecError
– npm could not be found, or there was an error installing the package.
-