omdev 0.0.0.dev36__py3-none-any.whl → 0.0.0.dev37__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of omdev might be problematic. Click here for more details.
- omdev/.manifests.json +1 -1
- omdev/amalg/amalg.py +3 -1
- omdev/interp/inspect.py +1 -1
- omdev/interp/pyenv.py +2 -2
- omdev/interp/system.py +1 -1
- omdev/interp/types.py +3 -3
- omdev/packaging/names.py +44 -0
- omdev/packaging/requires.py +484 -0
- omdev/scripts/interp.py +9 -4
- omdev/scripts/pyproject.py +1175 -1170
- omdev/tools/piptools.py +34 -0
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/RECORD +20 -18
- /omdev/{versioning → packaging}/__init__.py +0 -0
- /omdev/{versioning → packaging}/specifiers.py +0 -0
- /omdev/{versioning → packaging}/versions.py +0 -0
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev36.dist-info → omdev-0.0.0.dev37.dist-info}/top_level.txt +0 -0
omdev/.manifests.json
CHANGED
omdev/amalg/amalg.py
CHANGED
|
@@ -205,6 +205,7 @@ def make_import(
|
|
|
205
205
|
|
|
206
206
|
|
|
207
207
|
TYPE_ALIAS_COMMENT = '# ta.TypeAlias'
|
|
208
|
+
NOQA_TYPE_ALIAS_COMMENT = TYPE_ALIAS_COMMENT + ' # noqa'
|
|
208
209
|
|
|
209
210
|
|
|
210
211
|
@dc.dataclass(frozen=True, kw_only=True)
|
|
@@ -218,7 +219,8 @@ class Typing:
|
|
|
218
219
|
|
|
219
220
|
|
|
220
221
|
def _is_typing(lts: Tokens) -> bool:
|
|
221
|
-
|
|
222
|
+
es = tks.join_toks(lts).strip()
|
|
223
|
+
if any(es.endswith(sfx) for sfx in (TYPE_ALIAS_COMMENT, NOQA_TYPE_ALIAS_COMMENT)):
|
|
222
224
|
return True
|
|
223
225
|
|
|
224
226
|
wts = list(tks.ignore_ws(lts))
|
omdev/interp/inspect.py
CHANGED
|
@@ -8,7 +8,7 @@ import typing as ta
|
|
|
8
8
|
from omlish.lite.logs import log
|
|
9
9
|
from omlish.lite.subprocesses import subprocess_check_output
|
|
10
10
|
|
|
11
|
-
from ..
|
|
11
|
+
from ..packaging.versions import Version
|
|
12
12
|
from .types import InterpOpts
|
|
13
13
|
from .types import InterpVersion
|
|
14
14
|
|
omdev/interp/pyenv.py
CHANGED
|
@@ -25,8 +25,8 @@ from omlish.lite.subprocesses import subprocess_check_call
|
|
|
25
25
|
from omlish.lite.subprocesses import subprocess_check_output_str
|
|
26
26
|
from omlish.lite.subprocesses import subprocess_try_output
|
|
27
27
|
|
|
28
|
-
from ..
|
|
29
|
-
from ..
|
|
28
|
+
from ..packaging.versions import InvalidVersion
|
|
29
|
+
from ..packaging.versions import Version
|
|
30
30
|
from .inspect import INTERP_INSPECTOR
|
|
31
31
|
from .inspect import InterpInspector
|
|
32
32
|
from .providers import InterpProvider
|
omdev/interp/system.py
CHANGED
|
@@ -12,7 +12,7 @@ import typing as ta
|
|
|
12
12
|
from omlish.lite.cached import cached_nullary
|
|
13
13
|
from omlish.lite.logs import log
|
|
14
14
|
|
|
15
|
-
from ..
|
|
15
|
+
from ..packaging.versions import InvalidVersion
|
|
16
16
|
from .inspect import INTERP_INSPECTOR
|
|
17
17
|
from .inspect import InterpInspector
|
|
18
18
|
from .providers import InterpProvider
|
omdev/interp/types.py
CHANGED
|
@@ -3,9 +3,9 @@ import collections
|
|
|
3
3
|
import dataclasses as dc
|
|
4
4
|
import typing as ta
|
|
5
5
|
|
|
6
|
-
from ..
|
|
7
|
-
from ..
|
|
8
|
-
from ..
|
|
6
|
+
from ..packaging.specifiers import Specifier
|
|
7
|
+
from ..packaging.versions import InvalidVersion
|
|
8
|
+
from ..packaging.versions import Version
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
# See https://peps.python.org/pep-3149/
|
omdev/packaging/names.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) Donald Stufft and individual contributors.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
5
|
+
# following conditions are met:
|
|
6
|
+
#
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
|
8
|
+
# following disclaimer.
|
|
9
|
+
#
|
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
|
11
|
+
# following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
12
|
+
#
|
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
14
|
+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
15
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
16
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
17
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
18
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This file is dual licensed under the terms of the
|
|
20
|
+
# Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
|
|
21
|
+
# details.
|
|
22
|
+
# https://github.com/pypa/packaging/blob/cf2cbe2aec28f87c6228a6fb136c27931c9af407/src/packaging/utils.py
|
|
23
|
+
import re
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Core metadata spec for `Name`
|
|
27
|
+
_CANONICAL_NAME_VALIDATE_PATTERN = re.compile(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', re.IGNORECASE)
|
|
28
|
+
_CANONICAL_NAME_CANONICALIZE_PATTERN = re.compile(r'[-_.]+')
|
|
29
|
+
_CANONICAL_NAME_NORMALIZED_PATTERN = re.compile(r'^([a-z0-9]|[a-z0-9]([a-z0-9-](?!--))*[a-z0-9])$')
|
|
30
|
+
|
|
31
|
+
# PEP 427: The build number must start with a digit.
|
|
32
|
+
_CANONICAL_NAME_BUILD_TAG_PATTERN = re.compile(r'(\d+)(.*)')
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def canonicalize_name(name: str, *, validate: bool = False) -> str:
|
|
36
|
+
if validate and not _CANONICAL_NAME_VALIDATE_PATTERN.match(name):
|
|
37
|
+
raise NameError(f'name is invalid: {name!r}')
|
|
38
|
+
# This is taken from PEP 503.
|
|
39
|
+
value = _CANONICAL_NAME_CANONICALIZE_PATTERN.sub('-', name).lower()
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_normalized_name(name: str) -> bool:
|
|
44
|
+
return _CANONICAL_NAME_NORMALIZED_PATTERN.match(name) is not None
|
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
# Copyright (c) Donald Stufft and individual contributors.
|
|
2
|
+
# All rights reserved.
|
|
3
|
+
#
|
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
5
|
+
# following conditions are met:
|
|
6
|
+
#
|
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
|
8
|
+
# following disclaimer.
|
|
9
|
+
#
|
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
|
|
11
|
+
# following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
12
|
+
#
|
|
13
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
14
|
+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
15
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
16
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
17
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
18
|
+
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This file is dual licensed under the terms of the
|
|
20
|
+
# Apache License, Version 2.0, and the BSD License. See the LICENSE file in the root of this repository for complete
|
|
21
|
+
# details.
|
|
22
|
+
# https://github.com/pypa/packaging/blob/cf2cbe2aec28f87c6228a6fb136c27931c9af407/src/packaging/_parser.py#L65
|
|
23
|
+
# ruff: noqa: UP006 UP007
|
|
24
|
+
import ast
|
|
25
|
+
import contextlib
|
|
26
|
+
import dataclasses as dc
|
|
27
|
+
import re
|
|
28
|
+
import typing as ta
|
|
29
|
+
|
|
30
|
+
from omlish.lite.check import check_not_none
|
|
31
|
+
from omlish.lite.check import check_state
|
|
32
|
+
|
|
33
|
+
from .specifiers import Specifier
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dc.dataclass()
|
|
37
|
+
class RequiresToken:
|
|
38
|
+
name: str
|
|
39
|
+
text: str
|
|
40
|
+
position: int
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class RequiresParserSyntaxError(Exception):
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
message: str,
|
|
47
|
+
*,
|
|
48
|
+
source: str,
|
|
49
|
+
span: ta.Tuple[int, int],
|
|
50
|
+
) -> None:
|
|
51
|
+
self.span = span
|
|
52
|
+
self.message = message
|
|
53
|
+
self.source = source
|
|
54
|
+
|
|
55
|
+
super().__init__()
|
|
56
|
+
|
|
57
|
+
def __str__(self) -> str:
|
|
58
|
+
marker = ' ' * self.span[0] + '~' * (self.span[1] - self.span[0]) + '^'
|
|
59
|
+
return '\n '.join([self.message, self.source, marker])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
REQUIRES_DEFAULT_RULES: ta.Dict[str, ta.Union[str, ta.Pattern[str]]] = {
|
|
63
|
+
'LEFT_PARENTHESIS': r'\(',
|
|
64
|
+
'RIGHT_PARENTHESIS': r'\)',
|
|
65
|
+
'LEFT_BRACKET': r'\[',
|
|
66
|
+
'RIGHT_BRACKET': r'\]',
|
|
67
|
+
'SEMICOLON': r';',
|
|
68
|
+
'COMMA': r',',
|
|
69
|
+
'QUOTED_STRING': re.compile(
|
|
70
|
+
r"""
|
|
71
|
+
(
|
|
72
|
+
('[^']*')
|
|
73
|
+
|
|
|
74
|
+
("[^"]*")
|
|
75
|
+
)
|
|
76
|
+
""",
|
|
77
|
+
re.VERBOSE,
|
|
78
|
+
),
|
|
79
|
+
'OP': r'(===|==|~=|!=|<=|>=|<|>)',
|
|
80
|
+
'BOOLOP': r'\b(or|and)\b',
|
|
81
|
+
'IN': r'\bin\b',
|
|
82
|
+
'NOT': r'\bnot\b',
|
|
83
|
+
'VARIABLE': re.compile(
|
|
84
|
+
r"""
|
|
85
|
+
\b(
|
|
86
|
+
python_version
|
|
87
|
+
|python_full_version
|
|
88
|
+
|os[._]name
|
|
89
|
+
|sys[._]platform
|
|
90
|
+
|platform_(release|system)
|
|
91
|
+
|platform[._](version|machine|python_implementation)
|
|
92
|
+
|python_implementation
|
|
93
|
+
|implementation_(name|version)
|
|
94
|
+
|extra
|
|
95
|
+
)\b
|
|
96
|
+
""",
|
|
97
|
+
re.VERBOSE,
|
|
98
|
+
),
|
|
99
|
+
'SPECIFIER': re.compile(
|
|
100
|
+
Specifier._operator_regex_str + Specifier._version_regex_str, # noqa
|
|
101
|
+
re.VERBOSE | re.IGNORECASE,
|
|
102
|
+
),
|
|
103
|
+
'AT': r'\@',
|
|
104
|
+
'URL': r'[^ \t]+',
|
|
105
|
+
'IDENTIFIER': r'\b[a-zA-Z0-9][a-zA-Z0-9._-]*\b',
|
|
106
|
+
'VERSION_PREFIX_TRAIL': r'\.\*',
|
|
107
|
+
'VERSION_LOCAL_LABEL_TRAIL': r'\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*',
|
|
108
|
+
'WS': r'[ \t]+',
|
|
109
|
+
'END': r'$',
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class RequiresTokenizer:
|
|
114
|
+
|
|
115
|
+
def __init__(
|
|
116
|
+
self,
|
|
117
|
+
source: str,
|
|
118
|
+
*,
|
|
119
|
+
rules: ta.Dict[str, ta.Union[str, ta.Pattern[str]]],
|
|
120
|
+
) -> None:
|
|
121
|
+
super().__init__()
|
|
122
|
+
self.source = source
|
|
123
|
+
self.rules: ta.Dict[str, ta.Pattern[str]] = {name: re.compile(pattern) for name, pattern in rules.items()}
|
|
124
|
+
self.next_token: ta.Optional[RequiresToken] = None
|
|
125
|
+
self.position = 0
|
|
126
|
+
|
|
127
|
+
def consume(self, name: str) -> None:
|
|
128
|
+
if self.check(name):
|
|
129
|
+
self.read()
|
|
130
|
+
|
|
131
|
+
def check(self, name: str, *, peek: bool = False) -> bool:
|
|
132
|
+
check_state(self.next_token is None, f'Cannot check for {name!r}, already have {self.next_token!r}')
|
|
133
|
+
check_state(name in self.rules, f'Unknown token name: {name!r}')
|
|
134
|
+
|
|
135
|
+
expression = self.rules[name]
|
|
136
|
+
|
|
137
|
+
match = expression.match(self.source, self.position)
|
|
138
|
+
if match is None:
|
|
139
|
+
return False
|
|
140
|
+
if not peek:
|
|
141
|
+
self.next_token = RequiresToken(name, match[0], self.position)
|
|
142
|
+
return True
|
|
143
|
+
|
|
144
|
+
def expect(self, name: str, *, expected: str) -> RequiresToken:
|
|
145
|
+
if not self.check(name):
|
|
146
|
+
raise self.raise_syntax_error(f'Expected {expected}')
|
|
147
|
+
return self.read()
|
|
148
|
+
|
|
149
|
+
def read(self) -> RequiresToken:
|
|
150
|
+
token = self.next_token
|
|
151
|
+
check_state(token is not None)
|
|
152
|
+
|
|
153
|
+
self.position += len(check_not_none(token).text)
|
|
154
|
+
self.next_token = None
|
|
155
|
+
|
|
156
|
+
return check_not_none(token)
|
|
157
|
+
|
|
158
|
+
def raise_syntax_error(
|
|
159
|
+
self,
|
|
160
|
+
message: str,
|
|
161
|
+
*,
|
|
162
|
+
span_start: ta.Optional[int] = None,
|
|
163
|
+
span_end: ta.Optional[int] = None,
|
|
164
|
+
) -> ta.NoReturn:
|
|
165
|
+
span = (
|
|
166
|
+
self.position if span_start is None else span_start,
|
|
167
|
+
self.position if span_end is None else span_end,
|
|
168
|
+
)
|
|
169
|
+
raise RequiresParserSyntaxError(
|
|
170
|
+
message,
|
|
171
|
+
source=self.source,
|
|
172
|
+
span=span,
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
@contextlib.contextmanager
|
|
176
|
+
def enclosing_tokens(self, open_token: str, close_token: str, *, around: str) -> ta.Iterator[None]:
|
|
177
|
+
if self.check(open_token):
|
|
178
|
+
open_position = self.position
|
|
179
|
+
self.read()
|
|
180
|
+
else:
|
|
181
|
+
open_position = None
|
|
182
|
+
|
|
183
|
+
yield
|
|
184
|
+
|
|
185
|
+
if open_position is None:
|
|
186
|
+
return
|
|
187
|
+
|
|
188
|
+
if not self.check(close_token):
|
|
189
|
+
self.raise_syntax_error(
|
|
190
|
+
f'Expected matching {close_token} for {open_token}, after {around}',
|
|
191
|
+
span_start=open_position,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
self.read()
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
class RequiresNode:
|
|
198
|
+
def __init__(self, value: str) -> None:
|
|
199
|
+
super().__init__()
|
|
200
|
+
self.value = value
|
|
201
|
+
|
|
202
|
+
def __str__(self) -> str:
|
|
203
|
+
return self.value
|
|
204
|
+
|
|
205
|
+
def __repr__(self) -> str:
|
|
206
|
+
return f"<{self.__class__.__name__}('{self}')>"
|
|
207
|
+
|
|
208
|
+
def serialize(self) -> str:
|
|
209
|
+
raise NotImplementedError
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class RequiresVariable(RequiresNode):
|
|
213
|
+
def serialize(self) -> str:
|
|
214
|
+
return str(self)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class RequiresValue(RequiresNode):
|
|
218
|
+
def serialize(self) -> str:
|
|
219
|
+
return f'"{self}"'
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class RequiresOp(RequiresNode):
|
|
223
|
+
def serialize(self) -> str:
|
|
224
|
+
return str(self)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
RequiresMarkerVar = ta.Union['RequiresVariable', 'RequiresValue']
|
|
228
|
+
RequiresMarkerItem = ta.Tuple['RequiresMarkerVar', 'RequiresOp', 'RequiresMarkerVar']
|
|
229
|
+
RequiresMarkerAtom = ta.Union['RequiresMarkerItem', ta.Sequence['RequiresMarkerAtom']]
|
|
230
|
+
RequiresMarkerList = ta.Sequence[ta.Union['RequiresMarkerList', 'RequiresMarkerAtom', str]]
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
class ParsedRequirement(ta.NamedTuple):
|
|
234
|
+
name: str
|
|
235
|
+
url: str
|
|
236
|
+
extras: ta.List[str]
|
|
237
|
+
specifier: str
|
|
238
|
+
marker: ta.Optional[RequiresMarkerList]
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def parse_requirement(source: str) -> ParsedRequirement:
|
|
242
|
+
return _parse_requirement(RequiresTokenizer(source, rules=REQUIRES_DEFAULT_RULES))
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def _parse_requirement(tokenizer: RequiresTokenizer) -> ParsedRequirement:
|
|
246
|
+
tokenizer.consume('WS')
|
|
247
|
+
|
|
248
|
+
name_token = tokenizer.expect('IDENTIFIER', expected='package name at the start of dependency specifier')
|
|
249
|
+
name = name_token.text
|
|
250
|
+
tokenizer.consume('WS')
|
|
251
|
+
|
|
252
|
+
extras = _parse_requires_extras(tokenizer)
|
|
253
|
+
tokenizer.consume('WS')
|
|
254
|
+
|
|
255
|
+
url, specifier, marker = _parse_requirement_details(tokenizer)
|
|
256
|
+
tokenizer.expect('END', expected='end of dependency specifier')
|
|
257
|
+
|
|
258
|
+
return ParsedRequirement(name, url, extras, specifier, marker)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _parse_requirement_details(tokenizer: RequiresTokenizer) -> ta.Tuple[str, str, ta.Optional[RequiresMarkerList]]:
|
|
262
|
+
specifier = ''
|
|
263
|
+
url = ''
|
|
264
|
+
marker = None
|
|
265
|
+
|
|
266
|
+
if tokenizer.check('AT'):
|
|
267
|
+
tokenizer.read()
|
|
268
|
+
tokenizer.consume('WS')
|
|
269
|
+
|
|
270
|
+
url_start = tokenizer.position
|
|
271
|
+
url = tokenizer.expect('URL', expected='URL after @').text
|
|
272
|
+
if tokenizer.check('END', peek=True):
|
|
273
|
+
return (url, specifier, marker)
|
|
274
|
+
|
|
275
|
+
tokenizer.expect('WS', expected='whitespace after URL')
|
|
276
|
+
|
|
277
|
+
# The input might end after whitespace.
|
|
278
|
+
if tokenizer.check('END', peek=True):
|
|
279
|
+
return (url, specifier, marker)
|
|
280
|
+
|
|
281
|
+
marker = _parse_requirement_marker(
|
|
282
|
+
tokenizer, span_start=url_start, after='URL and whitespace',
|
|
283
|
+
)
|
|
284
|
+
else:
|
|
285
|
+
specifier_start = tokenizer.position
|
|
286
|
+
specifier = _parse_requires_specifier(tokenizer)
|
|
287
|
+
tokenizer.consume('WS')
|
|
288
|
+
|
|
289
|
+
if tokenizer.check('END', peek=True):
|
|
290
|
+
return (url, specifier, marker)
|
|
291
|
+
|
|
292
|
+
marker = _parse_requirement_marker(
|
|
293
|
+
tokenizer,
|
|
294
|
+
span_start=specifier_start,
|
|
295
|
+
after=(
|
|
296
|
+
'version specifier'
|
|
297
|
+
if specifier
|
|
298
|
+
else 'name and no valid version specifier'
|
|
299
|
+
),
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
return (url, specifier, marker)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _parse_requirement_marker(
|
|
306
|
+
tokenizer: RequiresTokenizer, *, span_start: int, after: str,
|
|
307
|
+
) -> RequiresMarkerList:
|
|
308
|
+
if not tokenizer.check('SEMICOLON'):
|
|
309
|
+
tokenizer.raise_syntax_error(
|
|
310
|
+
f'Expected end or semicolon (after {after})',
|
|
311
|
+
span_start=span_start,
|
|
312
|
+
)
|
|
313
|
+
tokenizer.read()
|
|
314
|
+
|
|
315
|
+
marker = _parse_requires_marker(tokenizer)
|
|
316
|
+
tokenizer.consume('WS')
|
|
317
|
+
|
|
318
|
+
return marker
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def _parse_requires_extras(tokenizer: RequiresTokenizer) -> ta.List[str]:
|
|
322
|
+
if not tokenizer.check('LEFT_BRACKET', peek=True):
|
|
323
|
+
return []
|
|
324
|
+
|
|
325
|
+
with tokenizer.enclosing_tokens(
|
|
326
|
+
'LEFT_BRACKET',
|
|
327
|
+
'RIGHT_BRACKET',
|
|
328
|
+
around='extras',
|
|
329
|
+
):
|
|
330
|
+
tokenizer.consume('WS')
|
|
331
|
+
extras = _parse_requires_extras_list(tokenizer)
|
|
332
|
+
tokenizer.consume('WS')
|
|
333
|
+
|
|
334
|
+
return extras
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _parse_requires_extras_list(tokenizer: RequiresTokenizer) -> ta.List[str]:
|
|
338
|
+
extras: ta.List[str] = []
|
|
339
|
+
|
|
340
|
+
if not tokenizer.check('IDENTIFIER'):
|
|
341
|
+
return extras
|
|
342
|
+
|
|
343
|
+
extras.append(tokenizer.read().text)
|
|
344
|
+
|
|
345
|
+
while True:
|
|
346
|
+
tokenizer.consume('WS')
|
|
347
|
+
if tokenizer.check('IDENTIFIER', peek=True):
|
|
348
|
+
tokenizer.raise_syntax_error('Expected comma between extra names')
|
|
349
|
+
elif not tokenizer.check('COMMA'):
|
|
350
|
+
break
|
|
351
|
+
|
|
352
|
+
tokenizer.read()
|
|
353
|
+
tokenizer.consume('WS')
|
|
354
|
+
|
|
355
|
+
extra_token = tokenizer.expect('IDENTIFIER', expected='extra name after comma')
|
|
356
|
+
extras.append(extra_token.text)
|
|
357
|
+
|
|
358
|
+
return extras
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _parse_requires_specifier(tokenizer: RequiresTokenizer) -> str:
|
|
362
|
+
with tokenizer.enclosing_tokens(
|
|
363
|
+
'LEFT_PARENTHESIS',
|
|
364
|
+
'RIGHT_PARENTHESIS',
|
|
365
|
+
around='version specifier',
|
|
366
|
+
):
|
|
367
|
+
tokenizer.consume('WS')
|
|
368
|
+
parsed_specifiers = _parse_requires_version_many(tokenizer)
|
|
369
|
+
tokenizer.consume('WS')
|
|
370
|
+
|
|
371
|
+
return parsed_specifiers
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _parse_requires_version_many(tokenizer: RequiresTokenizer) -> str:
|
|
375
|
+
parsed_specifiers = ''
|
|
376
|
+
while tokenizer.check('SPECIFIER'):
|
|
377
|
+
span_start = tokenizer.position
|
|
378
|
+
parsed_specifiers += tokenizer.read().text
|
|
379
|
+
if tokenizer.check('VERSION_PREFIX_TRAIL', peek=True):
|
|
380
|
+
tokenizer.raise_syntax_error(
|
|
381
|
+
'.* suffix can only be used with `==` or `!=` operators',
|
|
382
|
+
span_start=span_start,
|
|
383
|
+
span_end=tokenizer.position + 1,
|
|
384
|
+
)
|
|
385
|
+
if tokenizer.check('VERSION_LOCAL_LABEL_TRAIL', peek=True):
|
|
386
|
+
tokenizer.raise_syntax_error(
|
|
387
|
+
'Local version label can only be used with `==` or `!=` operators',
|
|
388
|
+
span_start=span_start,
|
|
389
|
+
span_end=tokenizer.position,
|
|
390
|
+
)
|
|
391
|
+
tokenizer.consume('WS')
|
|
392
|
+
if not tokenizer.check('COMMA'):
|
|
393
|
+
break
|
|
394
|
+
parsed_specifiers += tokenizer.read().text
|
|
395
|
+
tokenizer.consume('WS')
|
|
396
|
+
|
|
397
|
+
return parsed_specifiers
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def parse_requires_marker(source: str) -> RequiresMarkerList:
|
|
401
|
+
return _parse_requires_full_marker(RequiresTokenizer(source, rules=REQUIRES_DEFAULT_RULES))
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _parse_requires_full_marker(tokenizer: RequiresTokenizer) -> RequiresMarkerList:
|
|
405
|
+
retval = _parse_requires_marker(tokenizer)
|
|
406
|
+
tokenizer.expect('END', expected='end of marker expression')
|
|
407
|
+
return retval
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _parse_requires_marker(tokenizer: RequiresTokenizer) -> RequiresMarkerList:
|
|
411
|
+
expression = [_parse_requires_marker_atom(tokenizer)]
|
|
412
|
+
while tokenizer.check('BOOLOP'):
|
|
413
|
+
token = tokenizer.read()
|
|
414
|
+
expr_right = _parse_requires_marker_atom(tokenizer)
|
|
415
|
+
expression.extend((token.text, expr_right))
|
|
416
|
+
return expression
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def _parse_requires_marker_atom(tokenizer: RequiresTokenizer) -> RequiresMarkerAtom:
|
|
420
|
+
tokenizer.consume('WS')
|
|
421
|
+
if tokenizer.check('LEFT_PARENTHESIS', peek=True):
|
|
422
|
+
with tokenizer.enclosing_tokens(
|
|
423
|
+
'LEFT_PARENTHESIS',
|
|
424
|
+
'RIGHT_PARENTHESIS',
|
|
425
|
+
around='marker expression',
|
|
426
|
+
):
|
|
427
|
+
tokenizer.consume('WS')
|
|
428
|
+
marker: RequiresMarkerAtom = _parse_requires_marker(tokenizer)
|
|
429
|
+
tokenizer.consume('WS')
|
|
430
|
+
else:
|
|
431
|
+
marker = _parse_requires_marker_item(tokenizer)
|
|
432
|
+
tokenizer.consume('WS')
|
|
433
|
+
return marker
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _parse_requires_marker_item(tokenizer: RequiresTokenizer) -> RequiresMarkerItem:
|
|
437
|
+
tokenizer.consume('WS')
|
|
438
|
+
marker_var_left = _parse_requires_marker_var(tokenizer)
|
|
439
|
+
tokenizer.consume('WS')
|
|
440
|
+
marker_op = _parse_requires_marker_op(tokenizer)
|
|
441
|
+
tokenizer.consume('WS')
|
|
442
|
+
marker_var_right = _parse_requires_marker_var(tokenizer)
|
|
443
|
+
tokenizer.consume('WS')
|
|
444
|
+
return (marker_var_left, marker_op, marker_var_right)
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def _parse_requires_marker_var(tokenizer: RequiresTokenizer) -> RequiresMarkerVar:
|
|
448
|
+
if tokenizer.check('VARIABLE'):
|
|
449
|
+
return process_requires_env_var(tokenizer.read().text.replace('.', '_'))
|
|
450
|
+
elif tokenizer.check('QUOTED_STRING'):
|
|
451
|
+
return process_requires_python_str(tokenizer.read().text)
|
|
452
|
+
else:
|
|
453
|
+
tokenizer.raise_syntax_error(message='Expected a marker variable or quoted string')
|
|
454
|
+
raise RuntimeError # noqa
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def process_requires_env_var(env_var: str) -> RequiresVariable:
|
|
458
|
+
if env_var in ('platform_python_implementation', 'python_implementation'):
|
|
459
|
+
return RequiresVariable('platform_python_implementation')
|
|
460
|
+
else:
|
|
461
|
+
return RequiresVariable(env_var)
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
def process_requires_python_str(python_str: str) -> RequiresValue:
|
|
465
|
+
value = ast.literal_eval(python_str)
|
|
466
|
+
return RequiresValue(str(value))
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def _parse_requires_marker_op(tokenizer: RequiresTokenizer) -> RequiresOp:
|
|
470
|
+
if tokenizer.check('IN'):
|
|
471
|
+
tokenizer.read()
|
|
472
|
+
return RequiresOp('in')
|
|
473
|
+
elif tokenizer.check('NOT'):
|
|
474
|
+
tokenizer.read()
|
|
475
|
+
tokenizer.expect('WS', expected="whitespace after 'not'")
|
|
476
|
+
tokenizer.expect('IN', expected="'in' after 'not'")
|
|
477
|
+
return RequiresOp('not in')
|
|
478
|
+
elif tokenizer.check('OP'):
|
|
479
|
+
return RequiresOp(tokenizer.read().text)
|
|
480
|
+
else:
|
|
481
|
+
return tokenizer.raise_syntax_error(
|
|
482
|
+
'Expected marker operator, one of '
|
|
483
|
+
'<=, <, !=, ==, >=, >, ~=, ===, in, not in',
|
|
484
|
+
)
|
omdev/scripts/interp.py
CHANGED
|
@@ -43,7 +43,7 @@ if sys.version_info < (3, 8):
|
|
|
43
43
|
########################################
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
# ../../
|
|
46
|
+
# ../../packaging/versions.py
|
|
47
47
|
VersionLocalType = ta.Tuple[ta.Union[int, str], ...]
|
|
48
48
|
VersionCmpPrePostDevType = ta.Union['InfinityVersionType', 'NegativeInfinityVersionType', ta.Tuple[str, int]]
|
|
49
49
|
_VersionCmpLocalType0 = ta.Tuple[ta.Union[ta.Tuple[int, str], ta.Tuple['NegativeInfinityVersionType', ta.Union[int, str]]], ...] # noqa
|
|
@@ -54,14 +54,14 @@ VersionComparisonMethod = ta.Callable[[VersionCmpKey, VersionCmpKey], bool]
|
|
|
54
54
|
# ../../../omlish/lite/check.py
|
|
55
55
|
T = ta.TypeVar('T')
|
|
56
56
|
|
|
57
|
-
# ../../
|
|
57
|
+
# ../../packaging/specifiers.py
|
|
58
58
|
UnparsedVersion = ta.Union['Version', str]
|
|
59
59
|
UnparsedVersionVar = ta.TypeVar('UnparsedVersionVar', bound=UnparsedVersion)
|
|
60
60
|
CallableVersionOperator = ta.Callable[['Version', str], bool]
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
########################################
|
|
64
|
-
# ../../
|
|
64
|
+
# ../../packaging/versions.py
|
|
65
65
|
# Copyright (c) Donald Stufft and individual contributors.
|
|
66
66
|
# All rights reserved.
|
|
67
67
|
#
|
|
@@ -522,6 +522,11 @@ def check_non_empty_str(v: ta.Optional[str]) -> str:
|
|
|
522
522
|
return v
|
|
523
523
|
|
|
524
524
|
|
|
525
|
+
def check_state(v: bool, msg: str = 'Illegal state') -> None:
|
|
526
|
+
if not v:
|
|
527
|
+
raise ValueError(msg)
|
|
528
|
+
|
|
529
|
+
|
|
525
530
|
########################################
|
|
526
531
|
# ../../../omlish/lite/json.py
|
|
527
532
|
|
|
@@ -632,7 +637,7 @@ def is_sunder(name: str) -> bool:
|
|
|
632
637
|
|
|
633
638
|
|
|
634
639
|
########################################
|
|
635
|
-
# ../../
|
|
640
|
+
# ../../packaging/specifiers.py
|
|
636
641
|
# Copyright (c) Donald Stufft and individual contributors.
|
|
637
642
|
# All rights reserved.
|
|
638
643
|
#
|