summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-10-18 10:30:35 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-10-20 14:38:40 -0700
commit84814412a032742e5ccef576b24dbaa0ef25fe06 (patch)
tree14fa14a48a6f59b7dd690d2645fb2d521c3259a0
parent202f5ae96a9ac2e44fac9aee0dd5ed044d323abb (diff)
[4.1.x] Fixed #34085 -- Made management commands don't use black for non-Python files.
Bug in d113b5a837f726d1c638d76c4e88445e6cd59fd5. Co-authored-by: programmylife <acmshar@gmail.com> Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es> Backport of 5c2c7277d4554db34c585477b269bb1acfcbbe56 from main.
-rw-r--r--django/core/management/templates.py4
-rw-r--r--docs/releases/4.1.3.txt4
-rw-r--r--tests/admin_scripts/custom_templates/project_template/additional_dir/requirements.in5
-rw-r--r--tests/admin_scripts/tests.py17
4 files changed, 26 insertions, 4 deletions
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index e06e6a6307..433150e449 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -80,7 +80,6 @@ class TemplateCommand(BaseCommand):
)
def handle(self, app_or_project, name, target=None, **options):
- self.written_files = []
self.app_or_project = app_or_project
self.a_or_an = "an" if app_or_project == "app" else "a"
self.paths_to_remove = []
@@ -201,7 +200,6 @@ class TemplateCommand(BaseCommand):
else:
shutil.copyfile(old_path, new_path)
- self.written_files.append(new_path)
if self.verbosity >= 2:
self.stdout.write("Creating %s" % new_path)
try:
@@ -224,7 +222,7 @@ class TemplateCommand(BaseCommand):
else:
shutil.rmtree(path_to_remove)
- run_formatters(self.written_files)
+ run_formatters([top_dir])
def handle_template(self, template, subdir):
"""
diff --git a/docs/releases/4.1.3.txt b/docs/releases/4.1.3.txt
index e9bc8284cd..f6be8c68df 100644
--- a/docs/releases/4.1.3.txt
+++ b/docs/releases/4.1.3.txt
@@ -9,4 +9,6 @@ Django 4.1.3 fixes several bugs in 4.1.2.
Bugfixes
========
-* ...
+* Fixed a bug in Django 4.1 that caused non-Python files created by
+ ``startproject`` and ``startapp`` management commands from custom templates
+ to be incorrectly formatted using the ``black`` command (:ticket:`34085`).
diff --git a/tests/admin_scripts/custom_templates/project_template/additional_dir/requirements.in b/tests/admin_scripts/custom_templates/project_template/additional_dir/requirements.in
new file mode 100644
index 0000000000..77e66e2c93
--- /dev/null
+++ b/tests/admin_scripts/custom_templates/project_template/additional_dir/requirements.in
@@ -0,0 +1,5 @@
+# Should not be processed by `black`.
+Django<4.2
+environs[django]
+psycopg2-binary
+django-extensions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index 9d2ca839d5..005ccb3312 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -2468,6 +2468,23 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, "additional_dir")))
+ def test_custom_project_template_non_python_files_not_formatted(self):
+ template_path = os.path.join(custom_templates_dir, "project_template")
+ args = ["startproject", "--template", template_path, "customtestproject"]
+ testproject_dir = os.path.join(self.test_dir, "customtestproject")
+
+ _, err = self.run_django_admin(args)
+ self.assertNoOutput(err)
+ with open(
+ os.path.join(template_path, "additional_dir", "requirements.in")
+ ) as f:
+ expected = f.read()
+ with open(
+ os.path.join(testproject_dir, "additional_dir", "requirements.in")
+ ) as f:
+ result = f.read()
+ self.assertEqual(expected, result)
+
def test_template_dir_with_trailing_slash(self):
"Ticket 17475: Template dir passed has a trailing path separator"
template_path = os.path.join(custom_templates_dir, "project_template" + os.sep)