API

Commands

CLI

Loaders

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) CodeType[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