wandb

Форк
0
/
workspace.py 
71 строка · 1.7 Кб
1
"""Information about the workspace for wini build scripts."""
2

3
import enum
4
import os
5
import platform
6
import subprocess
7

8

9
def git_commit_sha():
10
    """Returns the hash of the current Git commit."""
11
    return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip()
12

13

14
class OS(enum.Enum):
15
    """A possible operating system to build for."""
16

17
    OTHER = 0
18
    LINUX = enum.auto()
19
    DARWIN = enum.auto()
20

21

22
class Arch(enum.Enum):
23
    """A possible architecture to build for."""
24

25
    OTHER = 0
26
    AMD64 = enum.auto()
27
    ARM64 = enum.auto()
28

29

30
def target_osarch() -> (OS, Arch):
31
    """Returns the target platform."""
32
    sys = _parse_current_os()
33

34
    # cibuildwheel builds on an x86_64 Mac when targeting ARM64.
35
    # It sets an undocumented "PLAT" environment variable which we use
36
    # to detect this case (potential improvement: use a command-line argument
37
    # to the build system instead).
38
    if sys == OS.DARWIN and os.getenv("PLAT", "").endswith("arm64"):
39
        arch = Arch.ARM64
40
    else:
41
        arch = _parse_current_arch()
42

43
    return (sys, arch)
44

45

46
def target_os() -> OS:
47
    """Returns the target operating system."""
48
    (os, _) = target_osarch()
49
    return os
50

51

52
def _parse_current_os() -> OS:
53
    """Extracts the current operating system."""
54
    sys = platform.system().lower()
55
    if sys == "linux":
56
        return OS.LINUX
57
    elif sys == "darwin":
58
        return OS.DARWIN
59
    else:
60
        return OS.OTHER
61

62

63
def _parse_current_arch() -> Arch:
64
    """Extracts the current architecture."""
65
    machine = platform.machine().lower()
66
    if machine in ["x86_64", "amd64", "aarch64"]:
67
        return Arch.AMD64
68
    elif machine == "arm64":
69
        return Arch.ARM64
70
    else:
71
        return Arch.OTHER
72

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.