tools/spec: correct some PEP8 style warnings

This commit is contained in:
Danny Robson 2019-03-13 14:49:21 +11:00
parent 80c13529bd
commit 5d2c872596

View File

@ -1,9 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import sys import sys
import logging import logging
from typing import List, Dict, Set, TextIO from typing import List, Dict, Set, TextIO
import pprint
import xml.etree.ElementTree import xml.etree.ElementTree
@ -15,7 +14,7 @@ def rename(name: str):
############################################################################### ###############################################################################
class Registry: class Registry:
types: Dict[str, object] = {} types: Dict[str, 'Type'] = {}
extensions: Dict = {} extensions: Dict = {}
features: Dict = {} features: Dict = {}
applied: Set = set() applied: Set = set()
@ -403,13 +402,13 @@ class Command(Type):
be the same as self.name for a useful system). be the same as self.name for a useful system).
""" """
def __init__(self, name:str, type:str, param:str, depends:List[str]): def __init__(self, name: str, klass: str, param: str, depends: List[str]):
super().__init__( super().__init__(
name=name, name=name,
depends=depends, depends=depends,
) )
self.type = type self.type = klass
self.param = param self.param = param
def __repr__(self) -> str: def __repr__(self) -> str:
@ -509,9 +508,9 @@ class Require(object):
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
class Feature(Type): class Feature(Type):
def __init__(self, name: str, requires: List[Require] = []): def __init__(self, name: str, requires: List[Require] = None):
super().__init__(name) super().__init__(name)
self.requires = requires self.requires = requires or []
def define(self, reg: Registry): def define(self, reg: Registry):
return "#define %s" % self.name return "#define %s" % self.name
@ -569,7 +568,6 @@ class Extension(Type):
############################################################################### ###############################################################################
def ignore_node(types: Dict[str, Type], root): def ignore_node(types: Dict[str, Type], root):
types, root
pass pass
@ -595,7 +593,7 @@ def parse_types(reg: Registry, root):
reg.types[name] = AliasType(name, target) reg.types[name] = AliasType(name, target)
continue continue
category = t.attrib.get ('category') category = t.attrib.get('category')
# if we don't have a category we should have a bare type that has a # if we don't have a category we should have a bare type that has a
# dependency on something like a header. # dependency on something like a header.
@ -645,7 +643,8 @@ def parse_enums(reg: Registry, root):
else: else:
owner[valuename] = Constant(node) owner[valuename] = Constant(node)
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def parse_param(root) -> Command.Param: def parse_param(root) -> Command.Param:
assert root.tag == 'param' assert root.tag == 'param'
@ -657,12 +656,12 @@ def parse_param(root) -> Command.Param:
param = " ".join(param.split()) param = " ".join(param.split())
name = root.find('name').text name = root.find('name').text
type = root.find('type').text klass = root.find('type').text
depends = [root.find('type').text] depends = [root.find('type').text]
return Command.Param( return Command.Param(
name=name, name=name,
type=type, klass=klass,
param=param, param=param,
depends=depends, depends=depends,
) )
@ -711,7 +710,8 @@ def parse_require(root) -> Require:
return Require(values=values, depends=depends) return Require(values=values, depends=depends)
##-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
def parse_feature(reg: Registry, root): def parse_feature(reg: Registry, root):
assert root.tag == 'feature' assert root.tag == 'feature'
@ -814,7 +814,7 @@ def write_load(dst: TextIO, q: List[Type], reg: Registry):
""") """)
for name, test in collections.items(): for name, test in collections.items():
curr = [i for i in commands if test(i, reg)] curr = [i for i in commands if test(i, reg)]
next = [i for i in commands if not test(i, reg)] next = [i for i in commands if not test(i, reg)]
commands = next commands = next
@ -1016,7 +1016,7 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry):
for obj in (i for i in q if isinstance(i, Command)): for obj in (i for i in q if isinstance(i, Command)):
inner = "" inner = ""
if obj.name in [ 'vkGetInstanceProcAddr' ]: if obj.name in ['vkGetInstanceProcAddr']:
inner = """ inner = """
#define FWD(NAME) \\ #define FWD(NAME) \\
@ -1026,9 +1026,12 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry):
else \\ else \\
return nullptr;\\ return nullptr;\\
} }
#undef FWD
#define FWD(NAME) if (!strcmp(#NAME,pName)) { return (PFN_vkVoidFunction)NAME; }
MAP_INSTANCE_COMMANDS(FWD) MAP_INSTANCE_COMMANDS(FWD)
#undef FWD #undef FWD
std::clog << "Missed: " << pName << '\\n'; std::clog << "Unhooked: " << pName << '\\n';
""" """
dst.write(f""" dst.write(f"""
@ -1041,10 +1044,6 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry):
############################################################################### ###############################################################################
import argparse
# -----------------------------------------------------------------------------
def main(): def main():
logging.getLogger().setLevel(logging.WARNING) logging.getLogger().setLevel(logging.WARNING)