diff --git a/plugin-template b/plugin-template index 72eb310b..623f0d5a 100755 --- a/plugin-template +++ b/plugin-template @@ -5,6 +5,7 @@ import os import pprint import shlex import shutil +import subprocess import sys import textwrap from pathlib import Path @@ -357,7 +358,8 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): **config, } - for relative_path in generate_relative_path_set(section_template_dir): + relative_path_set = generate_relative_path_set(section_template_dir) + for relative_path in relative_path_set: if not config["stalebot"] and "stale" in relative_path: continue if config["use_issue_template"] is False and "ISSUE_TEMPLATE" in relative_path: @@ -403,6 +405,17 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): if verbose: print(f"Copied file: {relative_path}") + if config["black"]: + black_paths = filter(lambda x: x.endswith(".py.j2"), relative_path_set) + black_paths = map(lambda x: x[: -len(".j2")], black_paths) + black_paths = map( + lambda x: x.replace("plugin_name", utils.to_snake(config["plugin_name"])), black_paths + ) + black_paths = filter( + lambda x: os.path.exists(os.path.join(plugin_root_dir, x)), black_paths + ) + subprocess.run(["black", "--quiet"] + list(black_paths), cwd=plugin_root_dir) + print(f"Section: {name} \n templated: {files_templated}\n copied: {files_copied}") return 0