Fixed most typing issues
This commit is contained in:
parent
99e6f9b38e
commit
220f15008b
4 changed files with 22 additions and 10 deletions
|
@ -32,7 +32,7 @@ class TargetScope(Scope):
|
||||||
target: model.Target
|
target: model.Target
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def use(args: model.TargetArgs) -> "TargetScope":
|
def use(args: model.TargetArgs) -> "TargetScope": # type: ignore[override]
|
||||||
registry = model.Registry.use(args)
|
registry = model.Registry.use(args)
|
||||||
target = model.Target.use(args)
|
target = model.Target.use(args)
|
||||||
return TargetScope(registry, target)
|
return TargetScope(registry, target)
|
||||||
|
@ -324,8 +324,8 @@ def gen(out: TextIO, scope: TargetScope):
|
||||||
|
|
||||||
w.separator("Tools")
|
w.separator("Tools")
|
||||||
|
|
||||||
for i in scope.target.tools:
|
for i in target.tools:
|
||||||
tool = scope.target.tools[i]
|
tool = target.tools[i]
|
||||||
rule = rules.rules[i]
|
rule = rules.rules[i]
|
||||||
w.variable(i, tool.cmd)
|
w.variable(i, tool.cmd)
|
||||||
w.variable(
|
w.variable(
|
||||||
|
@ -401,14 +401,14 @@ def _(args: BuildArgs):
|
||||||
|
|
||||||
|
|
||||||
class RunArgs(BuildArgs, shell.DebugArgs, shell.ProfileArgs):
|
class RunArgs(BuildArgs, shell.DebugArgs, shell.ProfileArgs):
|
||||||
debug: bool = cli.arg(None, "debug", "Attach a debugger")
|
debug: bool = cli.arg("d", "debug", "Attach a debugger")
|
||||||
profile: bool = cli.arg(None, "profile", "Profile the execution")
|
profile: bool = cli.arg("p", "profile", "Profile the execution")
|
||||||
args: list[str] = cli.extra("args", "Arguments to pass to the component")
|
args: list[str] = cli.extra("args", "Arguments to pass to the component")
|
||||||
|
|
||||||
|
|
||||||
@cli.command("r", "builder/run", "Run a component")
|
@cli.command("r", "builder/run", "Run a component")
|
||||||
def runCmd(args: RunArgs):
|
def runCmd(args: RunArgs):
|
||||||
args.props |= {"debug": args.debug}
|
args.props |= {"debug": str(args.debug).lower()}
|
||||||
scope = TargetScope.use(args)
|
scope = TargetScope.use(args)
|
||||||
|
|
||||||
component = scope.registry.lookup(
|
component = scope.registry.lookup(
|
||||||
|
|
|
@ -308,10 +308,14 @@ class Field:
|
||||||
)
|
)
|
||||||
|
|
||||||
def innerType(self) -> type:
|
def innerType(self) -> type:
|
||||||
|
assert self._fieldType
|
||||||
|
|
||||||
if self.isList():
|
if self.isList():
|
||||||
|
assert isinstance(self._fieldType, GenericAlias)
|
||||||
return self._fieldType.__args__[0]
|
return self._fieldType.__args__[0]
|
||||||
|
|
||||||
if self.isDict():
|
if self.isDict():
|
||||||
|
assert isinstance(self._fieldType, GenericAlias)
|
||||||
return self._fieldType.__args__[1]
|
return self._fieldType.__args__[1]
|
||||||
|
|
||||||
return self._fieldType
|
return self._fieldType
|
||||||
|
@ -362,6 +366,7 @@ class Field:
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def putValue(self, obj: Any, value: Any, subkey: Optional[str] = None):
|
def putValue(self, obj: Any, value: Any, subkey: Optional[str] = None):
|
||||||
|
assert self._fieldName
|
||||||
value = self.castValue(value, subkey)
|
value = self.castValue(value, subkey)
|
||||||
field = getattr(obj, self._fieldName)
|
field = getattr(obj, self._fieldName)
|
||||||
if isinstance(field, list):
|
if isinstance(field, list):
|
||||||
|
@ -375,6 +380,7 @@ class Field:
|
||||||
setattr(obj, self._fieldName, value)
|
setattr(obj, self._fieldName, value)
|
||||||
|
|
||||||
def getAttr(self, obj: Any) -> Any:
|
def getAttr(self, obj: Any) -> Any:
|
||||||
|
assert self._fieldName
|
||||||
return getattr(obj, self._fieldName)
|
return getattr(obj, self._fieldName)
|
||||||
|
|
||||||
|
|
||||||
|
@ -496,6 +502,7 @@ class Schema:
|
||||||
arg.setDefault(res)
|
arg.setDefault(res)
|
||||||
|
|
||||||
for operand in self.operands:
|
for operand in self.operands:
|
||||||
|
assert operand._fieldName
|
||||||
if operand.isList():
|
if operand.isList():
|
||||||
setattr(res, operand._fieldName, [])
|
setattr(res, operand._fieldName, [])
|
||||||
else:
|
else:
|
||||||
|
@ -696,7 +703,7 @@ class Command:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
_root = Command(None, const.ARGV0)
|
_root = Command(None, [const.ARGV0])
|
||||||
|
|
||||||
|
|
||||||
def _splitPath(path: str) -> list[str]:
|
def _splitPath(path: str) -> list[str]:
|
||||||
|
@ -709,9 +716,11 @@ def _resolvePath(path: list[str]) -> Command:
|
||||||
if path == "/":
|
if path == "/":
|
||||||
return _root
|
return _root
|
||||||
cmd = _root
|
cmd = _root
|
||||||
|
visited = []
|
||||||
for name in path:
|
for name in path:
|
||||||
|
visited.append(name)
|
||||||
if name not in cmd.subcommands:
|
if name not in cmd.subcommands:
|
||||||
cmd.subcommands[name] = Command(None, name)
|
cmd.subcommands[name] = Command(None, visited)
|
||||||
cmd = cmd.subcommands[name]
|
cmd = cmd.subcommands[name]
|
||||||
return cmd
|
return cmd
|
||||||
|
|
||||||
|
|
|
@ -712,7 +712,7 @@ def view(
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if component.resolved[target.id].enabled:
|
if component.resolved[target.id].enabled:
|
||||||
fillcolor = "lightgrey" if component.type == model.Kind.LIB else "lightblue"
|
fillcolor = "lightgrey" if component.type == Kind.LIB else "lightblue"
|
||||||
shape = "plaintext" if not scope == component.id else "box"
|
shape = "plaintext" if not scope == component.id else "box"
|
||||||
|
|
||||||
g.node(
|
g.node(
|
||||||
|
|
|
@ -263,7 +263,10 @@ def _profileMem(cmd: list[str]):
|
||||||
exec("heaptrack", "-o", perfFile, *cmd)
|
exec("heaptrack", "-o", perfFile, *cmd)
|
||||||
|
|
||||||
|
|
||||||
def profile(cmd: list[str], rate=1000, what: Literal["cpu", "mem"] = "cpu"):
|
def profile(cmd: list[str], rate=1000, what: str = "cpu"):
|
||||||
|
if what not in ["cpu", "mem"]:
|
||||||
|
raise RuntimeError("Only cpu and mem can be profile, not " + what)
|
||||||
|
|
||||||
if what == "cpu":
|
if what == "cpu":
|
||||||
_profileCpu(cmd, rate)
|
_profileCpu(cmd, rate)
|
||||||
elif what == "mem":
|
elif what == "mem":
|
||||||
|
|
Loading…
Reference in a new issue