5

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?

Joost
  • 4,094
  • 3
  • 27
  • 58
  • Looking at the sourcecode: https://github.com/django/django/blob/master/django/core/management/__init__.py The management commands are pretty restrictive - in the sense they only allow built ins or apps defined in INSTALLED_APPS – karthikr Oct 30 '16 at 20:51
  • Right, I was afraid of that (now that you mention it, looking at the source should've been my first try). Is there a different, standard approach to make a command available to `tox`, besides as a management command? – Joost Oct 30 '16 at 20:53
  • One approach i have taken in the past - though not very elegant is to have a `scripts/` directory and call the `django.setup()` to register it as a django script - it has its down sides though. – karthikr Oct 30 '16 at 21:00
  • The other thing you could do is, have your app installed as a part of `requirements.txt`, and configure any of the custom apps to call this. – karthikr Oct 30 '16 at 21:02

1 Answers1

1

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']
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895