omdev 0.0.0.dev149__py3-none-any.whl → 0.0.0.dev151__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.
- omdev/amalg/amalg.py +1 -1
- omdev/git.py +2 -2
- omdev/imgur.py +1 -1
- omdev/interp/cli.py +2 -2
- omdev/interp/pyenv.py +5 -5
- omdev/interp/standalone.py +2 -2
- omdev/packaging/requires.py +6 -7
- omdev/pyproject/cli.py +7 -8
- omdev/revisions.py +2 -2
- omdev/scripts/interp.py +432 -77
- omdev/scripts/pyproject.py +445 -90
- omdev/tools/docker.py +1 -1
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/RECORD +18 -18
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev149.dist-info → omdev-0.0.0.dev151.dist-info}/top_level.txt +0 -0
omdev/scripts/pyproject.py
CHANGED
|
@@ -101,6 +101,11 @@ CallableT = ta.TypeVar('CallableT', bound=ta.Callable)
|
|
|
101
101
|
|
|
102
102
|
# ../../omlish/lite/check.py
|
|
103
103
|
SizedT = ta.TypeVar('SizedT', bound=ta.Sized)
|
|
104
|
+
CheckMessage = ta.Union[str, ta.Callable[..., ta.Optional[str]], None] # ta.TypeAlias
|
|
105
|
+
CheckLateConfigureFn = ta.Callable[['Checks'], None] # ta.TypeAlias
|
|
106
|
+
CheckOnRaiseFn = ta.Callable[[Exception], None] # ta.TypeAlias
|
|
107
|
+
CheckExceptionFactory = ta.Callable[..., Exception] # ta.TypeAlias
|
|
108
|
+
CheckArgsRenderer = ta.Callable[..., ta.Optional[str]] # ta.TypeAlias
|
|
104
109
|
|
|
105
110
|
# ../packaging/specifiers.py
|
|
106
111
|
UnparsedVersion = ta.Union['Version', str]
|
|
@@ -1888,104 +1893,454 @@ def async_cached_nullary(fn): # ta.Callable[..., T]) -> ta.Callable[..., T]:
|
|
|
1888
1893
|
|
|
1889
1894
|
########################################
|
|
1890
1895
|
# ../../../omlish/lite/check.py
|
|
1896
|
+
"""
|
|
1897
|
+
TODO:
|
|
1898
|
+
- def maybe(v: lang.Maybe[T])
|
|
1899
|
+
- patch / override lite.check ?
|
|
1900
|
+
- checker interface?
|
|
1901
|
+
"""
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
##
|
|
1905
|
+
|
|
1906
|
+
|
|
1907
|
+
class Checks:
|
|
1908
|
+
def __init__(self) -> None:
|
|
1909
|
+
super().__init__()
|
|
1910
|
+
|
|
1911
|
+
self._config_lock = threading.RLock()
|
|
1912
|
+
self._on_raise_fns: ta.Sequence[CheckOnRaiseFn] = []
|
|
1913
|
+
self._exception_factory: CheckExceptionFactory = Checks.default_exception_factory
|
|
1914
|
+
self._args_renderer: ta.Optional[CheckArgsRenderer] = None
|
|
1915
|
+
self._late_configure_fns: ta.Sequence[CheckLateConfigureFn] = []
|
|
1916
|
+
|
|
1917
|
+
@staticmethod
|
|
1918
|
+
def default_exception_factory(exc_cls: ta.Type[Exception], *args, **kwargs) -> Exception:
|
|
1919
|
+
return exc_cls(*args, **kwargs) # noqa
|
|
1920
|
+
|
|
1921
|
+
#
|
|
1922
|
+
|
|
1923
|
+
def register_on_raise(self, fn: CheckOnRaiseFn) -> None:
|
|
1924
|
+
with self._config_lock:
|
|
1925
|
+
self._on_raise_fns = [*self._on_raise_fns, fn]
|
|
1926
|
+
|
|
1927
|
+
def unregister_on_raise(self, fn: CheckOnRaiseFn) -> None:
|
|
1928
|
+
with self._config_lock:
|
|
1929
|
+
self._on_raise_fns = [e for e in self._on_raise_fns if e != fn]
|
|
1930
|
+
|
|
1931
|
+
#
|
|
1932
|
+
|
|
1933
|
+
def set_exception_factory(self, factory: CheckExceptionFactory) -> None:
|
|
1934
|
+
self._exception_factory = factory
|
|
1935
|
+
|
|
1936
|
+
def set_args_renderer(self, renderer: ta.Optional[CheckArgsRenderer]) -> None:
|
|
1937
|
+
self._args_renderer = renderer
|
|
1938
|
+
|
|
1939
|
+
#
|
|
1940
|
+
|
|
1941
|
+
def register_late_configure(self, fn: CheckLateConfigureFn) -> None:
|
|
1942
|
+
with self._config_lock:
|
|
1943
|
+
self._late_configure_fns = [*self._late_configure_fns, fn]
|
|
1944
|
+
|
|
1945
|
+
def _late_configure(self) -> None:
|
|
1946
|
+
if not self._late_configure_fns:
|
|
1947
|
+
return
|
|
1891
1948
|
|
|
1949
|
+
with self._config_lock:
|
|
1950
|
+
if not (lc := self._late_configure_fns):
|
|
1951
|
+
return
|
|
1892
1952
|
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
raise TypeError(v)
|
|
1896
|
-
return v
|
|
1953
|
+
for fn in lc:
|
|
1954
|
+
fn(self)
|
|
1897
1955
|
|
|
1956
|
+
self._late_configure_fns = []
|
|
1898
1957
|
|
|
1899
|
-
|
|
1900
|
-
if isinstance(v, spec):
|
|
1901
|
-
raise TypeError(v)
|
|
1902
|
-
return v
|
|
1958
|
+
#
|
|
1903
1959
|
|
|
1960
|
+
class _ArgsKwargs:
|
|
1961
|
+
def __init__(self, *args, **kwargs):
|
|
1962
|
+
self.args = args
|
|
1963
|
+
self.kwargs = kwargs
|
|
1904
1964
|
|
|
1905
|
-
def
|
|
1906
|
-
|
|
1907
|
-
|
|
1965
|
+
def _raise(
|
|
1966
|
+
self,
|
|
1967
|
+
exception_type: ta.Type[Exception],
|
|
1968
|
+
default_message: str,
|
|
1969
|
+
message: CheckMessage,
|
|
1970
|
+
ak: _ArgsKwargs = _ArgsKwargs(),
|
|
1971
|
+
*,
|
|
1972
|
+
render_fmt: ta.Optional[str] = None,
|
|
1973
|
+
) -> ta.NoReturn:
|
|
1974
|
+
exc_args = ()
|
|
1975
|
+
if callable(message):
|
|
1976
|
+
message = ta.cast(ta.Callable, message)(*ak.args, **ak.kwargs)
|
|
1977
|
+
if isinstance(message, tuple):
|
|
1978
|
+
message, *exc_args = message # type: ignore
|
|
1979
|
+
|
|
1980
|
+
if message is None:
|
|
1981
|
+
message = default_message
|
|
1982
|
+
|
|
1983
|
+
self._late_configure()
|
|
1984
|
+
|
|
1985
|
+
if render_fmt is not None and (af := self._args_renderer) is not None:
|
|
1986
|
+
rendered_args = af(render_fmt, *ak.args)
|
|
1987
|
+
if rendered_args is not None:
|
|
1988
|
+
message = f'{message} : {rendered_args}'
|
|
1989
|
+
|
|
1990
|
+
exc = self._exception_factory(
|
|
1991
|
+
exception_type,
|
|
1992
|
+
message,
|
|
1993
|
+
*exc_args,
|
|
1994
|
+
*ak.args,
|
|
1995
|
+
**ak.kwargs,
|
|
1996
|
+
)
|
|
1908
1997
|
|
|
1998
|
+
for fn in self._on_raise_fns:
|
|
1999
|
+
fn(exc)
|
|
1909
2000
|
|
|
1910
|
-
|
|
1911
|
-
if v is None:
|
|
1912
|
-
raise ValueError
|
|
1913
|
-
return v
|
|
2001
|
+
raise exc
|
|
1914
2002
|
|
|
2003
|
+
#
|
|
1915
2004
|
|
|
1916
|
-
def
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
2005
|
+
def _unpack_isinstance_spec(self, spec: ta.Any) -> tuple:
|
|
2006
|
+
if isinstance(spec, type):
|
|
2007
|
+
return (spec,)
|
|
2008
|
+
if not isinstance(spec, tuple):
|
|
2009
|
+
spec = (spec,)
|
|
2010
|
+
if None in spec:
|
|
2011
|
+
spec = tuple(filter(None, spec)) + (None.__class__,) # noqa
|
|
2012
|
+
if ta.Any in spec:
|
|
2013
|
+
spec = (object,)
|
|
2014
|
+
return spec
|
|
2015
|
+
|
|
2016
|
+
def isinstance(self, v: ta.Any, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> T: # noqa
|
|
2017
|
+
if not isinstance(v, self._unpack_isinstance_spec(spec)):
|
|
2018
|
+
self._raise(
|
|
2019
|
+
TypeError,
|
|
2020
|
+
'Must be instance',
|
|
2021
|
+
msg,
|
|
2022
|
+
Checks._ArgsKwargs(v, spec),
|
|
2023
|
+
render_fmt='not isinstance(%s, %s)',
|
|
2024
|
+
)
|
|
1920
2025
|
|
|
2026
|
+
return v
|
|
1921
2027
|
|
|
1922
|
-
def
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
return v
|
|
2028
|
+
def of_isinstance(self, spec: ta.Union[ta.Type[T], tuple], msg: CheckMessage = None) -> ta.Callable[[ta.Any], T]:
|
|
2029
|
+
def inner(v):
|
|
2030
|
+
return self.isinstance(v, self._unpack_isinstance_spec(spec), msg)
|
|
1926
2031
|
|
|
2032
|
+
return inner
|
|
1927
2033
|
|
|
1928
|
-
def
|
|
1929
|
-
|
|
1930
|
-
|
|
2034
|
+
def cast(self, v: ta.Any, cls: ta.Type[T], msg: CheckMessage = None) -> T: # noqa
|
|
2035
|
+
if not isinstance(v, cls):
|
|
2036
|
+
self._raise(
|
|
2037
|
+
TypeError,
|
|
2038
|
+
'Must be instance',
|
|
2039
|
+
msg,
|
|
2040
|
+
Checks._ArgsKwargs(v, cls),
|
|
2041
|
+
)
|
|
1931
2042
|
|
|
2043
|
+
return v
|
|
1932
2044
|
|
|
1933
|
-
def
|
|
1934
|
-
|
|
1935
|
-
|
|
2045
|
+
def of_cast(self, cls: ta.Type[T], msg: CheckMessage = None) -> ta.Callable[[T], T]:
|
|
2046
|
+
def inner(v):
|
|
2047
|
+
return self.cast(v, cls, msg)
|
|
1936
2048
|
|
|
2049
|
+
return inner
|
|
1937
2050
|
|
|
1938
|
-
def
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2051
|
+
def not_isinstance(self, v: T, spec: ta.Any, msg: CheckMessage = None) -> T: # noqa
|
|
2052
|
+
if isinstance(v, self._unpack_isinstance_spec(spec)):
|
|
2053
|
+
self._raise(
|
|
2054
|
+
TypeError,
|
|
2055
|
+
'Must not be instance',
|
|
2056
|
+
msg,
|
|
2057
|
+
Checks._ArgsKwargs(v, spec),
|
|
2058
|
+
render_fmt='isinstance(%s, %s)',
|
|
2059
|
+
)
|
|
1942
2060
|
|
|
2061
|
+
return v
|
|
1943
2062
|
|
|
1944
|
-
def
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
return l
|
|
2063
|
+
def of_not_isinstance(self, spec: ta.Any, msg: CheckMessage = None) -> ta.Callable[[T], T]:
|
|
2064
|
+
def inner(v):
|
|
2065
|
+
return self.not_isinstance(v, self._unpack_isinstance_spec(spec), msg)
|
|
1948
2066
|
|
|
2067
|
+
return inner
|
|
1949
2068
|
|
|
1950
|
-
|
|
1951
|
-
if l is not r:
|
|
1952
|
-
raise ValueError(l, r)
|
|
1953
|
-
return l
|
|
2069
|
+
##
|
|
1954
2070
|
|
|
2071
|
+
def issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
|
|
2072
|
+
if not issubclass(v, spec):
|
|
2073
|
+
self._raise(
|
|
2074
|
+
TypeError,
|
|
2075
|
+
'Must be subclass',
|
|
2076
|
+
msg,
|
|
2077
|
+
Checks._ArgsKwargs(v, spec),
|
|
2078
|
+
render_fmt='not issubclass(%s, %s)',
|
|
2079
|
+
)
|
|
1955
2080
|
|
|
1956
|
-
|
|
1957
|
-
if l is r:
|
|
1958
|
-
raise ValueError(l, r)
|
|
1959
|
-
return l
|
|
2081
|
+
return v
|
|
1960
2082
|
|
|
2083
|
+
def not_issubclass(self, v: ta.Type[T], spec: ta.Any, msg: CheckMessage = None) -> ta.Type[T]: # noqa
|
|
2084
|
+
if issubclass(v, spec):
|
|
2085
|
+
self._raise(
|
|
2086
|
+
TypeError,
|
|
2087
|
+
'Must not be subclass',
|
|
2088
|
+
msg,
|
|
2089
|
+
Checks._ArgsKwargs(v, spec),
|
|
2090
|
+
render_fmt='issubclass(%s, %s)',
|
|
2091
|
+
)
|
|
1961
2092
|
|
|
1962
|
-
|
|
1963
|
-
if v not in c:
|
|
1964
|
-
raise ValueError(v, c)
|
|
1965
|
-
return v
|
|
2093
|
+
return v
|
|
1966
2094
|
|
|
2095
|
+
#
|
|
1967
2096
|
|
|
1968
|
-
def
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
2097
|
+
def in_(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
|
|
2098
|
+
if v not in c:
|
|
2099
|
+
self._raise(
|
|
2100
|
+
ValueError,
|
|
2101
|
+
'Must be in',
|
|
2102
|
+
msg,
|
|
2103
|
+
Checks._ArgsKwargs(v, c),
|
|
2104
|
+
render_fmt='%s not in %s',
|
|
2105
|
+
)
|
|
1972
2106
|
|
|
2107
|
+
return v
|
|
1973
2108
|
|
|
1974
|
-
def
|
|
1975
|
-
|
|
1976
|
-
|
|
2109
|
+
def not_in(self, v: T, c: ta.Container[T], msg: CheckMessage = None) -> T:
|
|
2110
|
+
if v in c:
|
|
2111
|
+
self._raise(
|
|
2112
|
+
ValueError,
|
|
2113
|
+
'Must not be in',
|
|
2114
|
+
msg,
|
|
2115
|
+
Checks._ArgsKwargs(v, c),
|
|
2116
|
+
render_fmt='%s in %s',
|
|
2117
|
+
)
|
|
2118
|
+
|
|
2119
|
+
return v
|
|
2120
|
+
|
|
2121
|
+
def empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
|
|
2122
|
+
if len(v) != 0:
|
|
2123
|
+
self._raise(
|
|
2124
|
+
ValueError,
|
|
2125
|
+
'Must be empty',
|
|
2126
|
+
msg,
|
|
2127
|
+
Checks._ArgsKwargs(v),
|
|
2128
|
+
render_fmt='%s',
|
|
2129
|
+
)
|
|
2130
|
+
|
|
2131
|
+
return v
|
|
2132
|
+
|
|
2133
|
+
def iterempty(self, v: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
|
|
2134
|
+
it = iter(v)
|
|
2135
|
+
try:
|
|
2136
|
+
next(it)
|
|
2137
|
+
except StopIteration:
|
|
2138
|
+
pass
|
|
2139
|
+
else:
|
|
2140
|
+
self._raise(
|
|
2141
|
+
ValueError,
|
|
2142
|
+
'Must be empty',
|
|
2143
|
+
msg,
|
|
2144
|
+
Checks._ArgsKwargs(v),
|
|
2145
|
+
render_fmt='%s',
|
|
2146
|
+
)
|
|
2147
|
+
|
|
2148
|
+
return v
|
|
2149
|
+
|
|
2150
|
+
def not_empty(self, v: SizedT, msg: CheckMessage = None) -> SizedT:
|
|
2151
|
+
if len(v) == 0:
|
|
2152
|
+
self._raise(
|
|
2153
|
+
ValueError,
|
|
2154
|
+
'Must not be empty',
|
|
2155
|
+
msg,
|
|
2156
|
+
Checks._ArgsKwargs(v),
|
|
2157
|
+
render_fmt='%s',
|
|
2158
|
+
)
|
|
1977
2159
|
|
|
2160
|
+
return v
|
|
1978
2161
|
|
|
1979
|
-
def
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
2162
|
+
def unique(self, it: ta.Iterable[T], msg: CheckMessage = None) -> ta.Iterable[T]:
|
|
2163
|
+
dupes = [e for e, c in collections.Counter(it).items() if c > 1]
|
|
2164
|
+
if dupes:
|
|
2165
|
+
self._raise(
|
|
2166
|
+
ValueError,
|
|
2167
|
+
'Must be unique',
|
|
2168
|
+
msg,
|
|
2169
|
+
Checks._ArgsKwargs(it, dupes),
|
|
2170
|
+
)
|
|
2171
|
+
|
|
2172
|
+
return it
|
|
2173
|
+
|
|
2174
|
+
def single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> T:
|
|
2175
|
+
try:
|
|
2176
|
+
[value] = obj
|
|
2177
|
+
except ValueError:
|
|
2178
|
+
self._raise(
|
|
2179
|
+
ValueError,
|
|
2180
|
+
'Must be single',
|
|
2181
|
+
message,
|
|
2182
|
+
Checks._ArgsKwargs(obj),
|
|
2183
|
+
render_fmt='%s',
|
|
2184
|
+
)
|
|
2185
|
+
|
|
2186
|
+
return value
|
|
2187
|
+
|
|
2188
|
+
def opt_single(self, obj: ta.Iterable[T], message: CheckMessage = None) -> ta.Optional[T]:
|
|
2189
|
+
it = iter(obj)
|
|
2190
|
+
try:
|
|
2191
|
+
value = next(it)
|
|
2192
|
+
except StopIteration:
|
|
2193
|
+
return None
|
|
2194
|
+
|
|
2195
|
+
try:
|
|
2196
|
+
next(it)
|
|
2197
|
+
except StopIteration:
|
|
2198
|
+
return value # noqa
|
|
2199
|
+
|
|
2200
|
+
self._raise(
|
|
2201
|
+
ValueError,
|
|
2202
|
+
'Must be empty or single',
|
|
2203
|
+
message,
|
|
2204
|
+
Checks._ArgsKwargs(obj),
|
|
2205
|
+
render_fmt='%s',
|
|
2206
|
+
)
|
|
2207
|
+
|
|
2208
|
+
raise RuntimeError # noqa
|
|
2209
|
+
|
|
2210
|
+
#
|
|
2211
|
+
|
|
2212
|
+
def none(self, v: ta.Any, msg: CheckMessage = None) -> None:
|
|
2213
|
+
if v is not None:
|
|
2214
|
+
self._raise(
|
|
2215
|
+
ValueError,
|
|
2216
|
+
'Must be None',
|
|
2217
|
+
msg,
|
|
2218
|
+
Checks._ArgsKwargs(v),
|
|
2219
|
+
render_fmt='%s',
|
|
2220
|
+
)
|
|
2221
|
+
|
|
2222
|
+
def not_none(self, v: ta.Optional[T], msg: CheckMessage = None) -> T:
|
|
2223
|
+
if v is None:
|
|
2224
|
+
self._raise(
|
|
2225
|
+
ValueError,
|
|
2226
|
+
'Must not be None',
|
|
2227
|
+
msg,
|
|
2228
|
+
Checks._ArgsKwargs(v),
|
|
2229
|
+
render_fmt='%s',
|
|
2230
|
+
)
|
|
2231
|
+
|
|
2232
|
+
return v
|
|
2233
|
+
|
|
2234
|
+
#
|
|
2235
|
+
|
|
2236
|
+
def equal(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
|
2237
|
+
if o != v:
|
|
2238
|
+
self._raise(
|
|
2239
|
+
ValueError,
|
|
2240
|
+
'Must be equal',
|
|
2241
|
+
msg,
|
|
2242
|
+
Checks._ArgsKwargs(v, o),
|
|
2243
|
+
render_fmt='%s != %s',
|
|
2244
|
+
)
|
|
2245
|
+
|
|
2246
|
+
return v
|
|
2247
|
+
|
|
2248
|
+
def is_(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
|
2249
|
+
if o is not v:
|
|
2250
|
+
self._raise(
|
|
2251
|
+
ValueError,
|
|
2252
|
+
'Must be the same',
|
|
2253
|
+
msg,
|
|
2254
|
+
Checks._ArgsKwargs(v, o),
|
|
2255
|
+
render_fmt='%s is not %s',
|
|
2256
|
+
)
|
|
2257
|
+
|
|
2258
|
+
return v
|
|
2259
|
+
|
|
2260
|
+
def is_not(self, v: T, o: ta.Any, msg: CheckMessage = None) -> T:
|
|
2261
|
+
if o is v:
|
|
2262
|
+
self._raise(
|
|
2263
|
+
ValueError,
|
|
2264
|
+
'Must not be the same',
|
|
2265
|
+
msg,
|
|
2266
|
+
Checks._ArgsKwargs(v, o),
|
|
2267
|
+
render_fmt='%s is %s',
|
|
2268
|
+
)
|
|
2269
|
+
|
|
2270
|
+
return v
|
|
2271
|
+
|
|
2272
|
+
def callable(self, v: T, msg: CheckMessage = None) -> T: # noqa
|
|
2273
|
+
if not callable(v):
|
|
2274
|
+
self._raise(
|
|
2275
|
+
TypeError,
|
|
2276
|
+
'Must be callable',
|
|
2277
|
+
msg,
|
|
2278
|
+
Checks._ArgsKwargs(v),
|
|
2279
|
+
render_fmt='%s',
|
|
2280
|
+
)
|
|
2281
|
+
|
|
2282
|
+
return v # type: ignore
|
|
2283
|
+
|
|
2284
|
+
def non_empty_str(self, v: ta.Optional[str], msg: CheckMessage = None) -> str:
|
|
2285
|
+
if not isinstance(v, str) or not v:
|
|
2286
|
+
self._raise(
|
|
2287
|
+
ValueError,
|
|
2288
|
+
'Must be non-empty str',
|
|
2289
|
+
msg,
|
|
2290
|
+
Checks._ArgsKwargs(v),
|
|
2291
|
+
render_fmt='%s',
|
|
2292
|
+
)
|
|
2293
|
+
|
|
2294
|
+
return v
|
|
2295
|
+
|
|
2296
|
+
def replacing(self, expected: ta.Any, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
|
|
2297
|
+
if old != expected:
|
|
2298
|
+
self._raise(
|
|
2299
|
+
ValueError,
|
|
2300
|
+
'Must be replacing',
|
|
2301
|
+
msg,
|
|
2302
|
+
Checks._ArgsKwargs(expected, old, new),
|
|
2303
|
+
render_fmt='%s -> %s -> %s',
|
|
2304
|
+
)
|
|
2305
|
+
|
|
2306
|
+
return new
|
|
2307
|
+
|
|
2308
|
+
def replacing_none(self, old: ta.Any, new: T, msg: CheckMessage = None) -> T:
|
|
2309
|
+
if old is not None:
|
|
2310
|
+
self._raise(
|
|
2311
|
+
ValueError,
|
|
2312
|
+
'Must be replacing None',
|
|
2313
|
+
msg,
|
|
2314
|
+
Checks._ArgsKwargs(old, new),
|
|
2315
|
+
render_fmt='%s -> %s',
|
|
2316
|
+
)
|
|
2317
|
+
|
|
2318
|
+
return new
|
|
2319
|
+
|
|
2320
|
+
#
|
|
2321
|
+
|
|
2322
|
+
def arg(self, v: bool, msg: CheckMessage = None) -> None:
|
|
2323
|
+
if not v:
|
|
2324
|
+
self._raise(
|
|
2325
|
+
RuntimeError,
|
|
2326
|
+
'Argument condition not met',
|
|
2327
|
+
msg,
|
|
2328
|
+
Checks._ArgsKwargs(v),
|
|
2329
|
+
render_fmt='%s',
|
|
2330
|
+
)
|
|
2331
|
+
|
|
2332
|
+
def state(self, v: bool, msg: CheckMessage = None) -> None:
|
|
2333
|
+
if not v:
|
|
2334
|
+
self._raise(
|
|
2335
|
+
RuntimeError,
|
|
2336
|
+
'State condition not met',
|
|
2337
|
+
msg,
|
|
2338
|
+
Checks._ArgsKwargs(v),
|
|
2339
|
+
render_fmt='%s',
|
|
2340
|
+
)
|
|
1983
2341
|
|
|
1984
2342
|
|
|
1985
|
-
|
|
1986
|
-
if not len(v):
|
|
1987
|
-
raise ValueError(v)
|
|
1988
|
-
return v
|
|
2343
|
+
check = Checks()
|
|
1989
2344
|
|
|
1990
2345
|
|
|
1991
2346
|
########################################
|
|
@@ -3209,10 +3564,10 @@ class ProxyObjMarshaler(ObjMarshaler):
|
|
|
3209
3564
|
m: ta.Optional[ObjMarshaler] = None
|
|
3210
3565
|
|
|
3211
3566
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3212
|
-
return
|
|
3567
|
+
return check.not_none(self.m).marshal(o, ctx)
|
|
3213
3568
|
|
|
3214
3569
|
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3215
|
-
return
|
|
3570
|
+
return check.not_none(self.m).unmarshal(o, ctx)
|
|
3216
3571
|
|
|
3217
3572
|
|
|
3218
3573
|
@dc.dataclass(frozen=True)
|
|
@@ -3371,19 +3726,19 @@ class DatetimeObjMarshaler(ObjMarshaler):
|
|
|
3371
3726
|
|
|
3372
3727
|
class DecimalObjMarshaler(ObjMarshaler):
|
|
3373
3728
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3374
|
-
return str(
|
|
3729
|
+
return str(check.isinstance(o, decimal.Decimal))
|
|
3375
3730
|
|
|
3376
3731
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3377
|
-
return decimal.Decimal(
|
|
3732
|
+
return decimal.Decimal(check.isinstance(v, str))
|
|
3378
3733
|
|
|
3379
3734
|
|
|
3380
3735
|
class FractionObjMarshaler(ObjMarshaler):
|
|
3381
3736
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3382
|
-
fr =
|
|
3737
|
+
fr = check.isinstance(o, fractions.Fraction)
|
|
3383
3738
|
return [fr.numerator, fr.denominator]
|
|
3384
3739
|
|
|
3385
3740
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3386
|
-
num, denom =
|
|
3741
|
+
num, denom = check.isinstance(v, list)
|
|
3387
3742
|
return fractions.Fraction(num, denom)
|
|
3388
3743
|
|
|
3389
3744
|
|
|
@@ -4358,7 +4713,7 @@ def parse_git_status_line(l: str) -> GitStatusItem:
|
|
|
4358
4713
|
if len(fields) == 1:
|
|
4359
4714
|
a, b = fields[0], None
|
|
4360
4715
|
elif len(fields) == 3:
|
|
4361
|
-
|
|
4716
|
+
check.state(fields[1] == '->', l)
|
|
4362
4717
|
a, b = fields[0], fields[2]
|
|
4363
4718
|
else:
|
|
4364
4719
|
raise ValueError(l)
|
|
@@ -4495,7 +4850,7 @@ async def asyncio_subprocess_popen(
|
|
|
4495
4850
|
if shell:
|
|
4496
4851
|
fac = functools.partial(
|
|
4497
4852
|
asyncio.create_subprocess_shell,
|
|
4498
|
-
|
|
4853
|
+
check.single(cmd),
|
|
4499
4854
|
)
|
|
4500
4855
|
else:
|
|
4501
4856
|
fac = functools.partial(
|
|
@@ -4535,7 +4890,7 @@ class AsyncioProcessCommunicator:
|
|
|
4535
4890
|
self._proc = proc
|
|
4536
4891
|
self._loop = loop
|
|
4537
4892
|
|
|
4538
|
-
self._transport: asyncio.base_subprocess.BaseSubprocessTransport =
|
|
4893
|
+
self._transport: asyncio.base_subprocess.BaseSubprocessTransport = check.isinstance(
|
|
4539
4894
|
proc._transport, # type: ignore # noqa
|
|
4540
4895
|
asyncio.base_subprocess.BaseSubprocessTransport,
|
|
4541
4896
|
)
|
|
@@ -4545,7 +4900,7 @@ class AsyncioProcessCommunicator:
|
|
|
4545
4900
|
return self._loop.get_debug()
|
|
4546
4901
|
|
|
4547
4902
|
async def _feed_stdin(self, input: bytes) -> None: # noqa
|
|
4548
|
-
stdin =
|
|
4903
|
+
stdin = check.not_none(self._proc.stdin)
|
|
4549
4904
|
try:
|
|
4550
4905
|
if input is not None:
|
|
4551
4906
|
stdin.write(input)
|
|
@@ -4569,13 +4924,13 @@ class AsyncioProcessCommunicator:
|
|
|
4569
4924
|
return None
|
|
4570
4925
|
|
|
4571
4926
|
async def _read_stream(self, fd: int) -> bytes:
|
|
4572
|
-
transport: ta.Any =
|
|
4927
|
+
transport: ta.Any = check.not_none(self._transport.get_pipe_transport(fd))
|
|
4573
4928
|
|
|
4574
4929
|
if fd == 2:
|
|
4575
|
-
stream =
|
|
4930
|
+
stream = check.not_none(self._proc.stderr)
|
|
4576
4931
|
else:
|
|
4577
|
-
|
|
4578
|
-
stream =
|
|
4932
|
+
check.equal(fd, 1)
|
|
4933
|
+
stream = check.not_none(self._proc.stdout)
|
|
4579
4934
|
|
|
4580
4935
|
if self._debug:
|
|
4581
4936
|
name = 'stdout' if fd == 1 else 'stderr'
|
|
@@ -4695,7 +5050,7 @@ async def asyncio_subprocess_check_output(
|
|
|
4695
5050
|
**kwargs,
|
|
4696
5051
|
)
|
|
4697
5052
|
|
|
4698
|
-
return
|
|
5053
|
+
return check.not_none(stdout)
|
|
4699
5054
|
|
|
4700
5055
|
|
|
4701
5056
|
async def asyncio_subprocess_check_output_str(*args: str, **kwargs: ta.Any) -> str:
|
|
@@ -4877,7 +5232,7 @@ class GitRevisionAdder:
|
|
|
4877
5232
|
def revision(self) -> str:
|
|
4878
5233
|
if self._given_revision is not None:
|
|
4879
5234
|
return self._given_revision
|
|
4880
|
-
return
|
|
5235
|
+
return check.non_empty_str(get_git_revision())
|
|
4881
5236
|
|
|
4882
5237
|
REVISION_ATTR = '__revision__'
|
|
4883
5238
|
|
|
@@ -5637,7 +5992,7 @@ class Pyenv:
|
|
|
5637
5992
|
|
|
5638
5993
|
@async_cached_nullary
|
|
5639
5994
|
async def exe(self) -> str:
|
|
5640
|
-
return os.path.join(
|
|
5995
|
+
return os.path.join(check.not_none(await self.root()), 'bin', 'pyenv')
|
|
5641
5996
|
|
|
5642
5997
|
async def version_exes(self) -> ta.List[ta.Tuple[str, str]]:
|
|
5643
5998
|
if (root := await self.root()) is None:
|
|
@@ -5863,7 +6218,7 @@ class PyenvVersionInstaller:
|
|
|
5863
6218
|
|
|
5864
6219
|
@async_cached_nullary
|
|
5865
6220
|
async def install_dir(self) -> str:
|
|
5866
|
-
return str(os.path.join(
|
|
6221
|
+
return str(os.path.join(check.not_none(await self._pyenv.root()), 'versions', self.install_name()))
|
|
5867
6222
|
|
|
5868
6223
|
@async_cached_nullary
|
|
5869
6224
|
async def install(self) -> str:
|
|
@@ -5886,7 +6241,7 @@ class PyenvVersionInstaller:
|
|
|
5886
6241
|
|
|
5887
6242
|
if self._given_install_name is not None:
|
|
5888
6243
|
full_args = [
|
|
5889
|
-
os.path.join(
|
|
6244
|
+
os.path.join(check.not_none(await self._pyenv.root()), 'plugins', 'python-build', 'bin', 'python-build'), # noqa
|
|
5890
6245
|
*conf_args,
|
|
5891
6246
|
self.install_dir(),
|
|
5892
6247
|
]
|
|
@@ -5958,7 +6313,7 @@ class PyenvInterpProvider(InterpProvider):
|
|
|
5958
6313
|
iv: ta.Optional[InterpVersion]
|
|
5959
6314
|
if self._inspect:
|
|
5960
6315
|
try:
|
|
5961
|
-
iv =
|
|
6316
|
+
iv = check.not_none(await self._inspector.inspect(ep)).iv
|
|
5962
6317
|
except Exception as e: # noqa
|
|
5963
6318
|
return None
|
|
5964
6319
|
else:
|
|
@@ -6319,8 +6674,8 @@ class Venv:
|
|
|
6319
6674
|
|
|
6320
6675
|
@async_cached_nullary
|
|
6321
6676
|
async def interp_exe(self) -> str:
|
|
6322
|
-
i = InterpSpecifier.parse(
|
|
6323
|
-
return
|
|
6677
|
+
i = InterpSpecifier.parse(check.not_none(self._cfg.interp))
|
|
6678
|
+
return check.not_none(await DEFAULT_INTERP_RESOLVER.resolve(i, install=True)).exe
|
|
6324
6679
|
|
|
6325
6680
|
@cached_nullary
|
|
6326
6681
|
def exe(self) -> str:
|
|
@@ -6485,24 +6840,24 @@ async def _venv_cmd(args) -> None:
|
|
|
6485
6840
|
|
|
6486
6841
|
elif cmd == 'exe':
|
|
6487
6842
|
await venv.create()
|
|
6488
|
-
|
|
6843
|
+
check.arg(not args.args)
|
|
6489
6844
|
print(venv.exe())
|
|
6490
6845
|
|
|
6491
6846
|
elif cmd == 'run':
|
|
6492
6847
|
await venv.create()
|
|
6493
|
-
sh =
|
|
6848
|
+
sh = check.not_none(shutil.which('bash'))
|
|
6494
6849
|
script = ' '.join(args.args)
|
|
6495
6850
|
if not script:
|
|
6496
6851
|
script = sh
|
|
6497
6852
|
os.execl(
|
|
6498
|
-
(bash :=
|
|
6853
|
+
(bash := check.not_none(sh)),
|
|
6499
6854
|
bash,
|
|
6500
6855
|
'-c',
|
|
6501
6856
|
f'. {venv.dir_name}/bin/activate && ' + script,
|
|
6502
6857
|
)
|
|
6503
6858
|
|
|
6504
6859
|
elif cmd == 'srcs':
|
|
6505
|
-
|
|
6860
|
+
check.arg(not args.args)
|
|
6506
6861
|
print('\n'.join(venv.srcs()))
|
|
6507
6862
|
|
|
6508
6863
|
elif cmd == 'test':
|