-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path__init__.py
More file actions
68 lines (49 loc) · 1.63 KB
/
__init__.py
File metadata and controls
68 lines (49 loc) · 1.63 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""A Python wrapper for the OpenAPI Generator CLI."""
from __future__ import annotations
import importlib.resources
import os
import shutil
import subprocess
import sys
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pathlib import Path
def run(args: list[str] | None = None) -> subprocess.CompletedProcess[bytes]:
"""Run the OpenAPI Generator CLI with the given arguments.
Args:
args (list[str], optional):
The list of arguments to pass to the Open
API Generator CLI. If not provided, the CLI will
be run without any arguments.
Returns:
subprocess.CompletedProcess[bytes]: The result of running the OpenAPI Generator CLI.
"""
java_path: Path | str | None
try:
from jdk4py import JAVA # noqa: PLC0415
java_path = JAVA
except ImportError:
java_path = shutil.which("java")
if not java_path:
msg = "java runtime is not found in PATH"
raise RuntimeError(msg)
arguments = [java_path]
java_opts = os.getenv("JAVA_OPTS")
if java_opts:
arguments.append(java_opts)
arguments.append("-jar")
jar_path = (
importlib.resources.files("openapi_generator_cli") / "openapi-generator.jar"
)
arguments.append(str(jar_path))
if args and isinstance(args, list):
arguments.extend(args)
return subprocess.run(arguments, check=False) # noqa: S603
def cli() -> None:
"""Run the OpenAPI Generator CLI with the arguments provided on the command line."""
args = []
if len(sys.argv) > 1:
args = sys.argv[1:]
run(args)
if __name__ == "__main__":
cli()