Skip to content

Commit 14024ee

Browse files
committed
Remove misc.save_script_parameters()
Unfortunately the save_script_parameters() function doesn't work as intended as the `globals()` call returns the dictionary of the current module. Inside a function, this is the module where it is defined, not the module from which it is called as described in the built-in functions [API docs for Python 2.7]. Long story short, this call is getting the global symbol table of the `imcflibs` namespace instead of the one from the caller (which is what we'd need for the org.scijava.script.ScriptModule part. See #136 for the current plan / progress on this. [1]: https://docs.python.org/2.7/library/functions.html#globals
1 parent 9dc6b9f commit 14024ee

1 file changed

Lines changed: 0 additions & 53 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -737,56 +737,3 @@ def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
737737
else:
738738
timed_log("Error converting [%s]: %d" % (file_path, result))
739739

740-
741-
def save_script_parameters(destination, save_file_name="script_parameters.txt"):
742-
"""Save all Fiji script parameters to a text file.
743-
744-
Parameters
745-
----------
746-
destination : str
747-
Directory where the script parameters file will be saved.
748-
save_file_name : str, optional
749-
Name of the script parameters file, by default "script_parameters.txt".
750-
751-
Notes
752-
-----
753-
This function records all input parameters defined in the Fiji script header
754-
(e.g. `#@ String`) to a text file.
755-
756-
The following parameters are excluded:
757-
- Parameters explicitly declared with `style="password"` are ignored.
758-
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
759-
"""
760-
# Get the ScriptModule object from globals made by Fiji
761-
module = globals().get("org.scijava.script.ScriptModule")
762-
if module is None:
763-
timed_log("No ScriptModule found - skipping saving script parameters.")
764-
return
765-
766-
destination = str(destination)
767-
out_path = os.path.join(destination, save_file_name)
768-
769-
# Access script metadata and inputs
770-
script_info = module.getInfo()
771-
inputs = module.getInputs()
772-
773-
# Keys to skip explicitly
774-
skip_keys = ["USERNAME", "SJLOG", "COMMAND", "RM"]
775-
776-
with open(out_path, "w") as f:
777-
for item in script_info.inputs():
778-
key = item.getName()
779-
780-
# Skip if any keys are in the skip list
781-
if any(skip in key.upper() for skip in skip_keys):
782-
continue
783-
784-
# Skip if parameter is declared with password style
785-
if WidgetStyle.isStyle(item, TextWidget.PASSWORD_STYLE):
786-
continue
787-
788-
if inputs.containsKey(key):
789-
val = inputs.get(key)
790-
f.write("%s: %s\n" % (key, str(val)))
791-
792-
timed_log("Saved script parameters to: %s" % out_path)

0 commit comments

Comments
 (0)