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]"
26 req = f"black{extra_deps}{version_specifier}"
29 with open(ACTION_PATH / ".git_archival.txt", encoding="utf-8") as fp:
31 if line.startswith("describe-name: "):
32 describe_name = line[len("describe-name: ") :].rstrip()
35 print("::error::Failed to detect action version.", flush=True)
37 # expected format is one of:
39 # - 23.1.0-51-g448bba7
40 if describe_name.count("-") < 2:
41 # the action's commit matches a tag exactly, install exact version from PyPI
42 req = f"black{extra_deps}=={describe_name}"
44 # the action's commit does not match any tag, install from the local git repo
45 req = f".{extra_deps}"
46 print(f"Installing {req}...", flush=True)
48 [str(ENV_BIN / "python"), "-m", "pip", "install", req],
54 if pip_proc.returncode:
55 print(pip_proc.stdout)
56 print("::error::Failed to install Black.", flush=True)
57 sys.exit(pip_proc.returncode)
60 base_cmd = [str(ENV_BIN / "black")]
62 # TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
63 proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
65 proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])
67 sys.exit(proc.returncode)