Joost
Joost

Reputation: 4134

Django add management command without installing as app

I've created a package for use with django, the main feature of which is accessible through a management command. However, in order to make management commands accessible, django seems to insist on the package being listed as an app in INSTALLED_APPS in settings.py.

This application is merely used as part of our build process while doing intergration testing. It does not even need to be installed on developer machines, let alone end up in our production environment. However, since it needs to be in settings.py's installed apps, it also spreads to requirements.txt, as it suddenly breaks builds wherever it is not installed.

Is there a way to inject a management command without the package being installed as a full-blown app?

Alternatively: is there a standard/recommended way to make a command available to tox in a different way than through a management command?

Upvotes: 5

Views: 2497

Answers (2)

Kamil
Kamil

Reputation: 11

Check out my django-management-commands app/plugin just released:

https://github.com/paduszyk/django-management-commands

It provides a simple wrapper for django.command.management.execute_from_comand_line that is used by default in Django projects in their started scripts (commonly named manage.py). The plugin offers defining apps outside apps, defining custom modules for command discovery, and aliasing of commands or their sequences.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599610

One solution is to have a separate settings.py for the build process that adds the app containing this command to INSTALLED_APPS. Then you can run manage.py mycommand --settings=build_settings or whatever.

The settings file itself can be as simple as:

from main_settings import *
INSTALLED_APPS += ['myapp']

Upvotes: 1

Related Questions