Ticket #14087: namespace_package_pth.5.diff

File namespace_package_pth.5.diff, 16.6 KB (added by bhuztez, 13 years ago)

remove trailing whitespaces

  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index 8f32898..1214a82 100644
    a b def find_management_module(app_name):  
    3939    """
    4040    parts = app_name.split('.')
    4141    parts.append('management')
    42     parts.reverse()
    43     part = parts.pop()
    44     path = None
    45 
    46     # When using manage.py, the project module is added to the path,
    47     # loaded, then removed from the path. This means that
    48     # testproject.testapp.models can be loaded in future, even if
    49     # testproject isn't in the path. When looking for the management
    50     # module, we need look for the case where the project name is part
    51     # of the app_name but the project directory itself isn't on the path.
    52     try:
    53         f, path, descr = imp.find_module(part,path)
    54     except ImportError,e:
    55         if os.path.basename(os.getcwd()) != part:
    56             raise e
     42
     43    for i in range(len(parts), 0, -1):
     44        try:
     45            path = sys.modules['.'.join(parts[:i])].__path__
     46        except AttributeError:
     47            raise ImportError("No package named %s" % parts[i-1])
     48        except KeyError:
     49            continue
     50
     51        parts = parts[i:]
     52        parts.reverse()
     53        break
     54    else:
     55        parts.reverse()
     56        part = parts.pop()
     57        path = sys.path
     58
     59        # When using manage.py, the project module is added to the path,
     60        # loaded, then removed from the path. This means that
     61        # testproject.testapp.models can be loaded in future, even if
     62        # testproject isn't in the path. When looking for the management
     63        # module, we need look for the case where the project name is part
     64        # of the app_name but the project directory itself isn't on the path.
     65        try:
     66            next_path = []
     67            for p in path:
     68                try:
     69                    next_path.append(imp.find_module(part, [p])[1])
     70                except ImportError:
     71                    pass
     72            if not next_path:
     73                raise ImportError("No module named %s" % part)
     74            path = next_path
     75        except ImportError,e:
     76            if os.path.basename(os.getcwd()) != part:
     77                raise e
    5778
    5879    while parts:
    5980        part = parts.pop()
    60         f, path, descr = imp.find_module(part, path and [path] or None)
    61     return path
     81        next_path = []
     82        for p in path:
     83            try:
     84                next_path.append(imp.find_module(part, [p])[1])
     85            except ImportError:
     86                pass
     87        if not next_path:
     88            raise ImportError("No module named %s" % part)
     89        path = next_path
     90
     91    return path[0]
    6292
    6393def load_command_class(app_name, name):
    6494    """
  • new file tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py

    diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py b/tests/regressiontests/admin_scripts/lib1/nons_app/management/commands/nons_app_command1.py
    new file mode 100644
    index 0000000..a393663
    - +  
     1from django.core.management.base import BaseCommand
     2
     3class Command(BaseCommand):
     4    help = 'Test managment commands in non-namespaced app'
     5    requires_model_validation = False
     6    args = ''
     7
     8    def handle(self, *labels, **options):
     9        print 'EXECUTE:nons_app_command1'
  • new file tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py

    diff --git a/tests/regressiontests/admin_scripts/lib1/nons_app/models.py b/tests/regressiontests/admin_scripts/lib1/nons_app/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/npapp/__init__.py b/tests/regressiontests/admin_scripts/lib1/npapp/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/npapp/management.py b/tests/regressiontests/admin_scripts/lib1/npapp/management.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/npapp/models.py b/tests/regressiontests/admin_scripts/lib1/npapp/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/__init__.py
    new file mode 100644
    index 0000000..32f26d8
    - +  
     1# http://packages.python.org/distribute/setuptools.html#namespace-packages
     2try:
     3    __import__('pkg_resources').declare_namespace(__name__)
     4except ImportError:
     5    from pkgutil import extend_path
     6    __path__ = extend_path(__path__, __name__)
  • new file tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py

    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/__init__.py
    new file mode 100644
    index 0000000..32f26d8
    - +  
     1# http://packages.python.org/distribute/setuptools.html#namespace-packages
     2try:
     3    __import__('pkg_resources').declare_namespace(__name__)
     4except ImportError:
     5    from pkgutil import extend_path
     6    __path__ = extend_path(__path__, __name__)
  • new file tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py

    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/management/commands/app1_command1.py
    new file mode 100644
    index 0000000..2f479bb
    - +  
     1from django.core.management.base import BaseCommand
     2
     3class Command(BaseCommand):
     4    help = 'Test managment commands in namespaced apps'
     5    requires_model_validation = False
     6    args = ''
     7
     8    def handle(self, *labels, **options):
     9        print 'EXECUTE:app1_command1'
  • new file tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py

    diff --git a/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/models.py b/tests/regressiontests/admin_scripts/lib1/nsapps/contrib/app1/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/__init__.py
    new file mode 100644
    index 0000000..32f26d8
    - +  
     1# http://packages.python.org/distribute/setuptools.html#namespace-packages
     2try:
     3    __import__('pkg_resources').declare_namespace(__name__)
     4except ImportError:
     5    from pkgutil import extend_path
     6    __path__ = extend_path(__path__, __name__)
  • new file tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py

    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/__init__.py
    new file mode 100644
    index 0000000..32f26d8
    - +  
     1# http://packages.python.org/distribute/setuptools.html#namespace-packages
     2try:
     3    __import__('pkg_resources').declare_namespace(__name__)
     4except ImportError:
     5    from pkgutil import extend_path
     6    __path__ = extend_path(__path__, __name__)
  • new file tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py

    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/management/commands/app2_command1.py
    new file mode 100644
    index 0000000..b9e20a7
    - +  
     1from django.core.management.base import BaseCommand
     2
     3class Command(BaseCommand):
     4    help = 'Test managment commands in namespaced apps'
     5    requires_model_validation = False
     6    args = ''
     7
     8    def handle(self, *labels, **options):
     9        print 'EXECUTE:app2_command1'
  • new file tests/regressiontests/admin_scripts/lib3/_addsitedir.py

    diff --git a/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/models.py b/tests/regressiontests/admin_scripts/lib2/nsapps/contrib/app2/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib3/_addsitedir.py b/tests/regressiontests/admin_scripts/lib3/_addsitedir.py
    new file mode 100644
    index 0000000..9e264d2
    - +  
     1import os.path, site; site.addsitedir(os.path.dirname(__file__))
  • new file tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth

    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth b/tests/regressiontests/admin_scripts/lib3/exapps-nspkg.pth
    new file mode 100644
    index 0000000..1f31155
    - +  
     1import sys,new,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('exapps',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('exapps',new.module('exapps')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
  • new file tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py

    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/__init__.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/management/commands/app3_command1.py
    new file mode 100644
    index 0000000..97f5d33
    - +  
     1from django.core.management.base import BaseCommand
     2
     3class Command(BaseCommand):
     4    help = 'Test managment commands in namespaced apps'
     5    requires_model_validation = False
     6    args = ''
     7
     8    def handle(self, *labels, **options):
     9        print 'EXECUTE:app3_command1'
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/lib3/exapps/app3/models.py b/tests/regressiontests/admin_scripts/lib3/exapps/app3/models.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index 68ebda0..45852ba 100644
    a b class AdminScriptTestCase(unittest.TestCase):  
    9090    def run_test(self, script, args, settings_file=None, apps=None):
    9191        project_dir = os.path.dirname(test_dir)
    9292        base_dir = os.path.dirname(project_dir)
     93        lib1_dir = os.path.join(os.path.dirname(__file__), 'lib1')
     94        lib2_dir = os.path.join(os.path.dirname(__file__), 'lib2')
     95        lib3_dir = os.path.join(os.path.dirname(__file__), 'lib3')
    9396        ext_backend_base_dirs = self._ext_backend_paths()
    9497
    9598        # Remember the old environment
    class AdminScriptTestCase(unittest.TestCase):  
    107110            os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
    108111        elif 'DJANGO_SETTINGS_MODULE' in os.environ:
    109112            del os.environ['DJANGO_SETTINGS_MODULE']
    110         python_path = [project_dir, base_dir]
     113        python_path = [project_dir, base_dir, lib1_dir, lib2_dir, lib3_dir]
    111114        python_path.extend(ext_backend_base_dirs)
    112115        os.environ[python_path_var_name] = os.pathsep.join(python_path)
    113116
    class StartProject(LiveServerTestCase, AdminScriptTestCase):  
    15521555        self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir)
    15531556        self.assertFalse(os.path.exists(testproject_dir))
    15541557
     1558
     1559class NamespacePackagedApps(AdminScriptTestCase):
     1560    def setUp(self):
     1561        self.write_settings('settings.py', apps=['nons_app', 'nsapps.contrib.app1','nsapps.contrib.app2','exapps.app3'])
     1562        test_dir = os.path.dirname(os.path.dirname(__file__))
     1563        settings_file = open(os.path.join(test_dir, 'settings.py'), 'a')
     1564        settings_file.write('import _addsitedir')
     1565        settings_file.close()
     1566
     1567    def tearDown(self):
     1568        self.remove_settings('settings.py')
     1569
     1570    def test_help(self):
     1571        out, err = self.run_manage(['help'])
     1572        self.assertNoOutput(err)
     1573        self.assertOutput(out, "nons_app_command1")
     1574        self.assertOutput(out, "app1_command1")
     1575        self.assertOutput(out, "app2_command1")
     1576        self.assertOutput(out, "app3_command1")
     1577
     1578    def test_nons_app(self):
     1579        args = ['nons_app_command1']
     1580        out, err = self.run_manage(args)
     1581        self.assertNoOutput(err)
     1582        self.assertOutput(out, "EXECUTE:nons_app_command1")
     1583
     1584    def test_nsapps(self):
     1585        args = ['app1_command1']
     1586        out, err = self.run_manage(args)
     1587        self.assertNoOutput(err)
     1588        self.assertOutput(out, "EXECUTE:app1_command1")
     1589
     1590        args = ['app2_command1']
     1591        out, err = self.run_manage(args)
     1592        self.assertNoOutput(err)
     1593        self.assertOutput(out, "EXECUTE:app2_command1")
     1594
     1595    def test_exapps(self):
     1596        args = ['app3_command1']
     1597        out, err = self.run_manage(args)
     1598        self.assertNoOutput(err)
     1599        self.assertOutput(out, "EXECUTE:app3_command1")
     1600
     1601class PreloadedNamespacePackagedApps(AdminScriptTestCase):
     1602    def setUp(self):
     1603        self.write_settings('settings.py', apps=['nsapps.contrib.app1','nsapps.contrib.app2'])
     1604        test_dir = os.path.dirname(os.path.dirname(__file__))
     1605        settings_file = open(os.path.join(test_dir, 'settings.py'), 'a')
     1606        settings_file.write('import nsapps')
     1607        settings_file.close()
     1608
     1609    def tearDown(self):
     1610        self.remove_settings('settings.py')
     1611
     1612    def test_help(self):
     1613        out, err = self.run_manage(['help'])
     1614        self.assertNoOutput(err)
     1615        self.assertOutput(out, "app1_command1")
     1616        self.assertOutput(out, "app2_command1")
     1617
     1618    def test_nsapps(self):
     1619        args = ['app1_command1']
     1620        out, err = self.run_manage(args)
     1621        self.assertNoOutput(err)
     1622        self.assertOutput(out, "EXECUTE:app1_command1")
     1623
     1624        args = ['app2_command1']
     1625        out, err = self.run_manage(args)
     1626        self.assertNoOutput(err)
     1627        self.assertOutput(out, "EXECUTE:app2_command1")
     1628
     1629
     1630class NonPackageManagementApps(AdminScriptTestCase):
     1631    def setUp(self):
     1632        self.write_settings('settings.py', apps=['npapp'])
     1633        settings_file = open(os.path.join(test_dir, 'settings.py'), 'a')
     1634        settings_file.write('import npapp.management')
     1635        settings_file.close()
     1636
     1637    def tearDown(self):
     1638        self.remove_settings('settings.py')
     1639
     1640    def test_help(self):
     1641        out, err = self.run_manage(['help'])
     1642        self.assertNoOutput(err)
     1643
Back to Top