Exemple #1
0
def translate_host_platform(
    platform_constraint: PlatformConstraint,
    binary_util: BinaryUtil,
) -> HostPlatform:
    # This method attempts to provide a uname function to BinaryUtil.host_platform() so that the
    # download urls can be calculated. For platforms that are different than the current host, we try
    # to "spoof" the most appropriate value.
    if Platform.current == Platform.darwin:
        darwin_uname: Any = os.uname
        linux_uname: Any = lambda: ("linux", None, None, None, "x86_64")
    else:
        assert Platform.current == Platform.linux
        darwin_uname = lambda: (
            "darwin",
            None,
            get_closest_mac_host_platform_pair(),
            None,
            "x86_64",
        )
        linux_uname = os.uname

    return cast(
        HostPlatform,
        match(
            platform_constraint,
            {
                PlatformConstraint.none:
                lambda: HostPlatform.empty,
                PlatformConstraint.darwin:
                lambda: binary_util.host_platform(uname=darwin_uname()),
                PlatformConstraint.linux:
                lambda: binary_util.host_platform(uname=linux_uname()),
            },
        )(),
    )