9from typing
import Any, Callable, Dict, List, Optional, Tuple, Union
23from .specifiers
import InvalidSpecifier, Specifier
27 "UndefinedComparison",
28 "UndefinedEnvironmentName",
30 "default_environment",
33Operator = Callable[[str, str], bool]
38 An invalid marker was found, users should refer to PEP 508.
44 An invalid operation was attempted on a value that doesn't support it.
50 A name was attempted to be used that does not exist inside of the
60 return str(self.
value)
63 return f
"<{self.__class__.__name__}('{self}')>"
66 raise NotImplementedError
85 L(
"implementation_version")
86 |
L(
"platform_python_implementation")
87 |
L(
"implementation_name")
88 |
L(
"python_full_version")
89 |
L(
"platform_release")
90 |
L(
"platform_version")
91 |
L(
"platform_machine")
92 |
L(
"platform_system")
98 |
L(
"platform.version")
99 |
L(
"platform.machine")
100 |
L(
"platform.python_implementation")
101 |
L(
"python_implementation")
105 "os.name":
"os_name",
106 "sys.platform":
"sys_platform",
107 "platform.version":
"platform_version",
108 "platform.machine":
"platform_machine",
109 "platform.python_implementation":
"platform_python_implementation",
110 "python_implementation":
"platform_python_implementation",
115 L(
"===") |
L(
"==") |
L(
">=") |
L(
"<=") |
L(
"!=") |
L(
"~=") |
L(
">") |
L(
"<")
118MARKER_OP = VERSION_CMP |
L(
"not in") |
L(
"in")
121MARKER_VALUE = QuotedString(
"'") | QuotedString(
'"')
124BOOLOP =
L(
"and") |
L(
"or")
126MARKER_VAR = VARIABLE | MARKER_VALUE
128MARKER_ITEM = Group(MARKER_VAR + MARKER_OP + MARKER_VAR)
131LPAREN =
L(
"(").suppress()
132RPAREN =
L(
")").suppress()
134MARKER_EXPR = Forward()
135MARKER_ATOM = MARKER_ITEM | Group(LPAREN + MARKER_EXPR + RPAREN)
136MARKER_EXPR << MARKER_ATOM + ZeroOrMore(BOOLOP + MARKER_EXPR)
138MARKER = stringStart + MARKER_EXPR + stringEnd
149 marker: Union[List[str], Tuple[Node, ...], str], first: Optional[bool] =
True
168 return " ".join(inner)
170 return "(" +
" ".join(inner) +
")"
177_operators: Dict[str, Operator] = {
178 "in":
lambda lhs, rhs: lhs
in rhs,
179 "not in":
lambda lhs, rhs: lhs
not in rhs,
192 except InvalidSpecifier:
201 return oper(lhs, rhs)
208_undefined = Undefined()
211def _get_env(environment: Dict[str, str], name: str) -> str:
216 f
"{name!r} does not exist in evaluation environment."
223 groups: List[List[bool]] = [[]]
225 for marker
in markers:
231 lhs, op, rhs = marker
240 groups[-1].append(
_eval_op(lhs_value, op, rhs_value))
242 assert marker
in [
"and",
"or"]
246 return any(all(item)
for item
in groups)
250 version =
"{0.major}.{0.minor}.{0.micro}".format(info)
261 "implementation_name": implementation_name,
262 "implementation_version": iver,
279 except ParseException
as e:
281 f
"Invalid marker: {marker!r}, parse error at "
282 f
"{marker[e.loc : e.loc + 8]!r}"
289 return f
"<Marker('{self}')>"
291 def evaluate(self, environment: Optional[Dict[str, str]] =
None) -> bool:
292 """Evaluate a marker.
294 Return the boolean from evaluating the given marker against the
295 environment. environment is an optional argument to override all or
296 part of the determined environment.
298 The environment is determined from the current Python process.
301 if environment
is not None:
None __init__(self, str marker)
bool evaluate(self, Optional[Dict[str, str]] environment=None)
None __init__(self, Any value)
str _format_marker(Union[List[str], Tuple[Node,...], str] marker, Optional[bool] first=True)
bool _eval_op(str lhs, Op op, str rhs)
bool _evaluate_markers(List[Any] markers, Dict[str, str] environment)
List[Any] _coerce_parse_result(Union[ParseResults, List[Any]] results)
str _get_env(Dict[str, str] environment, str name)
str format_full_version("sys._version_info" info)
Dict[str, str] default_environment()