INSTALLED_APPS dependency tracking

22 views
Skip to first unread message

Tim Chase

unread,
May 4, 2007, 4:34:54 PM5/4/07
to django...@googlegroups.com
I had a want for some simple dependency tracking in the
INSTALLED_APPS of my settings.py, so I cranked out the code
below. I don't know if it would help anybody else, but I wanted
to be able to specify via the DEPENDENCIES that proj.app2
depended on app3, app4, and app6, and so on. That way, I could
change my SPECIFIED_APPS based on my install to only include the
relevant apps and have my INSTALLED_APPS update with the proper
dependencies as well. It should handle circular references too.
Or maybe there's something like this already in Django that I
missed? :)

Anyways, if anybody finds it useful, feel free to play with it.

-tim

# various entries of the items as they would
# appear in the INSTALLED_APPS
APP1 = 'proj.app1'
APP2 = 'proj.app2'
APP3 = 'proj.app3'
APP4 = 'proj.app4'
APP5 = 'proj.app5'
APP6 = 'proj.app6'
APP7 = 'proj.app7'
APP8 = 'proj.app8'
APP9 = 'proj.app9'

# of the form KEY: [apps that KEY depends on]
DEPENDENCIES = {
APP2: [APP6, APP4, APP3],
APP5: [APP6, APP2],
APP6: [APP7, APP9, APP8],
}

# apps that you actually want in this deployment
SPECIFIED_APPS = [
APP1,
APP2,
]

def dependency_track(dependencies, specs):
results = set()
dependencys_to_process = specs
while dependencys_to_process:
dependency = dependencys_to_process.pop()
if dependency not in results:
results.add(dependency)
if dependency in dependencies:
dependencys_to_process.extend(
[d for d in dependencies[dependency] if d not in
results]
)
return tuple(results)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
) + dependency_track(DEPENDENCIES, SPECIFIED_APPS)

print INSTALLED_APPS

d...@simon.net.nz

unread,
May 5, 2007, 8:27:20 AM5/5/07
to Django users
Hi Tim,

This looks interesting, and there was some discussion of something
similar for django (quite a while ago: [1]). Could you create a ticket
at code.djangoproject.com with a brief overview of how you did this,
to stimulate further discussion?

Thanks,
Simon G.

[1] http://groups.google.com/group/django-developers/msg/be076ab6855b9b9f

Tim Chase

unread,
May 5, 2007, 9:38:48 AM5/5/07
to django...@googlegroups.com
> This looks interesting, and there was some discussion of something
> similar for django (quite a while ago: [1]). Could you create a ticket
> at code.djangoproject.com with a brief overview of how you did this,
> to stimulate further discussion?

Ticket #4224 created with a fair bit of rambling description.

http://code.djangoproject.com/ticket/4224

Better more detail than insufficient detail, IMHO. :*)

-tim


Reply all
Reply to author
Forward
0 new messages