Skip to main content

Allows multiple apps to override the same management command in Django

Project description

© 2014 Thomas Khyn

MCMO stands for ‘Management Command Multiple Override’. This django app allows multiple apps to override the same management command without evicting any.

Supports Django 1.4 to 1.7 and matching Python 2 and 3 versions.

Installation

As straightforward as it can be, using pip:

pip install django-mcmo

Usage

In your manage.py file, replace the line:

from django.core import management

by:

from mcmo import management

You can now use applications that concurrently define overrides for django.core management commands. Both commands will be called.

For example, if you are using djinga and django-extra_keywords, which both override Django’s makemessages management command, both commands from both applications will be called subsequently.

The first command which will be called will be the one relative to the application in the latest position in the INSTALLED_APPS.

Alternative usage

In your manage.py is automatically generated (e.g. if you are using buildout with djangorecipebook or djangorecipe), simply make sure that the statement:

import mcmo

is executed before calling django.management.execute_from_command_line.

Importing the package patches the django.core.management module, which functions are then enabled for multiple-override support.

Limitations

The same-name overrides should all derive from the same command class, or at least from on of Django’s base command classes (AppCommand, LabelCommand or NoArgsCommand).

django-mcmo will raise a warning (but the execution will carry on) in case of subclassing inconsistencies. For example, if the command cmd in app1 inherits from AppCommand and the command cmd in app2 inherits from NoArgsCommand. Indeed, as only one command is likely to be executed, the obtained results may not be consistent, depend on the relative position of the apps in INSTALLED_APPS, or raise an exception regarding arguments presence, absence or type.

In practice, same-name commands will only be met when two 3rd party apps override a Django core management command. They will therefore derive from the same Command base class, and cause no issue in 99.9% of the cases.

django-mcmo may also emmit warning messages if the same option is explicitly added in the same command of two distinct apps with command classes not being subclasses of each other.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-mcmo-2.0.zip (18.8 kB view details)

Uploaded Source

File details

Details for the file django-mcmo-2.0.zip.

File metadata

  • Download URL: django-mcmo-2.0.zip
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-mcmo-2.0.zip
Algorithm Hash digest
SHA256 1b3c1ae3604fcf675a5ff1024e2524b1751d9973f7c979981724cf18ab85e2af
MD5 3ece00f4dd8af7cd1b5b24a8cc7fe547
BLAKE2b-256 c398078ebf9f2d1a2ae38f8288a0f24e8bc395ab7d0014f7f866356e2bc6258d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page