Browse Source

Workaround module import

jk-bakalarka
Jiří Kalvoda 2 months ago
parent
commit
7ee84470e9
  1. 4
      src/formatitko/transform_processor.py

4
src/formatitko/transform_processor.py

@ -228,12 +228,12 @@ class TransformProcessor(NOPProcessor):
importedDoc = import_md(open(filename, "r").read())
self.transform(importedDoc.content)
elif e.attributes["type"] == "module":
matches = re.match(r"^(\w+)(?: as (\w+))?$", e.content[0].text[1:])
matches = re.match(r"^([\w\.]+)(?: as (\w+))?$", e.content[0].text[1:])
if not matches:
raise SyntaxError(f"`{e.content[0].text[1:]}`: invalid syntax")
module = importlib.import_module(matches.group(1))
module_name = matches.group(1) if matches.group(2) is None else matches.group(2)
self.context.add_commands_from_module(module, module_name)
self.context.add_commands_from_module(module, "")
elif e.attributes["type"] == "metadata":
filename = self.context.dir + "/" + e.content[0].text[1:]
self.context.add_dep(filename)

Loading…
Cancel
Save