Code

Ticket #6080: reusableapps.diff

File reusableapps.diff, 8.4 KB (added by jezdez, 6 years ago)

first implementation

Line 
1Index: django/db/models/loading.py
2===================================================================
3--- django/db/models/loading.py (revision 6789)
4+++ django/db/models/loading.py (working copy)
5@@ -5,9 +5,16 @@
6 import sys
7 import os
8 import threading
9+try:
10+    from pkg_resources import working_set, DistributionNotFound, \
11+        Environment, VersionConflict, UnknownExtra
12+except ImportError:
13+    pkg_resources_is_available = True
14+else:
15+    pkg_resources_is_available = False
16 
17 __all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models',
18-        'load_app', 'app_cache_ready')
19+        'load_app', 'app_cache_ready', 'get_all_apps')
20 
21 class AppCache(object):
22     """
23@@ -49,7 +56,7 @@
24         try:
25             if self.loaded:
26                 return
27-            for app_name in settings.INSTALLED_APPS:
28+            for app_name in self.get_all_apps():
29                 if app_name in self.handled:
30                     continue
31                 self.load_app(app_name, True)
32@@ -60,6 +67,30 @@
33         finally:
34             self.write_lock.release()
35 
36+    def get_all_apps(self):
37+        """
38+        Looks for apps in the directories defined by the ``APP_DIRS`` setting
39+        if ``pkg_resources`` (part of setuptools) is installed.
40+
41+        Every module having the entry point like the setting ``APP_ENTRY_POINT``
42+        will be added to the Python path, if necesary.
43+
44+        Returns a tuple with INSTALLED_APPS and all found apps.
45+        """
46+        APP_LIST = []
47+        if pkg_resources_is_available:
48+            # find every "distribution" in the app directory paths and add
49+            # them to the "working_set", effectively setting the PYTHONPATH
50+            app_environment = Environment(settings.APPS_DIRS)
51+            map(working_set.add, working_set.find_plugins(app_environment)[0])
52+            # look for entry points in all distributions currently on the
53+            # PYTHONPATH and add matching modules to INSTALLED_APPS
54+            for entry in working_set.iter_entry_points(settings.APP_ENTRY_POINT):
55+                app = entry.module_name
56+                if app not in settings.INSTALLED_APPS and app not in APP_LIST:
57+                    APP_LIST.append(app_name)
58+        return settings.INSTALLED_APPS + tuple(APP_LIST)
59+
60     def load_app(self, app_name, can_postpone=False):
61         """
62         Loads the app with the provided fully qualified name, and returns the
63@@ -185,3 +216,4 @@
64 register_models = cache.register_models
65 load_app = cache.load_app
66 app_cache_ready = cache.app_cache_ready
67+get_all_apps = cache.get_all_apps
68Index: django/conf/global_settings.py
69===================================================================
70--- django/conf/global_settings.py      (revision 6789)
71+++ django/conf/global_settings.py      (working copy)
72@@ -134,6 +134,12 @@
73 # List of strings representing installed apps.
74 INSTALLED_APPS = ()
75 
76+# List of locations of reusable apps, in search order.
77+APP_DIRS = ()
78+
79+# Entry point name of reusable Django apps
80+APP_ENTRY_POINT = 'django.apps'
81+
82 # List of locations of the template source files, in search order.
83 TEMPLATE_DIRS = ()
84 
85Index: setup.py
86===================================================================
87--- setup.py    (revision 6789)
88+++ setup.py    (working copy)
89@@ -1,5 +1,13 @@
90-from distutils.core import setup
91-from distutils.command.install import INSTALL_SCHEMES
92+try:
93+    from setuptools import setup
94+except ImportError:
95+    from distutils.core import setup
96+    from distutils.command.install import INSTALL_SCHEMES
97+    # Tell distutils to put the data_files in platform-specific installation
98+    # locations. See here for an explanation:
99+    # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
100+    for scheme in INSTALL_SCHEMES.values():
101+        scheme['data'] = scheme['purelib']
102 import os
103 import sys
104 
105@@ -17,12 +25,6 @@
106         return result
107     return fullsplit(head, [tail] + result)
108 
109-# Tell distutils to put the data_files in platform-specific installation
110-# locations. See here for an explanation:
111-# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
112-for scheme in INSTALL_SCHEMES.values():
113-    scheme['data'] = scheme['purelib']
114-
115 # Compile the list of packages available, because distutils doesn't have
116 # an easy way to do this.
117 packages, data_files = [], []
118@@ -46,18 +48,29 @@
119 # Dynamically calculate the version based on django.VERSION.
120 version_tuple = __import__('django').VERSION
121 if version_tuple[2] is not None:
122-    version = "%d.%d_%s" % version_tuple
123+    version = "%d.%d%s" % version_tuple
124 else:
125     version = "%d.%d" % version_tuple[:2]
126 
127 setup(
128     name = "Django",
129     version = version,
130+    license = 'BSD',
131     url = 'http://www.djangoproject.com/',
132     author = 'Lawrence Journal-World',
133     author_email = 'holovaty@gmail.com',
134     description = 'A high-level Python Web framework that encourages rapid development and clean, pragmatic design.',
135     packages = packages,
136     data_files = data_files,
137+    install_requires = ['setuptools>=0.6c7', 'Flup'],
138     scripts = ['django/bin/django-admin.py'],
139+    extras_require = {
140+        'MySQL':  ["MySQLdb>=1.2.1p2"],
141+        'SQLite': ["pysqlite>=2.0.3"],
142+        'PostgreSQL': ["psycopg>=1.1.21"],
143+        'PostgreSQL2': ["psycopg2>=2.0.5"],
144+        'Oracle': ["cx_Oracle>=4.3.1"],
145+        'PyYaml': ["PyYaml"],
146+    },
147+    zip_safe = False,
148 )
149Index: docs/install.txt
150===================================================================
151--- docs/install.txt    (revision 6789)
152+++ docs/install.txt    (working copy)
153@@ -224,6 +224,48 @@
154 command ``svn update`` from within the ``django-trunk`` directory. When you do
155 this, Subversion will automatically download any changes.
156 
157+Installing using setuptools' ``develop`` command
158+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159+**New in Django development version**
160+
161+If you already installed setuptools_ you can skip step 3 and 4 of the
162+instructions above and use the ``develop`` command of setuptools instead::
163+
164+    python setup.py develop
165+
166+This adds a special file automatically to your system's ``site-packages``
167+directory and enables the Python intepreter to find the Django checkout without the need to create a symbolic link or to set the ``PYTHONPATH`` environment variable. This is also platform-independent.
168+
169+Installing using easy_install
170+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171+**New in Django development version**
172+
173+If you want to benefit from setuptools_'s package management and dependency tracking, don't hesitate to install Django with easy_install_.
174+
175+1. Make sure that you have Subversion_ and setuptools_ installed, and that you
176+   can run its commands from a shell. (Enter ``svn help`` or
177+   ``easy_install --help`` at a shell prompt to test this.)
178+
179+2. Install Django's main development branch (the 'trunk') like so::
180+
181+    easy_install http://code.djangoproject.com/svn/django/trunk/
182+
183+   The above line checks out Django's source automatically and runs
184+   ``python setup.py install`` for you.
185+
186+If you want setuptools to install one of several recommended extras or a
187+Python database binding during Django's installation, you can also use
188+easy_install_ like this::
189+
190+    easy_install Django[PostgreSQL]
191+    easy_install Django[SQLite, PyYaml]
192+
193+To see a full list of the available extras, open ``setup.py`` and look at the
194+``extras_require`` keyword.
195+
196+
197 .. _`download page`: http://www.djangoproject.com/download/
198 .. _Subversion: http://subversion.tigris.org/
199 .. _from the Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx
200+.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
201+.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall
202Index: docs/settings.txt
203===================================================================
204--- docs/settings.txt   (revision 6789)
205+++ docs/settings.txt   (working copy)
206@@ -216,6 +216,21 @@
207 then ``{% ssi /home/html/foo.txt %}`` would work, but ``{% ssi /etc/passwd %}``
208 wouldn't.
209 
210+APP_DIRS
211+--------
212+
213+Default: ``()`` (Empty tuple)
214+
215+List of locations of reusable Django apps, in search order. Note that
216+these paths should use Unix-style forward slashes, even on Windows.
217+
218+APP_ENTRY_POINT
219+---------------
220+
221+Default: ``'django.apps'``
222+
223+Name of the entry point which is used to load reusable Django apps.
224+
225 APPEND_SLASH
226 ------------
227