File size: 4,884 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | # Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
"""Collection of enums used throughout conda."""
import sys
from enum import Enum
from platform import machine
from ..auxlib.decorators import classproperty
from ..auxlib.ish import dals
from ..auxlib.type_coercion import TypeCoercionError, boolify
from ..deprecations import deprecated
from ..exceptions import CondaUpgradeError
class Arch(Enum):
x86 = "x86"
x86_64 = "x86_64"
# arm64 is for macOS and Windows
arm64 = "arm64"
armv6l = "armv6l"
armv7l = "armv7l"
# aarch64 is for Linux only
aarch64 = "aarch64"
ppc64 = "ppc64"
ppc64le = "ppc64le"
riscv64 = "riscv64"
s390x = "s390x"
wasm32 = "wasm32"
z = "z"
@classmethod
def from_sys(cls):
if sys.platform == "zos":
return cls["z"]
return cls[machine()]
def __json__(self):
return self.value
class Platform(Enum):
freebsd = "freebsd"
linux = "linux"
win = "win32"
openbsd = "openbsd5"
osx = "darwin"
zos = "zos"
emscripten = "emscripten"
wasi = "wasi"
@classmethod
def from_sys(cls):
return cls(sys.platform)
def __json__(self):
return self.value
class FileMode(Enum):
text = "text"
binary = "binary"
def __str__(self):
return f"{self.value}"
class LinkType(Enum):
# directory is not a link type, and copy is not a path type
# LinkType is still probably the best name here
hardlink = 1
softlink = 2
copy = 3
directory = 4
def __int__(self):
return self.value
def __str__(self):
return self.name
def __json__(self):
return self.name
class PathEnum(Enum):
"""
Refers to if the file in question is hard linked or soft linked. Originally designed to be used
in paths.json
"""
hardlink = "hardlink"
softlink = "softlink"
directory = "directory"
# these additional types should not be included by conda-build in packages
linked_package_record = (
"linked_package_record" # a package's .json file in conda-meta
)
pyc_file = "pyc_file"
unix_python_entry_point = "unix_python_entry_point"
windows_python_entry_point_script = "windows_python_entry_point_script"
windows_python_entry_point_exe = "windows_python_entry_point_exe"
@classproperty
def basic_types(self):
return (PathEnum.hardlink, PathEnum.softlink, PathEnum.directory)
def __str__(self):
return self.name
def __json__(self):
return self.name
deprecated.constant(
deprecate_in="26.9",
remove_in="27.3",
constant="PathType",
value=PathEnum,
addendum="Use `conda.models.enums.PathEnum` instead.",
)
class PackageType(Enum):
NOARCH_GENERIC = "noarch_generic"
NOARCH_PYTHON = "noarch_python"
VIRTUAL_PRIVATE_ENV = "virtual_private_env"
VIRTUAL_PYTHON_WHEEL = "virtual_python_wheel" # manageable
VIRTUAL_PYTHON_EGG_MANAGEABLE = "virtual_python_egg_manageable"
VIRTUAL_PYTHON_EGG_UNMANAGEABLE = "virtual_python_egg_unmanageable"
VIRTUAL_PYTHON_EGG_LINK = "virtual_python_egg_link" # unmanageable
VIRTUAL_SYSTEM = "virtual_system" # virtual packages representing system attributes
@staticmethod
def conda_package_types():
return {
None,
PackageType.NOARCH_GENERIC,
PackageType.NOARCH_PYTHON,
}
@staticmethod
def unmanageable_package_types():
return {
PackageType.VIRTUAL_PYTHON_EGG_UNMANAGEABLE,
PackageType.VIRTUAL_PYTHON_EGG_LINK,
PackageType.VIRTUAL_SYSTEM,
}
class NoarchType(Enum):
generic = "generic"
python = "python"
@staticmethod
def coerce(val):
# what a mess
if isinstance(val, NoarchType):
return val
valtype = getattr(val, "type", None)
if isinstance(valtype, NoarchType): # see issue #8311
return valtype
if isinstance(val, bool):
val = NoarchType.generic if val else None
if isinstance(val, str):
val = val.lower()
if val == "python":
val = NoarchType.python
elif val == "generic":
val = NoarchType.generic
else:
try:
val = NoarchType.generic if boolify(val, nullable=True) else None
except TypeCoercionError:
raise CondaUpgradeError(
dals(
f"""
The noarch type for this package is set to '{val}'.
The current version of conda is too old to install this package.
Please update conda.
"""
)
)
return val
|