summaryrefslogtreecommitdiff
path: root/django/core/management/commands/makemigrations.py
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-02-08 12:38:43 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-02-11 12:23:26 +0100
commitd113b5a837f726d1c638d76c4e88445e6cd59fd5 (patch)
tree37191ed160b698bfbf81559b56735d3e83fd7f92 /django/core/management/commands/makemigrations.py
parentf9ec777a826816e20e68021c0e73b5a76be650af (diff)
Refs #33476 -- Made management commands use black.
Run black on generated files, if it is available on PATH.
Diffstat (limited to 'django/core/management/commands/makemigrations.py')
-rw-r--r--django/core/management/commands/makemigrations.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index 5afa209136..8938fb6309 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -6,6 +6,7 @@ from itertools import takewhile
from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError, no_translations
+from django.core.management.utils import run_formatters
from django.db import DEFAULT_DB_ALIAS, OperationalError, connections, router
from django.db.migrations import Migration
from django.db.migrations.autodetector import MigrationAutodetector
@@ -88,6 +89,7 @@ class Command(BaseCommand):
@no_translations
def handle(self, *app_labels, **options):
+ self.written_files = []
self.verbosity = options["verbosity"]
self.interactive = options["interactive"]
self.dry_run = options["dry_run"]
@@ -276,6 +278,7 @@ class Command(BaseCommand):
migration_string = writer.as_string()
with open(writer.path, "w", encoding="utf-8") as fh:
fh.write(migration_string)
+ self.written_files.append(writer.path)
elif self.verbosity == 3:
# Alternatively, makemigrations --dry-run --verbosity 3
# will log the migrations rather than saving the file to
@@ -286,6 +289,7 @@ class Command(BaseCommand):
)
)
self.log(writer.as_string())
+ run_formatters(self.written_files)
def handle_merge(self, loader, conflicts):
"""
@@ -382,6 +386,7 @@ class Command(BaseCommand):
# Write the merge migrations file to the disk
with open(writer.path, "w", encoding="utf-8") as fh:
fh.write(writer.as_string())
+ run_formatters([writer.path])
if self.verbosity > 0:
self.log("\nCreated new merge migration %s" % writer.path)
if self.scriptable: