Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subconverter stubbing #870

Merged
merged 11 commits into from
Aug 13, 2024
81 changes: 62 additions & 19 deletions src/pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,25 +920,67 @@ def update_conversion_progress(message):
)

# Assume all interfaces have the same conversion options for now
available_options = converter.get_conversion_options_schema()
options = {interface: {} for interface in info["source_data"]}

for interface in options:
available_opts = available_options.get("properties").get(interface).get("properties", {})

# Specify if stub test
if run_stub_test:
if available_opts.get("stub_test"):
options[interface]["stub_test"] = True

# Specify if iterator options are available
elif available_opts.get("iterator_opts"):
options[interface]["iterator_opts"] = dict(
display_progress=True,
progress_bar_class=TQDMProgressSubscriber,
progress_bar_options=progress_bar_options,
conversion_options_schema = converter.get_conversion_options_schema()
conversion_options = {interface: dict() for interface in info["source_data"]}

# print(f"{run_stub_test=}")
# print("\n")
# print(f"{conversion_options_schema=}")
# print("\n")
# print(f"{conversion_options=}")
# print("\n")

for interface_or_subconverter in conversion_options:
conversion_options_schema_per_interface_or_converter = conversion_options_schema.get(
"properties", dict()
).get(interface_or_subconverter, dict())

# Object is a nested converter
if conversion_options_schema_per_interface_or_converter.get("title", "") == "Conversion options schema":
subconverter = interface_or_subconverter

conversion_options_schema_per_subinterface = conversion_options_schema_per_interface_or_converter.get(
"properties", dict()
)

for subinterface, subschema in conversion_options_schema_per_subinterface.items():
conversion_options[subconverter][subinterface] = dict()
options_to_update = conversion_options[subconverter][subinterface]

properties_per_subinterface = subschema.get("properties", dict())

if run_stub_test is True and "stub_test" in properties_per_subinterface:
options_to_update["stub_test"] = True

# Only display per-file progress updates if not running a preview
if run_stub_test is False and "iterator_opts" in properties_per_subinterface:
options_to_update["iterator_opts"] = dict(
display_progress=True,
progress_bar_class=TQDMProgressSubscriber,
progress_bar_options=progress_bar_options,
)

# Object is a standard interface
else:
interface = interface_or_converter

conversion_options_schema_per_interface = options_per_interface_or_converter.get("properties", dict())
options_to_update = conversion_options[interface]

if run_stub_test is True and "stub_test" in conversion_options_schema_per_interface:
options_to_update[interface]["stub_test"] = True

# Only display per-file progress updates if not running a preview
if run_stub_test is False and "iterator_opts" in conversion_options_schema_per_interface:
options_to_update[interface]["iterator_opts"] = dict(
display_progress=True,
progress_bar_class=TQDMProgressSubscriber,
progress_bar_options=progress_bar_options,
)

print(f"{conversion_options=}")
print("\n")

# Add GUIDE watermark
package_json_file_path = resource_path("package.json" if is_packaged() else "../package.json")
with open(file=package_json_file_path) as fp:
Expand All @@ -951,11 +993,12 @@ def update_conversion_progress(message):
metadata=metadata,
nwbfile_path=nwbfile_path,
overwrite=overwrite,
conversion_options=options,
conversion_options=conversion_options,
backend=backend,
)

if not run_stub_test:
# Only set full backend configuration if running a full conversion
if run_stub_test is False:
run_conversion_kwargs.update(dict(backend_configuration=update_backend_configuration(info)))

converter.run_conversion(**run_conversion_kwargs)
Expand Down
Loading