Skip to content

Commit

Permalink
nice commented missing Args
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Sep 25, 2023
1 parent d425b4e commit 3b76cd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
28 changes: 14 additions & 14 deletions builder2ibek.support.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@
is_int_re = re.compile(r"[-+]?\d+$")
is_float_re = re.compile(r"[-+]?\d*\.\d+([eE][-+]?\d+)?$")

# this monster regex finds strings between '' or "" (oh boy!)
# this monster regex finds strings between '' or "" (just wow!)

# this monster regex finds strings between '' or "" (oh boy!)
extract_printed_strings_re = re.compile(r"([\"'])((?:\\\1|(?:(?!\1))[\S\s])*)(?:\1)")
# match substitution fields in print statements e.g. %(name)s or {name:s} etc
macros_re = re.compile(r"%\((.*?)\).|{(.*?)(?:\:.)?}")
macros_re = re.compile(r"(?:(?:{)|(?:%\())([^:\)}]*)(?:(?:(?::.)?})|(?:\).))")
# replace matched fields with jinja2 style macros
macro_to_jinja_re = r"{{\1}}"

MISSING = "TODO - MISSING ARGS: "


class Builder2Support:
arg_value_overrides = {}
Expand Down Expand Up @@ -257,12 +256,12 @@ def _extract_substitutions(self, name):

database["file"] = template

database["args"] = {a[0]: None for a in first_substitution.args.items()}
db_args = {a[0]: None for a in first_substitution.args.items()}
missing = set(db_args) - set(self.def_args[name])
comment = MISSING + ", ".join(missing) if missing else None

database.insert(3, "args", db_args, comment=comment)

missing = set(database["args"].keys()) - set(self.def_args[name])
if len(missing) > 0:
missed = ", ".join(missing)
database["warning"] = "Database Args missing: " + missed
return databases

def _make_init_script(
Expand Down Expand Up @@ -295,12 +294,13 @@ def _make_init_script(
line = macros_re.sub(macro_to_jinja_re, matches[0][1])
commands += line + "\n"
if commands:
script_item["value"] = PreservedScalarString(commands)
script.append(script_item)
script_text = PreservedScalarString(commands)
missing = set(command_args) - set(self.def_args[name])
if len(missing) > 0:
missed = ", ".join(missing)
script_item["warning"] = "function Args missing: " + missed
comment = MISSING + ", ".join(missing) if missing else None

script_item.insert(3, "value", script_text, comment=comment)

script.append(script_item)

def _call_initialise(self, builder_object, name):
"""
Expand Down
16 changes: 14 additions & 2 deletions src/ibek/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@

import json
from enum import Enum
from typing import Any, Dict, Optional, Sequence, Union
from typing import Any, Dict, ForwardRef, Optional, Sequence, Union

from pydantic import Field
from pydantic import Field, PydanticUndefinedAnnotation
from typing_extensions import Literal

from .globals import BaseSettings

UndefinedType = ForwardRef("UndefinedType")


def default(T: type):
"""
defines a default type which may be
"""
return Field(
Union[Optional[T], PydanticUndefinedAnnotation],
description="If given, instance doesn't supply argument, what value should be used",
)


class When(Enum):
first = "first"
Expand Down

0 comments on commit 3b76cd2

Please sign in to comment.