File: format.py

package info (click to toggle)
nvidia-cuda-toolkit 12.4.1-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 18,505,836 kB
  • sloc: ansic: 203,477; cpp: 64,769; python: 34,699; javascript: 22,006; xml: 13,410; makefile: 3,085; sh: 2,343; perl: 352
file content (37 lines) | stat: -rw-r--r-- 682 bytes parent folder | download | duplicates (6)
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()