omdev 0.0.0.dev148__py3-none-any.whl → 0.0.0.dev150__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/amalg/amalg.py +2 -1
- omdev/cli/clicli.py +1 -1
- omdev/git.py +2 -2
- omdev/imgur.py +2 -2
- 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/pycharm/cli.py +1 -1
- omdev/pyproject/cli.py +7 -8
- omdev/revisions.py +2 -2
- omdev/scripts/interp.py +434 -74
- omdev/scripts/pyproject.py +447 -87
- omdev/tools/doc.py +1 -1
- omdev/tools/docker.py +1 -1
- omdev/tools/git.py +1 -1
- omdev/tools/json/parsing.py +1 -1
- omdev/tools/notebook.py +1 -1
- omdev/tools/pip.py +1 -1
- omdev/tools/prof.py +1 -1
- omdev/tools/sqlrepl.py +1 -1
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.dist-info}/METADATA +2 -2
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.dist-info}/RECORD +27 -27
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.dist-info}/LICENSE +0 -0
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.dist-info}/WHEEL +0 -0
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.dist-info}/entry_points.txt +0 -0
- {omdev-0.0.0.dev148.dist-info → omdev-0.0.0.dev150.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]
|
|
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,99 +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
|
|
1891
1920
|
|
|
1921
|
+
#
|
|
1892
1922
|
|
|
1893
|
-
def
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
return v
|
|
1923
|
+
def register_on_raise(self, fn: CheckOnRaiseFn) -> None:
|
|
1924
|
+
with self._config_lock:
|
|
1925
|
+
self._on_raise_fns = [*self._on_raise_fns, fn]
|
|
1897
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]
|
|
1898
1930
|
|
|
1899
|
-
|
|
1900
|
-
if isinstance(v, spec):
|
|
1901
|
-
raise TypeError(v)
|
|
1902
|
-
return v
|
|
1931
|
+
#
|
|
1903
1932
|
|
|
1933
|
+
def set_exception_factory(self, factory: CheckExceptionFactory) -> None:
|
|
1934
|
+
self._exception_factory = factory
|
|
1904
1935
|
|
|
1905
|
-
def
|
|
1906
|
-
|
|
1907
|
-
raise ValueError(v)
|
|
1936
|
+
def set_args_renderer(self, renderer: ta.Optional[CheckArgsRenderer]) -> None:
|
|
1937
|
+
self._args_renderer = renderer
|
|
1908
1938
|
|
|
1939
|
+
#
|
|
1909
1940
|
|
|
1910
|
-
def
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
return v
|
|
1941
|
+
def register_late_configure(self, fn: CheckLateConfigureFn) -> None:
|
|
1942
|
+
with self._config_lock:
|
|
1943
|
+
self._late_configure_fns = [*self._late_configure_fns, fn]
|
|
1914
1944
|
|
|
1945
|
+
def _late_configure(self) -> None:
|
|
1946
|
+
if not self._late_configure_fns:
|
|
1947
|
+
return
|
|
1915
1948
|
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
return v
|
|
1949
|
+
with self._config_lock:
|
|
1950
|
+
if not (lc := self._late_configure_fns):
|
|
1951
|
+
return
|
|
1920
1952
|
|
|
1953
|
+
for fn in lc:
|
|
1954
|
+
fn(self)
|
|
1921
1955
|
|
|
1922
|
-
|
|
1923
|
-
if not v:
|
|
1924
|
-
raise ValueError
|
|
1925
|
-
return v
|
|
1956
|
+
self._late_configure_fns = []
|
|
1926
1957
|
|
|
1958
|
+
#
|
|
1927
1959
|
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1960
|
+
class _ArgsKwargs:
|
|
1961
|
+
def __init__(self, *args, **kwargs):
|
|
1962
|
+
self.args = args
|
|
1963
|
+
self.kwargs = kwargs
|
|
1931
1964
|
|
|
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
|
+
)
|
|
1997
|
+
|
|
1998
|
+
for fn in self._on_raise_fns:
|
|
1999
|
+
fn(exc)
|
|
1932
2000
|
|
|
1933
|
-
|
|
1934
|
-
if l != r:
|
|
1935
|
-
raise ValueError(l, r)
|
|
1936
|
-
return l
|
|
2001
|
+
raise exc
|
|
1937
2002
|
|
|
2003
|
+
#
|
|
1938
2004
|
|
|
1939
|
-
def
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
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
|
+
)
|
|
1943
2025
|
|
|
2026
|
+
return v
|
|
1944
2027
|
|
|
1945
|
-
def
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
return l
|
|
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)
|
|
1949
2031
|
|
|
2032
|
+
return inner
|
|
1950
2033
|
|
|
1951
|
-
def
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
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
|
+
)
|
|
1955
2042
|
|
|
2043
|
+
return v
|
|
1956
2044
|
|
|
1957
|
-
def
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
return v
|
|
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)
|
|
1961
2048
|
|
|
2049
|
+
return inner
|
|
1962
2050
|
|
|
1963
|
-
def
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
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
|
+
)
|
|
1967
2060
|
|
|
2061
|
+
return v
|
|
1968
2062
|
|
|
1969
|
-
def
|
|
1970
|
-
|
|
1971
|
-
|
|
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)
|
|
1972
2066
|
|
|
2067
|
+
return inner
|
|
2068
|
+
|
|
2069
|
+
##
|
|
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
|
+
)
|
|
2080
|
+
|
|
2081
|
+
return v
|
|
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
|
+
)
|
|
2092
|
+
|
|
2093
|
+
return v
|
|
2094
|
+
|
|
2095
|
+
#
|
|
2096
|
+
|
|
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
|
+
)
|
|
2106
|
+
|
|
2107
|
+
return v
|
|
2108
|
+
|
|
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
|
+
)
|
|
1973
2159
|
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2160
|
+
return v
|
|
2161
|
+
|
|
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
|
+
)
|
|
1978
2341
|
|
|
1979
2342
|
|
|
1980
|
-
|
|
1981
|
-
if not len(v):
|
|
1982
|
-
raise ValueError(v)
|
|
1983
|
-
return v
|
|
2343
|
+
check = Checks()
|
|
1984
2344
|
|
|
1985
2345
|
|
|
1986
2346
|
########################################
|
|
@@ -3204,10 +3564,10 @@ class ProxyObjMarshaler(ObjMarshaler):
|
|
|
3204
3564
|
m: ta.Optional[ObjMarshaler] = None
|
|
3205
3565
|
|
|
3206
3566
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3207
|
-
return
|
|
3567
|
+
return check.not_none(self.m).marshal(o, ctx)
|
|
3208
3568
|
|
|
3209
3569
|
def unmarshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3210
|
-
return
|
|
3570
|
+
return check.not_none(self.m).unmarshal(o, ctx)
|
|
3211
3571
|
|
|
3212
3572
|
|
|
3213
3573
|
@dc.dataclass(frozen=True)
|
|
@@ -3366,19 +3726,19 @@ class DatetimeObjMarshaler(ObjMarshaler):
|
|
|
3366
3726
|
|
|
3367
3727
|
class DecimalObjMarshaler(ObjMarshaler):
|
|
3368
3728
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3369
|
-
return str(
|
|
3729
|
+
return str(check.isinstance(o, decimal.Decimal))
|
|
3370
3730
|
|
|
3371
3731
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3372
|
-
return decimal.Decimal(
|
|
3732
|
+
return decimal.Decimal(check.isinstance(v, str))
|
|
3373
3733
|
|
|
3374
3734
|
|
|
3375
3735
|
class FractionObjMarshaler(ObjMarshaler):
|
|
3376
3736
|
def marshal(self, o: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3377
|
-
fr =
|
|
3737
|
+
fr = check.isinstance(o, fractions.Fraction)
|
|
3378
3738
|
return [fr.numerator, fr.denominator]
|
|
3379
3739
|
|
|
3380
3740
|
def unmarshal(self, v: ta.Any, ctx: 'ObjMarshalContext') -> ta.Any:
|
|
3381
|
-
num, denom =
|
|
3741
|
+
num, denom = check.isinstance(v, list)
|
|
3382
3742
|
return fractions.Fraction(num, denom)
|
|
3383
3743
|
|
|
3384
3744
|
|
|
@@ -4353,7 +4713,7 @@ def parse_git_status_line(l: str) -> GitStatusItem:
|
|
|
4353
4713
|
if len(fields) == 1:
|
|
4354
4714
|
a, b = fields[0], None
|
|
4355
4715
|
elif len(fields) == 3:
|
|
4356
|
-
|
|
4716
|
+
check.state(fields[1] == '->', l)
|
|
4357
4717
|
a, b = fields[0], fields[2]
|
|
4358
4718
|
else:
|
|
4359
4719
|
raise ValueError(l)
|
|
@@ -4490,7 +4850,7 @@ async def asyncio_subprocess_popen(
|
|
|
4490
4850
|
if shell:
|
|
4491
4851
|
fac = functools.partial(
|
|
4492
4852
|
asyncio.create_subprocess_shell,
|
|
4493
|
-
|
|
4853
|
+
check.single(cmd),
|
|
4494
4854
|
)
|
|
4495
4855
|
else:
|
|
4496
4856
|
fac = functools.partial(
|
|
@@ -4530,7 +4890,7 @@ class AsyncioProcessCommunicator:
|
|
|
4530
4890
|
self._proc = proc
|
|
4531
4891
|
self._loop = loop
|
|
4532
4892
|
|
|
4533
|
-
self._transport: asyncio.base_subprocess.BaseSubprocessTransport =
|
|
4893
|
+
self._transport: asyncio.base_subprocess.BaseSubprocessTransport = check.isinstance(
|
|
4534
4894
|
proc._transport, # type: ignore # noqa
|
|
4535
4895
|
asyncio.base_subprocess.BaseSubprocessTransport,
|
|
4536
4896
|
)
|
|
@@ -4540,7 +4900,7 @@ class AsyncioProcessCommunicator:
|
|
|
4540
4900
|
return self._loop.get_debug()
|
|
4541
4901
|
|
|
4542
4902
|
async def _feed_stdin(self, input: bytes) -> None: # noqa
|
|
4543
|
-
stdin =
|
|
4903
|
+
stdin = check.not_none(self._proc.stdin)
|
|
4544
4904
|
try:
|
|
4545
4905
|
if input is not None:
|
|
4546
4906
|
stdin.write(input)
|
|
@@ -4564,13 +4924,13 @@ class AsyncioProcessCommunicator:
|
|
|
4564
4924
|
return None
|
|
4565
4925
|
|
|
4566
4926
|
async def _read_stream(self, fd: int) -> bytes:
|
|
4567
|
-
transport: ta.Any =
|
|
4927
|
+
transport: ta.Any = check.not_none(self._transport.get_pipe_transport(fd))
|
|
4568
4928
|
|
|
4569
4929
|
if fd == 2:
|
|
4570
|
-
stream =
|
|
4930
|
+
stream = check.not_none(self._proc.stderr)
|
|
4571
4931
|
else:
|
|
4572
|
-
|
|
4573
|
-
stream =
|
|
4932
|
+
check.equal(fd, 1)
|
|
4933
|
+
stream = check.not_none(self._proc.stdout)
|
|
4574
4934
|
|
|
4575
4935
|
if self._debug:
|
|
4576
4936
|
name = 'stdout' if fd == 1 else 'stderr'
|
|
@@ -4690,7 +5050,7 @@ async def asyncio_subprocess_check_output(
|
|
|
4690
5050
|
**kwargs,
|
|
4691
5051
|
)
|
|
4692
5052
|
|
|
4693
|
-
return
|
|
5053
|
+
return check.not_none(stdout)
|
|
4694
5054
|
|
|
4695
5055
|
|
|
4696
5056
|
async def asyncio_subprocess_check_output_str(*args: str, **kwargs: ta.Any) -> str:
|
|
@@ -4872,7 +5232,7 @@ class GitRevisionAdder:
|
|
|
4872
5232
|
def revision(self) -> str:
|
|
4873
5233
|
if self._given_revision is not None:
|
|
4874
5234
|
return self._given_revision
|
|
4875
|
-
return
|
|
5235
|
+
return check.non_empty_str(get_git_revision())
|
|
4876
5236
|
|
|
4877
5237
|
REVISION_ATTR = '__revision__'
|
|
4878
5238
|
|
|
@@ -5632,7 +5992,7 @@ class Pyenv:
|
|
|
5632
5992
|
|
|
5633
5993
|
@async_cached_nullary
|
|
5634
5994
|
async def exe(self) -> str:
|
|
5635
|
-
return os.path.join(
|
|
5995
|
+
return os.path.join(check.not_none(await self.root()), 'bin', 'pyenv')
|
|
5636
5996
|
|
|
5637
5997
|
async def version_exes(self) -> ta.List[ta.Tuple[str, str]]:
|
|
5638
5998
|
if (root := await self.root()) is None:
|
|
@@ -5858,7 +6218,7 @@ class PyenvVersionInstaller:
|
|
|
5858
6218
|
|
|
5859
6219
|
@async_cached_nullary
|
|
5860
6220
|
async def install_dir(self) -> str:
|
|
5861
|
-
return str(os.path.join(
|
|
6221
|
+
return str(os.path.join(check.not_none(await self._pyenv.root()), 'versions', self.install_name()))
|
|
5862
6222
|
|
|
5863
6223
|
@async_cached_nullary
|
|
5864
6224
|
async def install(self) -> str:
|
|
@@ -5881,7 +6241,7 @@ class PyenvVersionInstaller:
|
|
|
5881
6241
|
|
|
5882
6242
|
if self._given_install_name is not None:
|
|
5883
6243
|
full_args = [
|
|
5884
|
-
os.path.join(
|
|
6244
|
+
os.path.join(check.not_none(await self._pyenv.root()), 'plugins', 'python-build', 'bin', 'python-build'), # noqa
|
|
5885
6245
|
*conf_args,
|
|
5886
6246
|
self.install_dir(),
|
|
5887
6247
|
]
|
|
@@ -5953,7 +6313,7 @@ class PyenvInterpProvider(InterpProvider):
|
|
|
5953
6313
|
iv: ta.Optional[InterpVersion]
|
|
5954
6314
|
if self._inspect:
|
|
5955
6315
|
try:
|
|
5956
|
-
iv =
|
|
6316
|
+
iv = check.not_none(await self._inspector.inspect(ep)).iv
|
|
5957
6317
|
except Exception as e: # noqa
|
|
5958
6318
|
return None
|
|
5959
6319
|
else:
|
|
@@ -6314,8 +6674,8 @@ class Venv:
|
|
|
6314
6674
|
|
|
6315
6675
|
@async_cached_nullary
|
|
6316
6676
|
async def interp_exe(self) -> str:
|
|
6317
|
-
i = InterpSpecifier.parse(
|
|
6318
|
-
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
|
|
6319
6679
|
|
|
6320
6680
|
@cached_nullary
|
|
6321
6681
|
def exe(self) -> str:
|
|
@@ -6480,24 +6840,24 @@ async def _venv_cmd(args) -> None:
|
|
|
6480
6840
|
|
|
6481
6841
|
elif cmd == 'exe':
|
|
6482
6842
|
await venv.create()
|
|
6483
|
-
|
|
6843
|
+
check.arg(not args.args)
|
|
6484
6844
|
print(venv.exe())
|
|
6485
6845
|
|
|
6486
6846
|
elif cmd == 'run':
|
|
6487
6847
|
await venv.create()
|
|
6488
|
-
sh =
|
|
6848
|
+
sh = check.not_none(shutil.which('bash'))
|
|
6489
6849
|
script = ' '.join(args.args)
|
|
6490
6850
|
if not script:
|
|
6491
6851
|
script = sh
|
|
6492
6852
|
os.execl(
|
|
6493
|
-
(bash :=
|
|
6853
|
+
(bash := check.not_none(sh)),
|
|
6494
6854
|
bash,
|
|
6495
6855
|
'-c',
|
|
6496
6856
|
f'. {venv.dir_name}/bin/activate && ' + script,
|
|
6497
6857
|
)
|
|
6498
6858
|
|
|
6499
6859
|
elif cmd == 'srcs':
|
|
6500
|
-
|
|
6860
|
+
check.arg(not args.args)
|
|
6501
6861
|
print('\n'.join(venv.srcs()))
|
|
6502
6862
|
|
|
6503
6863
|
elif cmd == 'test':
|