Ticket #10966: project_module_optional.2.patch

File project_module_optional.2.patch, 1.4 KB (added by chad@…, 15 years ago)

Patch to make importing of top-level project conditional on presence of init.py (w/o set_trace call :-) )

  • django/core/management/__init__.py

     
    331331    if settings_name.endswith("$py"):
    332332        settings_name = settings_name[:-3]
    333333
     334    # Decide whether to treat the project directory as a Python package.
     335    project_is_package = '__init__.py' in os.listdir(project_directory)
     336
    334337    # Set DJANGO_SETTINGS_MODULE appropriately.
    335338    if original_settings_path:
    336         os.environ['DJANGO_SETTINGS_MODULE'] = original_settings_path
     339        envvar = original_settings_path
     340    elif project_is_package:
     341        envvar = '%s.%s' % (project_name, settings_name)
    337342    else:
    338         os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
     343        envvar = settings_name
     344    os.environ['DJANGO_SETTINGS_MODULE'] = envvar
    339345
    340346    # Import the project module. We add the parent directory to PYTHONPATH to
    341347    # avoid some of the path errors new users can have.
    342     sys.path.append(os.path.join(project_directory, os.pardir))
    343     project_module = import_module(project_name)
    344     sys.path.pop()
     348    if project_is_package:
     349        sys.path.append(os.path.join(project_directory, os.pardir))
     350        project_module = import_module(project_name)
     351        sys.path.pop()
    345352
    346353    return project_directory
    347354
Back to Top