Skip to content

Commit bd10e92

Browse files
committed
automatically run black on files we update via templates
sometimes filling in a template leads to black changes (when an URL makes a line too long, for example), so lets fix that directly when generating, avoiding a second "black" commit
1 parent 26877f9 commit bd10e92

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

plugin-template

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import os
55
import pprint
66
import shlex
77
import shutil
8+
import subprocess
89
import sys
910
import textwrap
1011
from pathlib import Path
@@ -402,6 +403,14 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
402403
files_copied += 1
403404
if verbose:
404405
print(f"Copied file: {relative_path}")
406+
if config["black"] and destination_relative_path.endswith((".py", ".py.j2")):
407+
if destination_relative_path.endswith(".py.j2"):
408+
destination = destination_relative_path[: -len(".j2")]
409+
else:
410+
destination = destination_relative_path
411+
412+
if os.path.exists(os.path.join(plugin_root_dir, destination)):
413+
subprocess.run(["black", "--quiet", destination], cwd=plugin_root_dir)
405414

406415
print(f"Section: {name} \n templated: {files_templated}\n copied: {files_copied}")
407416
return 0

0 commit comments

Comments
 (0)