Fixed most typing issues

This commit is contained in:
Sleepy Monax 2024-02-22 08:09:27 +01:00
parent 99e6f9b38e
commit 220f15008b
4 changed files with 22 additions and 10 deletions

View file

@ -32,7 +32,7 @@ class TargetScope(Scope):
target: model.Target
@staticmethod
def use(args: model.TargetArgs) -> "TargetScope":
def use(args: model.TargetArgs) -> "TargetScope": # type: ignore[override]
registry = model.Registry.use(args)
target = model.Target.use(args)
return TargetScope(registry, target)
@ -324,8 +324,8 @@ def gen(out: TextIO, scope: TargetScope):
w.separator("Tools")
for i in scope.target.tools:
tool = scope.target.tools[i]
for i in target.tools:
tool = target.tools[i]
rule = rules.rules[i]
w.variable(i, tool.cmd)
w.variable(
@ -401,14 +401,14 @@ def _(args: BuildArgs):
class RunArgs(BuildArgs, shell.DebugArgs, shell.ProfileArgs):
debug: bool = cli.arg(None, "debug", "Attach a debugger")
profile: bool = cli.arg(None, "profile", "Profile the execution")
debug: bool = cli.arg("d", "debug", "Attach a debugger")
profile: bool = cli.arg("p", "profile", "Profile the execution")
args: list[str] = cli.extra("args", "Arguments to pass to the component")
@cli.command("r", "builder/run", "Run a component")
def runCmd(args: RunArgs):
args.props |= {"debug": args.debug}
args.props |= {"debug": str(args.debug).lower()}
scope = TargetScope.use(args)
component = scope.registry.lookup(

View file

@ -308,10 +308,14 @@ class Field:
)
def innerType(self) -> type:
assert self._fieldType
if self.isList():
assert isinstance(self._fieldType, GenericAlias)
return self._fieldType.__args__[0]
if self.isDict():
assert isinstance(self._fieldType, GenericAlias)
return self._fieldType.__args__[1]
return self._fieldType
@ -362,6 +366,7 @@ class Field:
return val
def putValue(self, obj: Any, value: Any, subkey: Optional[str] = None):
assert self._fieldName
value = self.castValue(value, subkey)
field = getattr(obj, self._fieldName)
if isinstance(field, list):
@ -375,6 +380,7 @@ class Field:
setattr(obj, self._fieldName, value)
def getAttr(self, obj: Any) -> Any:
assert self._fieldName
return getattr(obj, self._fieldName)
@ -496,6 +502,7 @@ class Schema:
arg.setDefault(res)
for operand in self.operands:
assert operand._fieldName
if operand.isList():
setattr(res, operand._fieldName, [])
else:
@ -696,7 +703,7 @@ class Command:
return
_root = Command(None, const.ARGV0)
_root = Command(None, [const.ARGV0])
def _splitPath(path: str) -> list[str]:
@ -709,9 +716,11 @@ def _resolvePath(path: list[str]) -> Command:
if path == "/":
return _root
cmd = _root
visited = []
for name in path:
visited.append(name)
if name not in cmd.subcommands:
cmd.subcommands[name] = Command(None, name)
cmd.subcommands[name] = Command(None, visited)
cmd = cmd.subcommands[name]
return cmd

View file

@ -712,7 +712,7 @@ def view(
continue
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"
g.node(

View file

@ -263,7 +263,10 @@ def _profileMem(cmd: list[str]):
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":
_profileCpu(cmd, rate)
elif what == "mem":