File size: 1,048 Bytes
71687cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""Detect whether this is Windows."""

from __future__ import annotations

from typing import TYPE_CHECKING

from ...base.context import context
from .. import hookimpl
from ..types import CondaVirtualPackage

if TYPE_CHECKING:
    from collections.abc import Iterable


def win_version() -> str | None:
    dist_name, dist_version = context.os_distribution_name_version
    if dist_name != "Windows":
        # dist_version is only valid if we are on Windows
        # this happens with `CONDA_SUBDIR=win-*`/`--platform=win-*` on a non-Windows machine
        dist_version = None
    return dist_version


@hookimpl
def conda_virtual_packages() -> Iterable[CondaVirtualPackage]:
    if not context.subdir.startswith("win-"):
        return

    # 1: __win==VERSION=0
    yield CondaVirtualPackage(
        name="win",
        version=win_version,
        build=None,
        override_entity="version",
        # empty_override=NULL,  # falsy override → skip __win
    )