Skip to content

Commit

Permalink
Fixed value of complex types
Browse files Browse the repository at this point in the history
  • Loading branch information
awicenec committed Apr 18, 2024
1 parent 10a9e3f commit ea8b55e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dlg_paletteGen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .cli import main # pragma: no cover

if __name__ == "__main__": # pragma: no cover
main()
palette = main()
12 changes: 8 additions & 4 deletions dlg_paletteGen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ def get_args(args=None):
)
if not args:
if len(sys.argv) == 1:
print("\x1b[31;20mInsufficient number of " + "arguments provided!!!\n\x1b[0m")
print(
"\x1b[31;20mInsufficient number of " + "arguments provided!!!\n\x1b[0m"
)
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
Expand Down Expand Up @@ -237,7 +239,7 @@ def palettes_from_module(
continue
filename = outfile if not split else f"{outfile}{m.replace('.','_')}.palette"
files[filename] = len(nodes)
prepare_and_write_palette(nodes, filename, module_doc=module_doc)
palette = prepare_and_write_palette(nodes, filename, module_doc=module_doc)
logger.info(
"%s palette file written with %s components\n%s",
filename,
Expand All @@ -248,6 +250,7 @@ def palettes_from_module(
"\n\n>>>>>>> Extraction summary <<<<<<<<\n%s\n",
"\n".join([f"Wrote {k} with {v} components" for k, v in files.items()]),
)
return palette


def main(): # pragma: no cover
Expand Down Expand Up @@ -283,7 +286,7 @@ def main(): # pragma: no cover

if len(module_path) > 0:
outputfile = "" if outputfile == "." else outputfile
palettes_from_module(
palette = palettes_from_module(
module_path, outfile=outputfile, recursive=recursive, split=split
)
else:
Expand All @@ -302,7 +305,8 @@ def main(): # pragma: no cover
nodes = process_compounddefs(
output_xml_filename, tag, allow_missing_eagle_start, language
)
prepare_and_write_palette(nodes, outputfile)
palette = prepare_and_write_palette(nodes, outputfile)
return
# cleanup the output directory
output_directory.cleanup()
return palette
24 changes: 18 additions & 6 deletions dlg_paletteGen/support_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ def write_palette_json(
# write palette to file
# logger.debug(">>> palette: %s", palette)
with open(output_filename, "w", encoding="utf-8") as outfile:
json.dump(palette, outfile, indent=4)
try:
json.dump(palette, outfile, indent=4)
return palette
except TypeError:
logger.error("Problem serializing palette! Bailing out!!")
return palette


def get_field_by_name(name: str, node, value_key: str = "") -> dict:
Expand Down Expand Up @@ -247,7 +252,7 @@ def prepare_and_write_palette(nodes: list, output_filename: str, module_doc: str
block_dag = build_block_dag(vertices, [], data_fields=BLOCKDAG_DATA_FIELDS)

# write the output json file
write_palette_json(
palette = write_palette_json(
output_filename,
module_doc,
f_nodes,
Expand All @@ -256,6 +261,7 @@ def prepare_and_write_palette(nodes: list, output_filename: str, module_doc: str
block_dag,
)
logger.debug("Wrote %s components to %s", len(nodes), output_filename)
return palette


def get_submodules(module):
Expand Down Expand Up @@ -378,7 +384,9 @@ def import_using_name(mod_name: str, traverse: bool = False):
mod = importlib.import_module(".".join(parts[:-1]))
break
except Exception as e:
raise ValueError("Problem importing module %s, %s" % (mod, e))
raise ValueError(
"Problem importing module %s, %s" % (mod, e)
)
logger.debug("Loaded module: %s", mod_name)
else:
logger.debug("Recursive import failed! %s", parts[0] in sys.modules)
Expand Down Expand Up @@ -464,7 +472,7 @@ def get_value_type_from_default(default):
except TypeError:
# this is a complex type
logger.debug("Object not JSON serializable: %s", value)
ptype = type(value).__name__
ptype = value = type(value).__name__
if not isinstance(value, (str, bool)) and (
ptype in ["Json"]
): # we want to carry these as strings
Expand Down Expand Up @@ -544,7 +552,9 @@ def populateFields(parameters: dict, dd, member=None) -> dict:
field[p]["type"] = param_desc["type"]
if isinstance(field[p]["value"], numpy.ndarray):
try:
field[p]["value"] = field[p]["defaultValue"] = field[p]["value"].tolist()
field[p]["value"] = field[p]["defaultValue"] = field[p][
"value"
].tolist()
except NotImplementedError:
field[p]["value"] = []
fields.update(field)
Expand Down Expand Up @@ -613,7 +623,9 @@ def populateDefaultFields(Node): # pylint: disable=invalid-name
et[n]["value"] = 2
et[n]["defaultValue"] = 2
et[n]["type"] = "Integer"
et[n]["description"] = "Estimate of execution time (in seconds) for this application."
et[n][
"description"
] = "Estimate of execution time (in seconds) for this application."
et[n]["parameterType"] = "ConstraintParameter"
Node["fields"].update(et)

Expand Down

0 comments on commit ea8b55e

Please sign in to comment.