API

Commands

django-enabler

Click entrypoint.

django-enabler [OPTIONS] COMMAND [ARGS]...

Options

--verbose

apply

Apply configuration stored in one or more json files.

CONFIG_SET: Path to configuration files

param click.core.Context context:

Click context

param list config_set:

list of paths to addon configuration to load and apply

django-enabler apply [OPTIONS] [CONFIG_SET]...

Arguments

CONFIG_SET

Optional argument(s)

enable

Enable the application in the current django project.

APPLICATION: Application module name (example: ‘djangocms_blog’)

param click.core.Context context:

Click context

param str application:

python module name to enable. It must be the name of a Django application.

django-enabler enable [OPTIONS] APPLICATION

Arguments

APPLICATION

Required argument

install

Install the package in the current virtualenv and enable the corresponding application in the current project.

PACKAGE: Package name as available on PyPi, or rather its requirement string.
Accepts any PEP-508 compliant requirement.
Example: “djangocms-blog~=1.2.0”
param click.core.Context context:

Click context

param str package:

Name of the package to install

param str pip_options:

Additional options passed to pip

django-enabler install [OPTIONS] PACKAGE

Options

--pip-options <pip_options>

Additional options passed as is to pip

Arguments

PACKAGE

Required argument

CLI

app_enabler.enable.apply_configuration(application_config: Dict[str, Any])[source]

Enable django application in the current project

Parameters:

application_config (dict) – addon configuration

app_enabler.enable.apply_configuration_set(config_set: List[Path], verbose: bool = False)[source]

Apply settings from the list of input files.

Parameters:
  • config_set (list) – list of paths to addon configuration to load and apply

  • verbose (bool) – Verbose output (currently unused)

app_enabler.enable.enable_application(application: str, verbose: bool = False)[source]

Enable django application in the current project

Parameters:
  • application (str) – python module name to enable. It must be the name of a Django application.

  • verbose (bool) – Verbose output (currently unused)

app_enabler.enable.output_message(message: str)[source]

Print the given message to stdout.

Parameters:

message (str) – Success message to display

app_enabler.enable.verify_installation(settings: django.conf.LazySettings, application_config: Dict[str, Any]) bool[source]

Verify that package installation has been successful.

Parameters:
  • settings (django.conf.LazySettings) – Path to settings file

  • application_config (dict) – addon configuration

app_enabler.install.get_application_from_package(package: str) str | None[source]

Detect the first in alphabetical order module provided by a package.

This approach is a bit simplistic, but as we only need this to get the addon.json file specified by this package, we can easily enforce this restriction.

Parameters:

package (str) – package name (or rather its requirement string). It can be anything complying with PEP508

Returns:

main (first) module name; if None, package is not available in the current virtualenv

app_enabler.install.install(package: str, verbose: bool = False, pip_options: str = '')[source]

Install the package.

Installation is done via pip executed as a subprocess to ensure maximum compatibility.

Parameters:
  • package (str) – Package name

  • verbose (bool) – Verbose output

  • pip_options (str) – Additional options passed to pip

Loaders

app_enabler.django.get_settings_path(setting: django.conf.LazySettings) str[source]

Get the path of the django settings file path from the django settings object.

Parameters:

setting (django.conf.LazySettings) – Django settings object

Returns:

path to the settings file

app_enabler.django.get_urlconf_path(setting: django.conf.LazySettings) str[source]

Get the path of the django urlconf file path from the django settings object.

Parameters:

setting (django.conf.LazySettings) – Django settings object

Returns:

path to the settings file

app_enabler.django.load_addon(module_name: str) Dict[str, Any] | None[source]

Load addon configuration from json file stored in package resources.

If addon has no configuration, return None.

Parameters:

module_name (str) – name of the python module to load as application

Returns:

addon configuration

Patchers

class app_enabler.patcher.DisableExecute[source]

Patch the manage.py module to remove the execute_from_command_line execution.

visit_Expr(node: AST) Any[source]

Visit the Expr node and remove it if it matches 'execute_from_command_line'.

app_enabler.patcher.monkeypatch_manage(manage_file: str) code[source]

Patch manage.py to be executable without actually running any command.

By using ast we remove the execute_from_command_line call and add an unconditional call to the main function.

Parameters:

manage_file (str) – path to manage.py file

Returns:

patched manage.py code

app_enabler.patcher.setup_django()[source]

Initialize the django environment by leveraging manage.py.

This works by using manage.py to set the DJANGO_SETTINGS_MODULE environment variable for django.setup() to work as it’s unknown at runtime.

This should be safer than reading the manage.py looking for the written variable as it rely on Django runtime behavior.

Manage.py is monkeypatched in memory to remove the call “execute_from_command_line” and executed from memory.

app_enabler.patcher.update_setting(project_setting: str, config: Dict[str, Any])[source]

Patch the settings module to include addon settings.

Original file is overwritten. As file is patched using AST, original comments and file structure is lost.

Parameters:
  • project_setting (str) – project settings file path

  • config (dict) – addon setting parameters

app_enabler.patcher.update_urlconf(project_urls: str, config: Dict[str, Any])[source]

Patch the ROOT_URLCONF module to include addon url patterns.

Original file is overwritten. As file is patched using AST, original comments and file structure is lost.

Parameters:
  • project_urls (str) – project urls.py file path

  • config (dict) – addon urlconf configuration