]> git.madduck.net Git - etc/vim.git/blob - action/main.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Top PyPI Packages: Use 30-days data, 365 is no longer available (#2995)
[etc/vim.git] / action / main.py
1 import os
2 import shlex
3 import sys
4 from pathlib import Path
5 from subprocess import run, PIPE, STDOUT
6
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 BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
13 VERSION = os.getenv("INPUT_VERSION", default="")
14
15 run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True)
16
17 req = "black[colorama]"
18 if VERSION:
19     req += f"=={VERSION}"
20 pip_proc = run(
21     [str(ENV_BIN / "python"), "-m", "pip", "install", req],
22     stdout=PIPE,
23     stderr=STDOUT,
24     encoding="utf-8",
25 )
26 if pip_proc.returncode:
27     print(pip_proc.stdout)
28     print("::error::Failed to install Black.", flush=True)
29     sys.exit(pip_proc.returncode)
30
31
32 base_cmd = [str(ENV_BIN / "black")]
33 if BLACK_ARGS:
34     # TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
35     proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
36 else:
37     proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])
38
39 sys.exit(proc.returncode)