Skip to content

Add flag parameter support for TOPP tools#397

Open
hjn0415a wants to merge 1 commit into
OpenMS:mainfrom
hjn0415a:main
Open

Add flag parameter support for TOPP tools#397
hjn0415a wants to merge 1 commit into
OpenMS:mainfrom
hjn0415a:main

Conversation

@hjn0415a

@hjn0415a hjn0415a commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added a flag_parameters argument to input_TOPP() so specific parameters can be designated as CLI flags (e.g. -force, -no_progress) that are passed by presence only, without a value
  • The specified flag list is saved in both params.json (_flag_params) and session_state["_topp_flag_params"], so it can be restored from params.json even after a session restart

Changes

  • src/workflow/StreamlitUI.py
    • Added a flag_parameters: List[str] = [] parameter to input_TOPP()
    • Stores the per-instance flag list in both _topp_flag_params (session_state) and _flag_params (params.json)
  • src/workflow/CommandExecutor.py
    • In run_topp(), loads the flag list from params.json first, falling back to session_state if not found
    • Split the merged_params / custom_params command-building logic so flag parameters are added as -key only when truthy, while all other parameters keep the existing behavior

Summary by CodeRabbit

  • New Features
    • Added support for boolean command-line flags in workflow tool configuration.
    • Flags are included only when enabled, while empty optional parameters are omitted.
    • Flag settings are retained for future workflow executions.
    • Existing support for multiline and list-based parameter values remains available.

Allows input_TOPP() to designate parameters as flags (present/absent)
instead of key-value pairs, persisted to params.json and session_state
so run_topp() can correctly build the command line.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

TOPP input handling now accepts and persists boolean flag parameter names. Command construction loads these definitions and emits enabled flags without values, while omitting disabled or empty parameters and preserving list and multiline expansion.

Changes

TOPP Flag Parameters

Layer / File(s) Summary
Persist flag parameter definitions
src/workflow/StreamlitUI.py
input_TOPP accepts flag parameter names and stores them in session state and params.json for each tool instance.
Construct flag-aware TOPP commands
src/workflow/CommandExecutor.py
run_topp loads flag definitions, emits enabled boolean flags, omits disabled or empty parameters, and retains multiline and list expansion for regular parameters.

Suggested reviewers: copilot

Poem

I’m a rabbit with flags in my ear,
Hopping through commands bright and clear.
Empty values fade, true flags appear,
Lists and newlines march without fear.
- Thump, thump, the workflow is here!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding boolean flag parameter support for TOPP tools.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/workflow/StreamlitUI.py (1)

827-833: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid mutable data structures for argument defaults.

Using mutable defaults like [] or {} can lead to unexpected behavior since the same instance is shared across all function calls. While they aren't mutated in this specific method, it's best practice to default to None and initialize the mutable structures within the function body.

♻️ Proposed refactor
-        exclude_parameters: List[str] = [],
-        include_parameters: List[str] = [],
-        flag_parameters: List[str] = [],
+        exclude_parameters: List[str] = None,
+        include_parameters: List[str] = None,
+        flag_parameters: List[str] = None,
         display_tool_name: bool = True,
         display_subsections: bool = True,
         display_subsection_tabs: bool = False,
-        custom_defaults: dict = {},
+        custom_defaults: dict = None,

(Note: Ensure you also initialize these to empty lists/dicts inside the function if they are None)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workflow/StreamlitUI.py` around lines 827 - 833, Update the affected
function’s exclude_parameters, include_parameters, flag_parameters, and
custom_defaults arguments to default to None instead of mutable list or
dictionary instances, then initialize each to an empty list or dictionary inside
the function when it is None. Preserve the existing behavior for callers that
provide values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/workflow/CommandExecutor.py`:
- Around line 308-315: The non-flag parameter loops in CommandExecutor must omit
empty lists and expand non-empty lists into separate CLI arguments. In
src/workflow/CommandExecutor.py lines 308-315, update the skip condition and add
list handling before scalar conversion; apply the same empty-list skip condition
in lines 326-332, while preserving existing string newline handling.
- Around line 274-278: Update the flag parameter selection in the relevant
CommandExecutor method so the fallback from st.session_state is evaluated when
flag_map has no entry for the current params_key, not only when the entire flag
map is empty. Preserve any existing params.json flags for that tool and
construct flag_params from the selected per-tool values.

---

Nitpick comments:
In `@src/workflow/StreamlitUI.py`:
- Around line 827-833: Update the affected function’s exclude_parameters,
include_parameters, flag_parameters, and custom_defaults arguments to default to
None instead of mutable list or dictionary instances, then initialize each to an
empty list or dictionary inside the function when it is None. Preserve the
existing behavior for callers that provide values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e933d71a-162b-4d6e-8e2d-e337f259b1f6

📥 Commits

Reviewing files that changed from the base of the PR and between 2b8cda2 and 268348f.

📒 Files selected for processing (2)
  • src/workflow/CommandExecutor.py
  • src/workflow/StreamlitUI.py

Comment on lines +274 to +278
flag_map = self.parameter_manager.get_parameters_from_json().get("_flag_params", {})
if not flag_map:
flag_map = st.session_state.get("_topp_flag_params", {})
flag_params: set = set(flag_map.get(params_key, []))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Fix the per-tool fallback logic for flag parameters.

The current logic falls back to st.session_state only if _flag_params is completely missing or empty in params.json. If another tool has saved its flags, flag_map evaluates to True, and the fallback won't be evaluated for the current tool (params_key), potentially ignoring its session state flags.

Evaluate the fallback at the params_key level instead.

💻 Proposed fix
-        flag_map = self.parameter_manager.get_parameters_from_json().get("_flag_params", {})
-        if not flag_map:
-            flag_map = st.session_state.get("_topp_flag_params", {})
-        flag_params: set = set(flag_map.get(params_key, []))
+        flag_map = self.parameter_manager.get_parameters_from_json().get("_flag_params", {})
+        
+        flag_list = flag_map.get(params_key)
+        if flag_list is None:
+            flag_list = st.session_state.get("_topp_flag_params", {}).get(params_key, [])
+            
+        flag_params: set = set(flag_list)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
flag_map = self.parameter_manager.get_parameters_from_json().get("_flag_params", {})
if not flag_map:
flag_map = st.session_state.get("_topp_flag_params", {})
flag_params: set = set(flag_map.get(params_key, []))
flag_map = self.parameter_manager.get_parameters_from_json().get("_flag_params", {})
flag_list = flag_map.get(params_key)
if flag_list is None:
flag_list = st.session_state.get("_topp_flag_params", {}).get(params_key, [])
flag_params: set = set(flag_list)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workflow/CommandExecutor.py` around lines 274 - 278, Update the flag
parameter selection in the relevant CommandExecutor method so the fallback from
st.session_state is evaluated when flag_map has no entry for the current
params_key, not only when the entire flag map is empty. Preserve any existing
params.json flags for that tool and construct flag_params from the selected
per-tool values.

Comment on lines +308 to +315
# Regular parameter: skip empty/None, append value otherwise
if v == "" or v is None:
continue
command += [f"-{k}"]
if isinstance(v, str) and "\n" in v:
command += v.split("\n")
else:
command += [str(v)]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix list handling and omit empty lists in command construction. Both loops formatting non-flag parameters (merged_params and custom_params) incorrectly process list values. merged_params converts list objects into string representations (e.g., "['a', 'b']") instead of expanding them as distinct CLI arguments. Additionally, both loops fail to skip empty lists ([]), which causes them to append a flag (e.g. -k) without providing a corresponding value, leading to TOPP parsing errors.

  • src/workflow/CommandExecutor.py#L308-L315: Update the skip condition to omit empty lists (v == "" or v is None or (isinstance(v, list) and not v)) and add an elif isinstance(v, list): command += [str(x) for x in v] block to properly expand list values.
  • src/workflow/CommandExecutor.py#L326-L332: Update the skip condition to identically omit empty lists (if v == "" or v is None or (isinstance(v, list) and not v):).
📍 Affects 1 file
  • src/workflow/CommandExecutor.py#L308-L315 (this comment)
  • src/workflow/CommandExecutor.py#L326-L332
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/workflow/CommandExecutor.py` around lines 308 - 315, The non-flag
parameter loops in CommandExecutor must omit empty lists and expand non-empty
lists into separate CLI arguments. In src/workflow/CommandExecutor.py lines
308-315, update the skip condition and add list handling before scalar
conversion; apply the same empty-list skip condition in lines 326-332, while
preserving existing string newline handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant