-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathutils.py
52 lines (38 loc) · 1.07 KB
/
utils.py
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
"""Some utils for builder."""
from __future__ import annotations
from functools import cache
import os
from pathlib import Path
import subprocess
import sys
import requests
@cache
def alpine_version() -> tuple[str, str]:
"""Return alpine version for index server."""
version = Path("/etc/alpine-release").read_text(encoding="utf-8").split(".")
return (version[0], version[1])
@cache
def build_arch() -> str:
"""Return build arch for wheels."""
return os.environ["ARCH"]
@cache
def build_abi() -> str:
"""Return build abi for wheels."""
return os.environ["ABI"]
def check_url(url: str) -> None:
"""Check if url is responsible."""
response = requests.get(url, timeout=10)
response.raise_for_status()
def run_command(
cmd: str, env: dict[str, str] | None = None, timeout: int | None = None
) -> None:
"""Implement subprocess.run but handle timeout different."""
subprocess.run(
cmd,
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
env=env,
timeout=timeout,
)