From 5c2c7277d4554db34c585477b269bb1acfcbbe56 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 18 Oct 2022 10:30:35 -0700 Subject: [PATCH 1/5] Fixed #34085 -- Made management commands don't use black for non-Python files. Bug in d113b5a837f726d1c638d76c4e88445e6cd59fd5. Co-authored-by: programmylife Co-authored-by: Carlton Gibson --- django/core/management/templates.py | 4 +--- docs/releases/4.1.3.txt | 4 +++- .../additional_dir/requirements.in | 5 +++++ tests/admin_scripts/tests.py | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 tests/admin_scripts/custom_templates/project_template/additional_dir/requirements.in diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 71ee0a6ce8..dd83668bca 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -84,7 +84,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 = [] @@ -209,7 +208,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: @@ -232,7 +230,7 @@ class TemplateCommand(BaseCommand): else: shutil.rmtree(path_to_remove) - run_formatters(self.written_files, **formatter_paths) + run_formatters([top_dir], **formatter_paths) 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 0a44e8a538..4149a31e21 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -2483,6 +2483,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) From a16132a9c4b32f9580cdda98a2711ae7261c2576 Mon Sep 17 00:00:00 2001 From: Diane DeMers Chen Date: Thu, 20 Oct 2022 15:52:45 -0700 Subject: [PATCH 2/5] Updated UTC uses to datetime.timezone.utc in docs. --- docs/intro/tutorial02.txt | 2 +- docs/ref/models/database-functions.txt | 4 ++-- docs/ref/signals.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/intro/tutorial02.txt b/docs/intro/tutorial02.txt index ee0707456d..b37d0c036b 100644 --- a/docs/intro/tutorial02.txt +++ b/docs/intro/tutorial02.txt @@ -407,7 +407,7 @@ Once you're in the shell, explore the :doc:`database API `:: >>> q.question_text "What's new?" >>> q.pub_date - datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=) + datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=datetime.timezone.utc) # Change values by changing the attributes, then calling save(). >>> q.question_text = "What's up?" diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index bdbecec2e9..71c98fd73e 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -721,8 +721,8 @@ Usage example:: {'date': datetime.date(2014, 6, 15), 'day': datetime.datetime(2014, 6, 16, 0, 0, tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')), 'hour': datetime.datetime(2014, 6, 16, 0, 0, tzinfo=zoneinfo.ZoneInfo('Australia/Melbourne')), - 'minute': 'minute': datetime.datetime(2014, 6, 15, 14, 30, tzinfo=zoneinfo.ZoneInfo('UTC')), - 'second': datetime.datetime(2014, 6, 15, 14, 30, 50, tzinfo=zoneinfo.ZoneInfo('UTC')) + 'minute': 'minute': datetime.datetime(2014, 6, 15, 14, 30, tzinfo=timezone.utc), + 'second': datetime.datetime(2014, 6, 15, 14, 30, 50, tzinfo=timezone.utc) } ``TimeField`` truncation diff --git a/docs/ref/signals.txt b/docs/ref/signals.txt index 48cc3c2d8f..2fdd215a8f 100644 --- a/docs/ref/signals.txt +++ b/docs/ref/signals.txt @@ -80,7 +80,7 @@ Argument Value arguments passed to ``__init__()``) ``kwargs`` ``{'question_text': "What's new?",`` - ``'pub_date': datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=)}`` + ``'pub_date': datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=datetime.timezone.utc)}`` ========== =============================================================== ``post_init`` From 3e928de8add92a5f38a562abd7560b023d24b6af Mon Sep 17 00:00:00 2001 From: HieuPham9720 <44531309+HieuPham9720@users.noreply.github.com> Date: Thu, 20 Oct 2022 18:50:48 -0700 Subject: [PATCH 3/5] Skipped scrypt tests when OpenSSL 1.1+ is not installed. --- tests/auth_tests/test_hashers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/auth_tests/test_hashers.py b/tests/auth_tests/test_hashers.py index a5dfd51a6b..4d718da46a 100644 --- a/tests/auth_tests/test_hashers.py +++ b/tests/auth_tests/test_hashers.py @@ -41,6 +41,14 @@ try: except ImportError: argon2 = None +# scrypt requires OpenSSL 1.1+ +try: + import hashlib + + scrypt = hashlib.scrypt +except ImportError: + scrypt = None + class PBKDF2SingleIterationHasher(PBKDF2PasswordHasher): iterations = 1 @@ -797,6 +805,7 @@ class TestUtilsHashPassArgon2(SimpleTestCase): setattr(hasher, attr, old_value) +@skipUnless(scrypt, "scrypt not available") @override_settings(PASSWORD_HASHERS=PASSWORD_HASHERS) class TestUtilsHashPassScrypt(SimpleTestCase): def test_scrypt(self): From 38936f6a0cecfdfbfc30009a1f0a725b770f0854 Mon Sep 17 00:00:00 2001 From: Ryan Cheley <9857779+ryancheley@users.noreply.github.com> Date: Fri, 21 Oct 2022 08:02:39 -0700 Subject: [PATCH 4/5] Fixed typo in docs/ref/models/querysets.txt. --- docs/ref/models/querysets.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index 223bb452b0..58d9771cc5 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1659,8 +1659,8 @@ one, doing so will result in an error. have measured that the difference between returning the fields you need and the full set of fields for the model will be significant. - Even if you think you are in the advanced use-case situation, **only use - ``defer()`` when you cannot, at queryset load time, determine if you will + Even if you think you are in the advanced use-case situation, **only use** + ``defer()`` **when you cannot, at queryset load time, determine if you will need the extra fields or not**. If you are frequently loading and using a particular subset of your data, the best choice you can make is to normalize your models and put the non-loaded data into a separate model From 5ec64fa481892747ee5ce7ec13584cc4fe53b857 Mon Sep 17 00:00:00 2001 From: Smile <84652925+SmailBestybay@users.noreply.github.com> Date: Fri, 21 Oct 2022 08:12:12 -0700 Subject: [PATCH 5/5] Corrected curl call in working with Git docs. --- docs/internals/contributing/writing-code/working-with-git.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/internals/contributing/writing-code/working-with-git.txt b/docs/internals/contributing/writing-code/working-with-git.txt index 08bf5b23e7..ab3ab25f26 100644 --- a/docs/internals/contributing/writing-code/working-with-git.txt +++ b/docs/internals/contributing/writing-code/working-with-git.txt @@ -255,7 +255,7 @@ patches. Those patches will typically exist as pull requests on GitHub and can be easily integrated into your local repository:: git checkout -b pull_xxxxx upstream/main - curl https://github.com/django/django/pull/xxxxx.patch | git am + curl -L https://github.com/django/django/pull/xxxxx.patch | git am This will create a new branch and then apply the changes from the pull request to it. At this point you can run the tests or do anything else you need to