All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 from pathlib import Path
5 from subprocess import PIPE, STDOUT, run
7 ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
8 ENV_PATH = ACTION_PATH / ".black-env"
9 ENV_BIN = ENV_PATH / ("Scripts" if sys.platform == "win32" else "bin")
10 OPTIONS = os.getenv("INPUT_OPTIONS", default="")
11 SRC = os.getenv("INPUT_SRC", default="")
12 JUPYTER = os.getenv("INPUT_JUPYTER") == "true"
13 BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
14 VERSION = os.getenv("INPUT_VERSION", default="")
16 run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True)
18 version_specifier = VERSION
19 if VERSION and VERSION[0] in "0123456789":
20 version_specifier = f"=={VERSION}"
22 extra_deps = "[colorama,jupyter]"
24 extra_deps = "[colorama]"
25 req = f"black{extra_deps}{version_specifier}"
27 [str(ENV_BIN / "python"), "-m", "pip", "install", req],
32 if pip_proc.returncode:
33 print(pip_proc.stdout)
34 print("::error::Failed to install Black.", flush=True)
35 sys.exit(pip_proc.returncode)
38 base_cmd = [str(ENV_BIN / "black")]
40 # TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
41 proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
43 proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])
45 sys.exit(proc.returncode)