Django

Code

Ticket #6080: reusableapps.diff

File reusableapps.diff, 8.4 kB (added by jezdez, 9 months ago)

first implementation

  • django/db/models/loading.py

    old new  
    55import sys 
    66import os 
    77import threading 
     8try: 
     9    from pkg_resources import working_set, DistributionNotFound, \ 
     10        Environment, VersionConflict, UnknownExtra 
     11except ImportError: 
     12    pkg_resources_is_available = True 
     13else: 
     14    pkg_resources_is_available = False 
    815 
    916__all__ = ('get_apps', 'get_app', 'get_models', 'get_model', 'register_models', 
    10         'load_app', 'app_cache_ready'
     17        'load_app', 'app_cache_ready', 'get_all_apps'
    1118 
    1219class AppCache(object): 
    1320    """ 
     
    4956        try: 
    5057            if self.loaded: 
    5158                return 
    52             for app_name in settings.INSTALLED_APPS
     59            for app_name in self.get_all_apps()
    5360                if app_name in self.handled: 
    5461                    continue 
    5562                self.load_app(app_name, True) 
     
    6067        finally: 
    6168            self.write_lock.release() 
    6269 
     70    def get_all_apps(self): 
     71        """ 
     72        Looks for apps in the directories defined by the ``APP_DIRS`` setting 
     73        if ``pkg_resources`` (part of setuptools) is installed. 
     74 
     75        Every module having the entry point like the setting ``APP_ENTRY_POINT`` 
     76        will be added to the Python path, if necesary. 
     77 
     78        Returns a tuple with INSTALLED_APPS and all found apps. 
     79        """ 
     80        APP_LIST = [] 
     81        if pkg_resources_is_available: 
     82            # find every "distribution" in the app directory paths and add 
     83            # them to the "working_set", effectively setting the PYTHONPATH 
     84            app_environment = Environment(settings.APPS_DIRS) 
     85            map(working_set.add, working_set.find_plugins(app_environment)[0]) 
     86            # look for entry points in all distributions currently on the 
     87            # PYTHONPATH and add matching modules to INSTALLED_APPS 
     88            for entry in working_set.iter_entry_points(settings.APP_ENTRY_POINT): 
     89                app = entry.module_name 
     90                if app not in settings.INSTALLED_APPS and app not in APP_LIST: 
     91                    APP_LIST.append(app_name) 
     92        return settings.INSTALLED_APPS + tuple(APP_LIST) 
     93 
    6394    def load_app(self, app_name, can_postpone=False): 
    6495        """ 
    6596        Loads the app with the provided fully qualified name, and returns the 
     
    185216register_models = cache.register_models 
    186217load_app = cache.load_app 
    187218app_cache_ready = cache.app_cache_ready 
     219get_all_apps = cache.get_all_apps 
  • django/conf/global_settings.py

    old new  
    134134# List of strings representing installed apps. 
    135135INSTALLED_APPS = () 
    136136 
     137# List of locations of reusable apps, in search order. 
     138APP_DIRS = () 
     139 
     140# Entry point name of reusable Django apps 
     141APP_ENTRY_POINT = 'django.apps' 
     142 
    137143# List of locations of the template source files, in search order. 
    138144TEMPLATE_DIRS = () 
    139145 
  • setup.py

    old new  
    1 from distutils.core import setup 
    2 from distutils.command.install import INSTALL_SCHEMES 
     1try: 
     2    from setuptools import setup 
     3except ImportError: 
     4    from distutils.core import setup 
     5    from distutils.command.install import INSTALL_SCHEMES 
     6    # Tell distutils to put the data_files in platform-specific installation 
     7    # locations. See here for an explanation: 
     8    # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb 
     9    for scheme in INSTALL_SCHEMES.values(): 
     10        scheme['data'] = scheme['purelib'] 
    311import os 
    412import sys 
    513 
     
    1725        return result 
    1826    return fullsplit(head, [tail] + result) 
    1927 
    20 # Tell distutils to put the data_files in platform-specific installation 
    21 # locations. See here for an explanation: 
    22 # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb 
    23 for scheme in INSTALL_SCHEMES.values(): 
    24     scheme['data'] = scheme['purelib'] 
    25  
    2628# Compile the list of packages available, because distutils doesn't have 
    2729# an easy way to do this. 
    2830packages, data_files = [], [] 
     
    4648# Dynamically calculate the version based on django.VERSION. 
    4749version_tuple = __import__('django').VERSION 
    4850if version_tuple[2] is not None: 
    49     version = "%d.%d_%s" % version_tuple 
     51    version = "%d.%d%s" % version_tuple 
    5052else: 
    5153    version = "%d.%d" % version_tuple[:2] 
    5254 
    5355setup( 
    5456    name = "Django", 
    5557    version = version, 
     58    license = 'BSD', 
    5659    url = 'http://www.djangoproject.com/', 
    5760    author = 'Lawrence Journal-World', 
    5861    author_email = 'holovaty@gmail.com', 
    5962    description = 'A high-level Python Web framework that encourages rapid development and clean, pragmatic design.', 
    6063    packages = packages, 
    6164    data_files = data_files, 
     65    install_requires = ['setuptools>=0.6c7', 'Flup'], 
    6266    scripts = ['django/bin/django-admin.py'], 
     67    extras_require = { 
     68        'MySQL':  ["MySQLdb>=1.2.1p2"], 
     69        'SQLite': ["pysqlite>=2.0.3"], 
     70        'PostgreSQL': ["psycopg>=1.1.21"], 
     71        'PostgreSQL2': ["psycopg2>=2.0.5"], 
     72        'Oracle': ["cx_Oracle>=4.3.1"], 
     73        'PyYaml': ["PyYaml"], 
     74    }, 
     75    zip_safe = False, 
    6376) 
  • docs/install.txt

    old new  
    224224command ``svn update`` from within the ``django-trunk`` directory. When you do 
    225225this, Subversion will automatically download any changes. 
    226226 
     227Installing using setuptools' ``develop`` command  
     228~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     229**New in Django development version** 
     230 
     231If you already installed setuptools_ you can skip step 3 and 4 of the 
     232instructions above and use the ``develop`` command of setuptools instead:: 
     233 
     234    python setup.py develop 
     235 
     236This adds a special file automatically to your system's ``site-packages`` 
     237directory 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. 
     238 
     239Installing using easy_install 
     240~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     241**New in Django development version** 
     242 
     243If you want to benefit from setuptools_'s package management and dependency tracking, don't hesitate to install Django with easy_install_. 
     244 
     2451. Make sure that you have Subversion_ and setuptools_ installed, and that you 
     246   can run its commands from a shell. (Enter ``svn help`` or 
     247   ``easy_install --help`` at a shell prompt to test this.) 
     248 
     2492. Install Django's main development branch (the 'trunk') like so:: 
     250 
     251    easy_install http://code.djangoproject.com/svn/django/trunk/ 
     252 
     253   The above line checks out Django's source automatically and runs 
     254   ``python setup.py install`` for you. 
     255 
     256If you want setuptools to install one of several recommended extras or a 
     257Python database binding during Django's installation, you can also use 
     258easy_install_ like this:: 
     259 
     260    easy_install Django[PostgreSQL] 
     261    easy_install Django[SQLite, PyYaml] 
     262 
     263To see a full list of the available extras, open ``setup.py`` and look at the 
     264``extras_require`` keyword. 
     265 
     266 
    227267.. _`download page`: http://www.djangoproject.com/download/ 
    228268.. _Subversion: http://subversion.tigris.org/ 
    229269.. _from the Control Panel: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sysdm_advancd_environmnt_addchange_variable.mspx 
     270.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools 
     271.. _easy_install: http://peak.telecommunity.com/DevCenter/EasyInstall 
  • docs/settings.txt

    old new  
    216216then ``{% ssi /home/html/foo.txt %}`` would work, but ``{% ssi /etc/passwd %}`` 
    217217wouldn't. 
    218218 
     219APP_DIRS 
     220-------- 
     221 
     222Default: ``()`` (Empty tuple) 
     223 
     224List of locations of reusable Django apps, in search order. Note that 
     225these paths should use Unix-style forward slashes, even on Windows. 
     226 
     227APP_ENTRY_POINT 
     228--------------- 
     229 
     230Default: ``'django.apps'`` 
     231 
     232Name of the entry point which is used to load reusable Django apps. 
     233 
    219234APPEND_SLASH 
    220235------------ 
    221236