summaryrefslogtreecommitdiff
path: root/django/core/management/utils.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/utils.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/utils.py')
-rw-r--r--django/core/management/utils.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/django/core/management/utils.py b/django/core/management/utils.py
index c12d90f6ae..e3e1122409 100644
--- a/django/core/management/utils.py
+++ b/django/core/management/utils.py
@@ -1,5 +1,7 @@
import fnmatch
import os
+import shutil
+import subprocess
from pathlib import Path
from subprocess import run
@@ -153,3 +155,14 @@ def is_ignored_path(path, ignore_patterns):
)
return any(ignore(pattern) for pattern in normalize_path_patterns(ignore_patterns))
+
+
+def run_formatters(written_files):
+ """
+ Run the black formatter on the specified files.
+ """
+ if black_path := shutil.which("black"):
+ subprocess.run(
+ [black_path, "--fast", "--", *written_files],
+ capture_output=True,
+ )