omdev 0.0.0.dev179__py3-none-any.whl → 0.0.0.dev181__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/scripts/interp.py CHANGED
@@ -78,7 +78,7 @@ UnparsedVersionVar = ta.TypeVar('UnparsedVersionVar', bound=UnparsedVersion)
78
78
  CallableVersionOperator = ta.Callable[['Version', str], bool]
79
79
 
80
80
  # ../../omlish/argparse/cli.py
81
- ArgparseCommandFn = ta.Callable[[], ta.Optional[int]] # ta.TypeAlias
81
+ ArgparseCmdFn = ta.Callable[[], ta.Optional[int]] # ta.TypeAlias
82
82
 
83
83
  # ../../omlish/lite/inject.py
84
84
  U = ta.TypeVar('U')
@@ -1050,13 +1050,6 @@ json_dump_compact: ta.Callable[..., bytes] = functools.partial(json.dump, **JSON
1050
1050
  json_dumps_compact: ta.Callable[..., str] = functools.partial(json.dumps, **JSON_COMPACT_KWARGS)
1051
1051
 
1052
1052
 
1053
- ########################################
1054
- # ../../../omlish/lite/logs.py
1055
-
1056
-
1057
- log = logging.getLogger(__name__)
1058
-
1059
-
1060
1053
  ########################################
1061
1054
  # ../../../omlish/lite/maybes.py
1062
1055
 
@@ -1953,15 +1946,15 @@ def argparse_arg(*args, **kwargs) -> ArgparseArg:
1953
1946
 
1954
1947
 
1955
1948
  @dc.dataclass(eq=False)
1956
- class ArgparseCommand:
1949
+ class ArgparseCmd:
1957
1950
  name: str
1958
- fn: ArgparseCommandFn
1951
+ fn: ArgparseCmdFn
1959
1952
  args: ta.Sequence[ArgparseArg] = () # noqa
1960
1953
 
1961
1954
  # _: dc.KW_ONLY
1962
1955
 
1963
1956
  aliases: ta.Optional[ta.Sequence[str]] = None
1964
- parent: ta.Optional['ArgparseCommand'] = None
1957
+ parent: ta.Optional['ArgparseCmd'] = None
1965
1958
  accepts_unknown: bool = False
1966
1959
 
1967
1960
  def __post_init__(self) -> None:
@@ -1976,7 +1969,7 @@ class ArgparseCommand:
1976
1969
 
1977
1970
  check.arg(callable(self.fn))
1978
1971
  check.arg(all(isinstance(a, ArgparseArg) for a in self.args))
1979
- check.isinstance(self.parent, (ArgparseCommand, type(None)))
1972
+ check.isinstance(self.parent, (ArgparseCmd, type(None)))
1980
1973
  check.isinstance(self.accepts_unknown, bool)
1981
1974
 
1982
1975
  functools.update_wrapper(self, self.fn)
@@ -1990,21 +1983,21 @@ class ArgparseCommand:
1990
1983
  return self.fn(*args, **kwargs)
1991
1984
 
1992
1985
 
1993
- def argparse_command(
1986
+ def argparse_cmd(
1994
1987
  *args: ArgparseArg,
1995
1988
  name: ta.Optional[str] = None,
1996
1989
  aliases: ta.Optional[ta.Iterable[str]] = None,
1997
- parent: ta.Optional[ArgparseCommand] = None,
1990
+ parent: ta.Optional[ArgparseCmd] = None,
1998
1991
  accepts_unknown: bool = False,
1999
- ) -> ta.Any: # ta.Callable[[ArgparseCommandFn], ArgparseCommand]: # FIXME
1992
+ ) -> ta.Any: # ta.Callable[[ArgparseCmdFn], ArgparseCmd]: # FIXME
2000
1993
  for arg in args:
2001
1994
  check.isinstance(arg, ArgparseArg)
2002
1995
  check.isinstance(name, (str, type(None)))
2003
- check.isinstance(parent, (ArgparseCommand, type(None)))
1996
+ check.isinstance(parent, (ArgparseCmd, type(None)))
2004
1997
  check.not_isinstance(aliases, str)
2005
1998
 
2006
1999
  def inner(fn):
2007
- return ArgparseCommand(
2000
+ return ArgparseCmd(
2008
2001
  (name if name is not None else fn.__name__).replace('_', '-'),
2009
2002
  fn,
2010
2003
  args,
@@ -2059,7 +2052,7 @@ class ArgparseCli:
2059
2052
  for bns in [bcls.__dict__ for bcls in reversed(mro)] + [ns]:
2060
2053
  bseen = set() # type: ignore
2061
2054
  for k, v in bns.items():
2062
- if isinstance(v, (ArgparseCommand, ArgparseArg)):
2055
+ if isinstance(v, (ArgparseCmd, ArgparseArg)):
2063
2056
  check.not_in(v, bseen)
2064
2057
  bseen.add(v)
2065
2058
  objs[k] = v
@@ -2086,7 +2079,7 @@ class ArgparseCli:
2086
2079
  subparsers = parser.add_subparsers()
2087
2080
 
2088
2081
  for att, obj in objs.items():
2089
- if isinstance(obj, ArgparseCommand):
2082
+ if isinstance(obj, ArgparseCmd):
2090
2083
  if obj.parent is not None:
2091
2084
  raise NotImplementedError
2092
2085
 
@@ -2148,7 +2141,7 @@ class ArgparseCli:
2148
2141
 
2149
2142
  #
2150
2143
 
2151
- def _bind_cli_cmd(self, cmd: ArgparseCommand) -> ta.Callable:
2144
+ def _bind_cli_cmd(self, cmd: ArgparseCmd) -> ta.Callable:
2152
2145
  return cmd.__get__(self, type(self))
2153
2146
 
2154
2147
  def prepare_cli_run(self) -> ta.Optional[ta.Callable]:
@@ -4205,9 +4198,15 @@ class InterpInspection:
4205
4198
 
4206
4199
 
4207
4200
  class InterpInspector:
4208
- def __init__(self) -> None:
4201
+ def __init__(
4202
+ self,
4203
+ *,
4204
+ log: ta.Optional[logging.Logger] = None,
4205
+ ) -> None:
4209
4206
  super().__init__()
4210
4207
 
4208
+ self._log = log
4209
+
4211
4210
  self._cache: ta.Dict[str, ta.Optional[InterpInspection]] = {}
4212
4211
 
4213
4212
  _RAW_INSPECTION_CODE = """
@@ -4256,8 +4255,8 @@ class InterpInspector:
4256
4255
  try:
4257
4256
  ret = await self._inspect(exe)
4258
4257
  except Exception as e: # noqa
4259
- if log.isEnabledFor(logging.DEBUG):
4260
- log.exception('Failed to inspect interp: %s', exe)
4258
+ if self._log is not None and self._log.isEnabledFor(logging.DEBUG):
4259
+ self._log.exception('Failed to inspect interp: %s', exe)
4261
4260
  ret = None
4262
4261
  self._cache[exe] = ret
4263
4262
  return ret
@@ -4397,12 +4396,14 @@ class SystemInterpProvider(InterpProvider):
4397
4396
  options: Options = Options(),
4398
4397
  *,
4399
4398
  inspector: ta.Optional[InterpInspector] = None,
4399
+ log: ta.Optional[logging.Logger] = None,
4400
4400
  ) -> None:
4401
4401
  super().__init__()
4402
4402
 
4403
4403
  self._options = options
4404
4404
 
4405
4405
  self._inspector = inspector
4406
+ self._log = log
4406
4407
 
4407
4408
  #
4408
4409
 
@@ -4476,7 +4477,8 @@ class SystemInterpProvider(InterpProvider):
4476
4477
  lst = []
4477
4478
  for e in self.exes():
4478
4479
  if (ev := await self.get_exe_version(e)) is None:
4479
- log.debug('Invalid system version: %s', e)
4480
+ if self._log is not None:
4481
+ self._log.debug('Invalid system version: %s', e)
4480
4482
  continue
4481
4483
  lst.append((e, ev))
4482
4484
  return lst
@@ -4833,6 +4835,7 @@ class PyenvInterpProvider(InterpProvider):
4833
4835
  *,
4834
4836
  pyenv: Pyenv,
4835
4837
  inspector: InterpInspector,
4838
+ log: ta.Optional[logging.Logger] = None,
4836
4839
  ) -> None:
4837
4840
  super().__init__()
4838
4841
 
@@ -4840,6 +4843,7 @@ class PyenvInterpProvider(InterpProvider):
4840
4843
 
4841
4844
  self._pyenv = pyenv
4842
4845
  self._inspector = inspector
4846
+ self._log = log
4843
4847
 
4844
4848
  #
4845
4849
 
@@ -4884,7 +4888,8 @@ class PyenvInterpProvider(InterpProvider):
4884
4888
  ret: ta.List[PyenvInterpProvider.Installed] = []
4885
4889
  for vn, ep in await self._pyenv.version_exes():
4886
4890
  if (i := await self._make_installed(vn, ep)) is None:
4887
- log.debug('Invalid pyenv version: %s', vn)
4891
+ if self._log is not None:
4892
+ self._log.debug('Invalid pyenv version: %s', vn)
4888
4893
  continue
4889
4894
  ret.append(i)
4890
4895
  return ret
@@ -5034,7 +5039,7 @@ class InterpCli(ArgparseCli):
5034
5039
 
5035
5040
  #
5036
5041
 
5037
- @argparse_command(
5042
+ @argparse_cmd(
5038
5043
  argparse_arg('version'),
5039
5044
  argparse_arg('-d', '--debug', action='store_true'),
5040
5045
  )
@@ -5043,7 +5048,7 @@ class InterpCli(ArgparseCli):
5043
5048
  s = InterpSpecifier.parse(self.args.version)
5044
5049
  await r.list(s)
5045
5050
 
5046
- @argparse_command(
5051
+ @argparse_cmd(
5047
5052
  argparse_arg('version'),
5048
5053
  argparse_arg('-p', '--provider'),
5049
5054
  argparse_arg('-d', '--debug', action='store_true'),