re-run through ruff formatter

This commit is contained in:
2025-01-15 12:40:31 +00:00
parent 7b725a51e3
commit da1d5132a8
28 changed files with 608 additions and 609 deletions

View File

@@ -21,14 +21,14 @@ logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
argparser = argparse.ArgumentParser(description="creates a basic dsl")
argparser.add_argument("-i", action="store_true")
argparser = argparse.ArgumentParser(description='creates a basic dsl')
argparser.add_argument('-i', action='store_true')
args = argparser.parse_args()
ParamKinds = IntEnum(
"ParamKinds",
"bool float string",
'ParamKinds',
'bool float string',
)
@@ -51,12 +51,12 @@ class BoolStrategy(Strategy):
"""Convert a string representation of truth to it's numeric form."""
val = val.lower()
if val in ("y", "yes", "t", "true", "on", "1"):
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return 1
elif val in ("n", "no", "f", "false", "off", "0"):
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return 0
else:
raise ValueError("invalid truth value %r" % (val,))
raise ValueError('invalid truth value %r' % (val,))
class FloatStrategy(Strategy):
@@ -66,7 +66,7 @@ class FloatStrategy(Strategy):
class StringStrategy(Strategy):
def run(self):
setattr(self.target, self.param, " ".join(self.val))
setattr(self.target, self.param, ' '.join(self.val))
class Context:
@@ -86,16 +86,16 @@ class Context:
class Parser:
IS_STRING = ("label",)
IS_STRING = ('label',)
def __init__(self, vm):
self.logger = logger.getChild(self.__class__.__name__)
self.vm = vm
self.kls = Group(OneOrMore(Word(alphanums)))
self.token = Suppress("->")
self.token = Suppress('->')
self.param = Group(OneOrMore(Word(alphanums)))
self.value = Combine(
Optional("-") + Word(nums) + Optional(".") + Optional(Word(nums))
Optional('-') + Word(nums) + Optional('.') + Optional(Word(nums))
) | Group(OneOrMore(Word(alphanums)))
self.event = (
self.kls
@@ -110,7 +110,7 @@ class Parser:
res = list()
for cmd in cmds:
self.logger.debug(f"running command: {cmd}")
self.logger.debug(f'running command: {cmd}')
match cmd_parsed := self.event.parseString(cmd):
case [[kls, index], [param]]:
target = getattr(self.vm, kls)[int(index)]
@@ -125,7 +125,7 @@ class Parser:
context = self._get_context(ParamKinds.bool, target, param, val)
context.run()
except ValueError as e:
self.logger.error(f"{e}... switching to float strategy")
self.logger.error(f'{e}... switching to float strategy')
context.strategy = FloatStrategy(target, param, val)
context.run()
case [
@@ -140,12 +140,12 @@ class Parser:
context = self._get_context(ParamKinds.bool, target, param, val)
context.run()
except ValueError as e:
self.logger.error(f"{e}... switching to float strategy")
self.logger.error(f'{e}... switching to float strategy')
context.strategy = FloatStrategy(target, param, val)
context.run()
case _:
self.logger.error(
f"unable to determine the kind of parameter from {cmd_parsed}"
f'unable to determine the kind of parameter from {cmd_parsed}'
)
time.sleep(0.05)
return res
@@ -166,7 +166,7 @@ class Parser:
def interactive_mode(parser):
while cmd := input("Please enter command (Press <Enter> to exit)\n"):
while cmd := input('Please enter command (Press <Enter> to exit)\n'):
if res := parser.parse((cmd,)):
print(res)
@@ -184,7 +184,7 @@ def main():
)
# fmt: on
with voicemeeterlib.api("potato") as vm:
with voicemeeterlib.api('potato') as vm:
parser = Parser(vm)
if args.i:
interactive_mode(parser)
@@ -194,5 +194,5 @@ def main():
print(res)
if __name__ == "__main__":
if __name__ == '__main__':
main()