From abc0777b63057e2ff97eee2ff184356051e14c47 Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Sun, 24 Jan 2016 10:06:01 +0100 Subject: Fixed #25968 -- Changed project/app templates to use a "py-tpl" suffix. Debian packages unconditionally byte-compile .py files on installation and do not silence errors by design. Therefore, we need a way of shipping these invalid .py files without a .py extension but ensuring that when we template them, they end up as .py. We don't special-case .py files so that the all the TemplateCommand command-line options (eg. extra_files and extensions) still work entirely as expected and it may even be useful for other formats too. --- django/conf/app_template/__init__.py | 0 django/conf/app_template/__init__.py-tpl | 0 django/conf/app_template/admin.py | 3 - django/conf/app_template/admin.py-tpl | 3 + django/conf/app_template/apps.py | 5 - django/conf/app_template/apps.py-tpl | 5 + django/conf/app_template/migrations/__init__.py | 0 .../conf/app_template/migrations/__init__.py-tpl | 0 django/conf/app_template/models.py | 3 - django/conf/app_template/models.py-tpl | 3 + django/conf/app_template/tests.py | 3 - django/conf/app_template/tests.py-tpl | 3 + django/conf/app_template/views.py | 3 - django/conf/app_template/views.py-tpl | 3 + django/conf/project_template/manage.py | 10 -- django/conf/project_template/manage.py-tpl | 10 ++ .../conf/project_template/project_name/__init__.py | 0 .../project_template/project_name/__init__.py-tpl | 0 .../conf/project_template/project_name/settings.py | 120 --------------------- .../project_template/project_name/settings.py-tpl | 120 +++++++++++++++++++++ django/conf/project_template/project_name/urls.py | 21 ---- .../conf/project_template/project_name/urls.py-tpl | 21 ++++ django/conf/project_template/project_name/wsgi.py | 16 --- .../conf/project_template/project_name/wsgi.py-tpl | 16 +++ django/core/management/templates.py | 12 ++- docs/ref/django-admin.txt | 9 ++ docs/releases/1.9.2.txt | 19 +++- docs/releases/1.9.txt | 5 +- docs/topics/install.txt | 3 +- .../custom_templates/project_template/manage.py | 6 -- .../project_template/manage.py-tpl | 6 ++ tests/admin_scripts/tests.py | 2 +- tests/project_template/test_settings.py | 15 +++ 33 files changed, 248 insertions(+), 197 deletions(-) delete mode 100644 django/conf/app_template/__init__.py create mode 100644 django/conf/app_template/__init__.py-tpl delete mode 100644 django/conf/app_template/admin.py create mode 100644 django/conf/app_template/admin.py-tpl delete mode 100644 django/conf/app_template/apps.py create mode 100644 django/conf/app_template/apps.py-tpl delete mode 100644 django/conf/app_template/migrations/__init__.py create mode 100644 django/conf/app_template/migrations/__init__.py-tpl delete mode 100644 django/conf/app_template/models.py create mode 100644 django/conf/app_template/models.py-tpl delete mode 100644 django/conf/app_template/tests.py create mode 100644 django/conf/app_template/tests.py-tpl delete mode 100644 django/conf/app_template/views.py create mode 100644 django/conf/app_template/views.py-tpl delete mode 100755 django/conf/project_template/manage.py create mode 100755 django/conf/project_template/manage.py-tpl delete mode 100644 django/conf/project_template/project_name/__init__.py create mode 100644 django/conf/project_template/project_name/__init__.py-tpl delete mode 100644 django/conf/project_template/project_name/settings.py create mode 100644 django/conf/project_template/project_name/settings.py-tpl delete mode 100644 django/conf/project_template/project_name/urls.py create mode 100644 django/conf/project_template/project_name/urls.py-tpl delete mode 100644 django/conf/project_template/project_name/wsgi.py create mode 100644 django/conf/project_template/project_name/wsgi.py-tpl delete mode 100755 tests/admin_scripts/custom_templates/project_template/manage.py create mode 100755 tests/admin_scripts/custom_templates/project_template/manage.py-tpl diff --git a/django/conf/app_template/__init__.py b/django/conf/app_template/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/django/conf/app_template/__init__.py-tpl b/django/conf/app_template/__init__.py-tpl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/conf/app_template/admin.py b/django/conf/app_template/admin.py deleted file mode 100644 index 8c38f3f3da..0000000000 --- a/django/conf/app_template/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/django/conf/app_template/admin.py-tpl b/django/conf/app_template/admin.py-tpl new file mode 100644 index 0000000000..8c38f3f3da --- /dev/null +++ b/django/conf/app_template/admin.py-tpl @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django/conf/app_template/apps.py b/django/conf/app_template/apps.py deleted file mode 100644 index 8d1a017751..0000000000 --- a/django/conf/app_template/apps.py +++ /dev/null @@ -1,5 +0,0 @@ -{{ unicode_literals }}from django.apps import AppConfig - - -class {{ camel_case_app_name }}Config(AppConfig): - name = '{{ app_name }}' diff --git a/django/conf/app_template/apps.py-tpl b/django/conf/app_template/apps.py-tpl new file mode 100644 index 0000000000..8d1a017751 --- /dev/null +++ b/django/conf/app_template/apps.py-tpl @@ -0,0 +1,5 @@ +{{ unicode_literals }}from django.apps import AppConfig + + +class {{ camel_case_app_name }}Config(AppConfig): + name = '{{ app_name }}' diff --git a/django/conf/app_template/migrations/__init__.py b/django/conf/app_template/migrations/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/django/conf/app_template/migrations/__init__.py-tpl b/django/conf/app_template/migrations/__init__.py-tpl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/conf/app_template/models.py b/django/conf/app_template/models.py deleted file mode 100644 index 7a54b3e371..0000000000 --- a/django/conf/app_template/models.py +++ /dev/null @@ -1,3 +0,0 @@ -{{ unicode_literals }}from django.db import models - -# Create your models here. diff --git a/django/conf/app_template/models.py-tpl b/django/conf/app_template/models.py-tpl new file mode 100644 index 0000000000..7a54b3e371 --- /dev/null +++ b/django/conf/app_template/models.py-tpl @@ -0,0 +1,3 @@ +{{ unicode_literals }}from django.db import models + +# Create your models here. diff --git a/django/conf/app_template/tests.py b/django/conf/app_template/tests.py deleted file mode 100644 index 7ce503c2dd..0000000000 --- a/django/conf/app_template/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/django/conf/app_template/tests.py-tpl b/django/conf/app_template/tests.py-tpl new file mode 100644 index 0000000000..7ce503c2dd --- /dev/null +++ b/django/conf/app_template/tests.py-tpl @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django/conf/app_template/views.py b/django/conf/app_template/views.py deleted file mode 100644 index 91ea44a218..0000000000 --- a/django/conf/app_template/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/django/conf/app_template/views.py-tpl b/django/conf/app_template/views.py-tpl new file mode 100644 index 0000000000..91ea44a218 --- /dev/null +++ b/django/conf/app_template/views.py-tpl @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/django/conf/project_template/manage.py b/django/conf/project_template/manage.py deleted file mode 100755 index 391dd88ba4..0000000000 --- a/django/conf/project_template/manage.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") - - from django.core.management import execute_from_command_line - - execute_from_command_line(sys.argv) diff --git a/django/conf/project_template/manage.py-tpl b/django/conf/project_template/manage.py-tpl new file mode 100755 index 0000000000..391dd88ba4 --- /dev/null +++ b/django/conf/project_template/manage.py-tpl @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/django/conf/project_template/project_name/__init__.py b/django/conf/project_template/project_name/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/django/conf/project_template/project_name/__init__.py-tpl b/django/conf/project_template/project_name/__init__.py-tpl new file mode 100644 index 0000000000..e69de29bb2 diff --git a/django/conf/project_template/project_name/settings.py b/django/conf/project_template/project_name/settings.py deleted file mode 100644 index 3ef0ab7900..0000000000 --- a/django/conf/project_template/project_name/settings.py +++ /dev/null @@ -1,120 +0,0 @@ -""" -Django settings for {{ project_name }} project. - -Generated by 'django-admin startproject' using Django {{ django_version }}. - -For more information on this file, see -https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '{{ secret_key }}' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', -] - -MIDDLEWARE_CLASSES = [ - 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = '{{ project_name }}.urls' - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - 'django.template.context_processors.debug', - 'django.template.context_processors.request', - 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - ], - }, - }, -] - -WSGI_APPLICATION = '{{ project_name }}.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - - -# Password validation -# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', - }, - { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', - }, -] - - -# Internationalization -# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/ - -STATIC_URL = '/static/' diff --git a/django/conf/project_template/project_name/settings.py-tpl b/django/conf/project_template/project_name/settings.py-tpl new file mode 100644 index 0000000000..3ef0ab7900 --- /dev/null +++ b/django/conf/project_template/project_name/settings.py-tpl @@ -0,0 +1,120 @@ +""" +Django settings for {{ project_name }} project. + +Generated by 'django-admin startproject' using Django {{ django_version }}. + +For more information on this file, see +https://docs.djangoproject.com/en/{{ docs_version }}/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '{{ secret_key }}' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE_CLASSES = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = '{{ project_name }}.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = '{{ project_name }}.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/{{ docs_version }}/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/django/conf/project_template/project_name/urls.py b/django/conf/project_template/project_name/urls.py deleted file mode 100644 index 30ddffb876..0000000000 --- a/django/conf/project_template/project_name/urls.py +++ /dev/null @@ -1,21 +0,0 @@ -"""{{ project_name }} URL Configuration - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/{{ docs_version }}/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.conf.urls import url, include - 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) -""" -from django.conf.urls import url -from django.contrib import admin - -urlpatterns = [ - url(r'^admin/', admin.site.urls), -] diff --git a/django/conf/project_template/project_name/urls.py-tpl b/django/conf/project_template/project_name/urls.py-tpl new file mode 100644 index 0000000000..30ddffb876 --- /dev/null +++ b/django/conf/project_template/project_name/urls.py-tpl @@ -0,0 +1,21 @@ +"""{{ project_name }} URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/{{ docs_version }}/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/django/conf/project_template/project_name/wsgi.py b/django/conf/project_template/project_name/wsgi.py deleted file mode 100644 index 0d68b95645..0000000000 --- a/django/conf/project_template/project_name/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for {{ project_name }} project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") - -application = get_wsgi_application() diff --git a/django/conf/project_template/project_name/wsgi.py-tpl b/django/conf/project_template/project_name/wsgi.py-tpl new file mode 100644 index 0000000000..0d68b95645 --- /dev/null +++ b/django/conf/project_template/project_name/wsgi.py-tpl @@ -0,0 +1,16 @@ +""" +WSGI config for {{ project_name }} project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/{{ docs_version }}/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") + +application = get_wsgi_application() diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 7c147a5231..1cd06d101a 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -42,6 +42,11 @@ class TemplateCommand(BaseCommand): # Can't perform any active locale changes during this command, because # setting might not be available at all. leave_locale_alone = True + # Rewrite the following suffixes when determining the target filename. + rewrite_template_suffixes = ( + # Allow shipping invalid .py files without byte-compilation. + ('.py-tpl', '.py'), + ) def add_arguments(self, parser): parser.add_argument('name', help='Name of the application or project.') @@ -139,6 +144,11 @@ class TemplateCommand(BaseCommand): old_path = path.join(root, filename) new_path = path.join(top_dir, relative_dir, filename.replace(base_name, name)) + for old_suffix, new_suffix in self.rewrite_template_suffixes: + if new_path.endswith(old_suffix): + new_path = new_path[:-len(old_suffix)] + new_suffix + break # Only rewrite once + if path.exists(new_path): raise CommandError("%s already exists, overlaying a " "project or app into an existing " @@ -149,7 +159,7 @@ class TemplateCommand(BaseCommand): # accidentally render Django templates files with open(old_path, 'rb') as template_file: content = template_file.read() - if filename.endswith(extensions) or filename in extra_files: + if new_path.endswith(extensions) or filename in extra_files: content = content.decode('utf-8') template = Engine().from_string(content) content = template.render(context) diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index a0d9e54296..5bc31ea112 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -1175,6 +1175,15 @@ files is: To work around this problem, you can use the :ttag:`templatetag` templatetag to "escape" the various parts of the template syntax. + In addition, to allow Python template files that contain Django template + language syntax while also preventing packaging systems from trying to + byte-compile invalid ``*.py`` files, template files ending with ``.py-tpl`` + will be renamed to ``.py``. + + .. versionchanged:: 1.9.2 + + Renaming of ``.py-tpl`` to ``.py`` was added. + .. _source: https://github.com/django/django/tree/master/django/conf/app_template/ startproject diff --git a/docs/releases/1.9.2.txt b/docs/releases/1.9.2.txt index f977b02ac3..e64c62e3da 100644 --- a/docs/releases/1.9.2.txt +++ b/docs/releases/1.9.2.txt @@ -4,7 +4,24 @@ Django 1.9.2 release notes *Under development* -Django 1.9.2 fixes several bugs in 1.9.1. +Django 1.9.2 fixes several bugs in 1.9.1 and makes a small backwards +incompatible change that hopefully doesn't affect any users. + +Backwards incompatible change: ``.py-tpl`` files rewritten in project/app templates +=================================================================================== + +The addition of some Django template language syntax to the default app +template in Django 1.9 means those files now have some invalid Python syntax. +This causes difficulties for packaging systems that unconditionally +byte-compile ``*.py`` files. + +To remedy this, a ``.py-tpl`` suffix is now used for the project and app +template files included in Django. The ``.py-tpl`` suffix is replaced with +``.py`` by the ``startproject`` and ``startapp`` commands. For example, a +template with the filename ``manage.py-tpl`` will be created as ``manage.py``. + +Please file a ticket if you have a custom project template containing +``.py-tpl`` files and find this behavior problematic. Bugfixes ======== diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt index dc43dce873..0c67558d69 100644 --- a/docs/releases/1.9.txt +++ b/docs/releases/1.9.txt @@ -1017,7 +1017,7 @@ a Django application with this structure:: ``SyntaxError`` when installing Django setuptools 5.5.x ------------------------------------------------------- -When installing Django 1.9+ with setuptools 5.5.x, you'll see:: +When installing Django 1.9 or 1.9.1 with setuptools 5.5.x, you'll see:: Compiling django/conf/app_template/apps.py ... File "django/conf/app_template/apps.py", line 4 @@ -1034,7 +1034,8 @@ When installing Django 1.9+ with setuptools 5.5.x, you'll see:: It's safe to ignore these errors (Django will still install just fine), but you can avoid them by upgrading setuptools to a more recent version. If you're using pip, you can upgrade pip using ``pip install -U pip`` which will also -upgrade setuptools. +upgrade setuptools. This is resolved in later versions of Django as described +in the :doc:`/releases/1.9.2`. Miscellaneous ------------- diff --git a/docs/topics/install.txt b/docs/topics/install.txt index f0fbc47881..b5195bea57 100644 --- a/docs/topics/install.txt +++ b/docs/topics/install.txt @@ -165,8 +165,7 @@ This is the recommended way to install Django. 1. Install pip_. The easiest is to use the `standalone pip installer`_. If your distribution already has ``pip`` installed, you might need to update it if it's outdated. If it's outdated, you'll know because installation won't - work. If you're using an old version of setuptools, you might see some - :ref:`harmless SyntaxErrors ` also. + work. 2. Take a look at virtualenv_ and virtualenvwrapper_. These tools provide isolated Python environments, which are more practical than installing diff --git a/tests/admin_scripts/custom_templates/project_template/manage.py b/tests/admin_scripts/custom_templates/project_template/manage.py deleted file mode 100755 index d9843c433f..0000000000 --- a/tests/admin_scripts/custom_templates/project_template/manage.py +++ /dev/null @@ -1,6 +0,0 @@ -# The manage.py of the {{ project_name }} test project - -# template context: -project_name = '{{ project_name }}' -project_directory = '{{ project_directory }}' -secret_key = '{{ secret_key }}' diff --git a/tests/admin_scripts/custom_templates/project_template/manage.py-tpl b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl new file mode 100755 index 0000000000..d9843c433f --- /dev/null +++ b/tests/admin_scripts/custom_templates/project_template/manage.py-tpl @@ -0,0 +1,6 @@ +# The manage.py of the {{ project_name }} test project + +# template context: +project_name = '{{ project_name }}' +project_directory = '{{ project_directory }}' +secret_key = '{{ secret_key }}' diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 805be8b144..60c3a68fd2 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -181,7 +181,7 @@ class AdminScriptTestCase(unittest.TestCase): pass conf_dir = os.path.dirname(upath(conf.__file__)) - template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py') + template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py-tpl') test_manage_py = os.path.join(self.test_dir, 'manage.py') shutil.copyfile(template_manage_py, test_manage_py) diff --git a/tests/project_template/test_settings.py b/tests/project_template/test_settings.py index ac115f7dc2..25a95717a9 100644 --- a/tests/project_template/test_settings.py +++ b/tests/project_template/test_settings.py @@ -1,13 +1,28 @@ +import os +import shutil import unittest +from django import conf from django.test import TestCase from django.utils import six +from django.utils._os import upath @unittest.skipIf(six.PY2, 'Python 2 cannot import the project template because ' 'django/conf/project_template doesn\'t have an __init__.py file.') class TestStartProjectSettings(TestCase): + def setUp(self): + # Ensure settings.py exists + project_dir = os.path.join( + os.path.dirname(upath(conf.__file__)), + 'project_template', + 'project_name', + ) + template_settings_py = os.path.join(project_dir, 'settings.py-tpl') + test_settings_py = os.path.join(project_dir, 'settings.py') + shutil.copyfile(template_settings_py, test_settings_py) + self.addCleanup(os.remove, test_settings_py) def test_middleware_classes_headers(self): """ -- cgit v1.3