Skip to content

Commit 3c96d1f

Browse files
committed
fix: cleanup workflow section code
- Fix critical variable shadowing bug in CommandExecutor.py where loop variable `i` was overwritten inside the loop, causing incorrect file indexing when processing multiple input files - Remove redundant if/else in FileManager._set_dir() that called the same function in both branches - Remove commented-out dead code in StreamlitUI.py and Logger.py - Fix docstring typo in Logger.py ("input_widgetThis" -> "This") - Remove unnecessary empty markdown heading used for checkbox spacing - Fix bare except clause in ParameterManager.py to catch specific exceptions (JSONDecodeError, IOError, OSError) https://claude.ai/code/session_01LaYLob1uWygBXmUS2JRKmH
1 parent 9d584de commit 3c96d1f

5 files changed

Lines changed: 9 additions & 20 deletions

File tree

src/workflow/CommandExecutor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ def run_topp(self, tool: str, input_output: dict, custom_params: dict = {}) -> b
273273
# get value from input_output dictionary
274274
value = input_output[k]
275275
# when multiple input/output files exist (e.g., multiple mzMLs and featureXMLs), but only one additional input file (e.g., one input database file)
276-
if len(value) == 1:
277-
i = 0
276+
# use index 0 for single-item lists, otherwise use the loop index
277+
idx = 0 if len(value) == 1 else i
278278
# when the entry is a list of collected files to be passed as one [["sample1", "sample2"]]
279-
if isinstance(value[i], list):
280-
command += value[i]
279+
if isinstance(value[idx], list):
280+
command += value[idx]
281281
# standard case, files was a list of strings, take the file name at index
282282
else:
283-
command += [value[i]]
283+
command += [value[idx]]
284284
# Add non-default TOPP tool parameters
285285
if tool in params.keys():
286286
for k, v in params[tool].items():

src/workflow/FileManager.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ def _set_dir(self, files: List[str], subdir_name: str) -> List[str]:
123123
Returns:
124124
List[str]: The files list with new directory.
125125
"""
126-
if not subdir_name:
127-
subdir_name = self._create_results_sub_dir(subdir_name)
128-
else:
129-
subdir_name = self._create_results_sub_dir(subdir_name)
126+
subdir_name = self._create_results_sub_dir(subdir_name)
130127

131128
def change_subdir(file_path, subdir):
132129
return Path(subdir, Path(file_path).name)

src/workflow/Logger.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Logger:
44
"""
5-
A simple logging class for writing messages to a log file. input_widgetThis class is designed
5+
A simple logging class for writing messages to a log file. This class is designed
66
to append messages to a log file in the current workflow directory, facilitating
77
easy tracking of events, errors, or other significant occurrences in processes called
88
during workflow execution.
@@ -35,8 +35,4 @@ def log(self, message: str, level: int = 0) -> None:
3535
f.write(f"{message}\n\n")
3636
if level <= 2:
3737
with open(Path(log_dir, "all.log"), "a", encoding="utf-8") as f:
38-
f.write(f"{message}\n\n")
39-
# log_types = ["minimal", "commands and run times", "tool outputs", "all"]
40-
# for i, log_type in enumerate(log_types):
41-
# with open(Path(log_dir, f"{log_type.replace(" ", "-")}.log"), "a", encoding="utf-8") as f:
42-
# f.write(f"{message}\n\n")
38+
f.write(f"{message}\n\n")

src/workflow/ParameterManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_parameters_from_json(self) -> dict:
126126
try:
127127
with open(self.params_file, "r", encoding="utf-8") as f:
128128
return json.load(f)
129-
except:
129+
except (json.JSONDecodeError, IOError, OSError):
130130
st.error("**ERROR**: Attempting to load an invalid JSON parameter file. Reset to defaults.")
131131
return {}
132132

src/workflow/StreamlitUI.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ def upload_widget(
163163

164164
# Local file upload option: via directory path
165165
if st.session_state.location == "local":
166-
# c2_text, c2_checkbox = c2.columns([1.5, 1], gap="large")
167-
# c2_text.markdown("**OR add files from local folder**")
168-
# use_copy = c2_checkbox.checkbox("Make a copy of files", key=f"{key}-copy_files", value=True, help="Create a copy of files in workspace.")
169166
with c2.container(border=True):
170167
st_cols = st.columns([0.05, 0.55], gap="small")
171168
with st_cols[0]:
@@ -812,7 +809,6 @@ def display_TOPP_params(params: dict, num_cols):
812809
p["value"] = p["value"].split("\n")
813810
# bools
814811
if isinstance(p["value"], bool):
815-
cols[i].markdown("##")
816812
cols[i].checkbox(
817813
name,
818814
value=(

0 commit comments

Comments
 (0)