1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
import importlib.util
import subprocess
import sys
from pathlib import Path
def run_python_command(cmd, errmsg=""):
cmd = [sys.executable, "-m"] + cmd
result = subprocess.run(cmd)
if result.returncode != 0:
sys.exit(errmsg)
def install_package():
spec = importlib.util.find_spec("black")
if spec is not None:
return
run_python_command(
["pip", "install", "black"], "Failed to install 'black' package."
)
def format():
recipe_pkg_dir = Path(__file__).parent
run_python_command(["black", recipe_pkg_dir], "Failed to format.")
def main():
install_package()
format()
if __name__ == "__main__":
main()
|