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. --- .../custom_templates/project_template/manage.py | 6 ------ .../custom_templates/project_template/manage.py-tpl | 6 ++++++ tests/admin_scripts/tests.py | 2 +- tests/project_template/test_settings.py | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) 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 (limited to 'tests') 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