-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathutils.py
More file actions
59 lines (51 loc) · 1.94 KB
/
utils.py
File metadata and controls
59 lines (51 loc) · 1.94 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
import tempfile
import sys
import subprocess
from loguru import logger
from pathlib import Path
def ensure_java():
java_version = None
try:
fp = tempfile.TemporaryDirectory()
fpath = Path(fp.name) / "A.java"
fpath.write_bytes(
b'public class A{ public static void main(String[] a) { System.out.println(System.getProperty("java.version")); }}' # noqa: E501
)
result = subprocess.run(
["java", str(fpath)], capture_output=True, text=True, check=True
) # java 11+
java_version = result.stdout.strip()
fp.cleanup()
except (FileNotFoundError, subprocess.CalledProcessError):
logger.error(
"Java not found or outdated!"
" Please make sure JDK 25 is installed and available in your system PATH."
)
sys.exit(1)
major = 0
if java_version is not None:
major = java_version.split(".")[0]
major = int(major) if major.isdigit() else 0
if major < 25:
logger.error("JDK 25 or newer is required!", java_version)
sys.exit(1)
logger.info("Java check success: {}", java_version)
def ensure_git():
try:
_ = subprocess.run(["git", "--version"], capture_output=True, text=True, check=True)
logger.info("Git check success: {}", _.stdout.strip())
except (FileNotFoundError, subprocess.CalledProcessError):
logger.error(
"Git not found! Please make sure Git is installed and available in your system PATH."
)
sys.exit(1)
def ensure_jar():
try:
_ = subprocess.run(["jar", "--version"], capture_output=True, text=True, check=True)
logger.info("Jar utility check success: {}", _.stdout.strip())
except (FileNotFoundError, subprocess.CalledProcessError):
logger.error(
"Please make sure JDK is properly installed "
"and the corresponding bin folder is on PATH."
)
sys.exit(1)