Skip to content

Commit 5bb4368

Browse files
committed
Refactor code for improved readability and consistency in function signatures across multiple files
1 parent c388cf5 commit 5bb4368

File tree

8 files changed

+234
-57
lines changed

8 files changed

+234
-57
lines changed

lib/galaxy/managers/credentials.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def build_credentials_context_response(
4848
name=association.service_name,
4949
version=association.service_version,
5050
selected_group=SelectedGroupResponse(
51-
id=association.selected_group_id, name=association.selected_group_name
51+
id=association.selected_group_id,
52+
name=association.selected_group_name,
5253
),
5354
)
5455
service_credentials_list.append(service_credential)
@@ -189,27 +190,47 @@ def add_user_credentials(
189190
self.session.flush()
190191
return user_credentials.id
191192

192-
def update_group(self, credentials_group: CredentialsGroup, group_name: str) -> None:
193+
def update_group(
194+
self,
195+
credentials_group: CredentialsGroup,
196+
group_name: str,
197+
) -> None:
193198
credentials_group.name = group_name
194199
self.session.add(credentials_group)
195200

196-
def set_group_last_updated(self, credentials_group: CredentialsGroup) -> None:
201+
def set_group_last_updated(
202+
self,
203+
credentials_group: CredentialsGroup,
204+
) -> None:
197205
credentials_group.update_time = now()
198206
self.session.add(credentials_group)
199207

200-
def add_group(self, user_credentials_id: DecodedDatabaseIdField, group_name: str) -> DecodedDatabaseIdField:
208+
def add_group(
209+
self,
210+
user_credentials_id: DecodedDatabaseIdField,
211+
group_name: str,
212+
) -> DecodedDatabaseIdField:
201213
credentials_group = CredentialsGroup(name=group_name, user_credentials_id=user_credentials_id)
202214
self.session.add(credentials_group)
203215
self.session.flush()
204216
return credentials_group.id
205217

206-
def update_credential(self, credential: Credential, value: Optional[str] = None, is_secret: bool = False) -> None:
218+
def update_credential(
219+
self,
220+
credential: Credential,
221+
value: Optional[str] = None,
222+
is_secret: bool = False,
223+
) -> None:
207224
credential.is_set = bool(value)
208225
credential.value = value if not is_secret else None
209226
self.session.add(credential)
210227

211228
def add_credential(
212-
self, group_id: DecodedDatabaseIdField, name: str, value: Optional[str] = None, is_secret: bool = False
229+
self,
230+
group_id: DecodedDatabaseIdField,
231+
name: str,
232+
value: Optional[str] = None,
233+
is_secret: bool = False,
213234
) -> None:
214235
credential = Credential(
215236
group_id=group_id,

lib/galaxy/tool_util/verify/interactor.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ def stage_data_in_history(
185185
job[test_data["fname"]] = test_dict
186186
resolve_data = test_data_resolver.get_filename if test_data_resolver else None
187187
staging_interface.stage(
188-
"tool", history_id=history, job=job, use_path_paste=force_path_paste, resolve_data=resolve_data
188+
"tool",
189+
history_id=history,
190+
job=job,
191+
use_path_paste=force_path_paste,
192+
resolve_data=resolve_data,
189193
)
190194
staging_interface.handle_jobs()
191195
galaxy_interactor.uploads = job
@@ -200,6 +204,7 @@ class RunToolResponse(NamedTuple):
200204

201205

202206
class InteractorStagingInterface(StagingInterface):
207+
203208
def __init__(self, galaxy_interactor: "GalaxyInteractorApi", maxseconds: Optional[int], upload_async: bool) -> None:
204209
super().__init__()
205210
self.galaxy_interactor = galaxy_interactor
@@ -787,7 +792,10 @@ def adapt_collections(test_input: JsonTestCollectionDefDict) -> DataCollectionRe
787792
jobs = submit_response_object["jobs"]
788793
try:
789794
return RunToolResponse(
790-
inputs=inputs_tree, outputs=outputs, output_collections=output_collections, jobs=jobs
795+
inputs=inputs_tree,
796+
outputs=outputs,
797+
output_collections=output_collections,
798+
jobs=jobs,
791799
)
792800
except KeyError:
793801
message = (
@@ -1019,7 +1027,12 @@ def ensure_user_with_email(self, email, password=None):
10191027
# If remote user middleware is enabled - this endpoint consumes
10201028
# ``remote_user_email`` otherwise it requires ``email``, ``password``
10211029
# and ``username``.
1022-
data = dict(remote_user_email=email, email=email, password=password, username=username)
1030+
data = dict(
1031+
remote_user_email=email,
1032+
email=email,
1033+
password=password,
1034+
username=username,
1035+
)
10231036
test_user = self._post("users", data, key=admin_key, json=True).json()
10241037
return test_user
10251038

@@ -1235,7 +1248,9 @@ def prepare_request_params(
12351248
new_items[key] = dumps(val)
12361249
data.update(new_items)
12371250

1238-
kwd: Dict[str, Any] = {"files": files}
1251+
kwd: Dict[str, Any] = {
1252+
"files": files,
1253+
}
12391254
if headers:
12401255
kwd["headers"] = headers
12411256
if as_json:
@@ -1542,7 +1557,11 @@ def verify_tool(
15421557
if tool_version is None and "tool_version" in tool_test_dict:
15431558
tool_version = tool_test_dict.get("tool_version")
15441559

1545-
job_data: JobDataT = {"tool_id": tool_id, "tool_version": tool_version, "test_index": test_index}
1560+
job_data: JobDataT = {
1561+
"tool_id": tool_id,
1562+
"tool_version": tool_version,
1563+
"test_index": test_index,
1564+
}
15461565
client_config = client_test_config.get_test_config(job_data)
15471566
skip_message = None
15481567
if client_config is not None:

lib/galaxy/tool_util/verify/parse.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ def parse_tool_test_descriptions(
7878
validated_test_case = case_state(
7979
raw_test_dict, tool_parameter_bundle.parameters, profile, validate=True
8080
)
81-
request_and_schema = TestRequestAndSchema(validated_test_case.tool_state, tool_parameter_bundle)
81+
request_and_schema = TestRequestAndSchema(
82+
validated_test_case.tool_state,
83+
tool_parameter_bundle,
84+
)
8285
except Exception as e:
8386
validation_exception = e
8487

lib/galaxy/tools/actions/__init__.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ def process_dataset(data, formats=None):
339339
)
340340
collection_builder = CollectionBuilder(collection_type_description)
341341
collection_builder.replace_elements_in_collection(
342-
template_collection=collection, replacement_dict=processed_dataset_dict
342+
template_collection=collection,
343+
replacement_dict=processed_dataset_dict,
343344
)
344345
new_collection = collection_builder.build()
345346
if child_collection:
@@ -435,7 +436,7 @@ def _collect_inputs(self, tool, trans, incoming, history, current_user_roles, co
435436
for tag in collection.auto_propagated_tags:
436437
preserved_hdca_tags[tag.value] = tag
437438
preserved_tags.update(preserved_hdca_tags)
438-
return (history, inp_data, inp_dataset_collections, preserved_tags, preserved_hdca_tags, all_permissions)
439+
return history, inp_data, inp_dataset_collections, preserved_tags, preserved_hdca_tags, all_permissions
439440

440441
def execute(
441442
self,
@@ -468,9 +469,14 @@ def execute(
468469
if execution_cache is None:
469470
execution_cache = ToolExecutionCache(trans)
470471
current_user_roles = execution_cache.current_user_roles
471-
history, inp_data, inp_dataset_collections, preserved_tags, preserved_hdca_tags, all_permissions = (
472-
self._collect_inputs(tool, trans, incoming, history, current_user_roles, collection_info)
473-
)
472+
(
473+
history,
474+
inp_data,
475+
inp_dataset_collections,
476+
preserved_tags,
477+
preserved_hdca_tags,
478+
all_permissions,
479+
) = self._collect_inputs(tool, trans, incoming, history, current_user_roles, collection_info)
474480
assert history # tell type system we've set history and it is no longer optional
475481
# Build name for output datasets based on tool name and input names
476482
on_text = self._get_on_text(inp_data, inp_dataset_collections)
@@ -674,7 +680,12 @@ def handle_output(name, output, hidden=None):
674680
else:
675681
index = name_to_index[parent_id]
676682
current_element_identifiers = cast(
677-
list[dict[str, Union[str, list[dict[str, Union[str, list[Any]]]]]]],
683+
list[
684+
dict[
685+
str,
686+
Union[str, list[dict[str, Union[str, list[Any]]]]],
687+
]
688+
],
678689
current_element_identifiers[index]["element_identifiers"],
679690
)
680691

@@ -688,14 +699,20 @@ def handle_output(name, output, hidden=None):
688699
# Following hack causes dataset to no be added to history...
689700
trans.sa_session.add(element)
690701
current_element_identifiers.append(
691-
{"__object__": element, "name": output_part_def.element_identifier}
702+
{
703+
"__object__": element,
704+
"name": output_part_def.element_identifier,
705+
}
692706
)
693707

694708
if output.dynamic_structure:
695709
assert not element_identifiers # known_outputs must have been empty
696710
element_kwds = dict(elements=collections_manager.ELEMENTS_UNINITIALIZED)
697711
else:
698-
element_kwds = dict(element_identifiers=element_identifiers, fields=output.structure.fields)
712+
element_kwds = dict(
713+
element_identifiers=element_identifiers,
714+
fields=output.structure.fields,
715+
)
699716
output_collections.create_collection(
700717
output=output, name=name, completed_job=completed_job, **element_kwds
701718
)
@@ -705,7 +722,8 @@ def handle_output(name, output, hidden=None):
705722
log.info(f"Handled output named {name} for tool {tool.id} {handle_output_timer}")
706723

707724
add_datasets_timer = tool.app.execution_timer_factory.get_timer(
708-
"internals.galaxy.tools.actions.add_datasets", "Added output datasets to history"
725+
"internals.galaxy.tools.actions.add_datasets",
726+
"Added output datasets to history",
709727
)
710728
# Add all the top-level (non-child) datasets to the history unless otherwise specified
711729
for name, data in out_data.items():

lib/galaxy/tools/evaluation.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def add_error(self, file, phase, exception):
117117

118118

119119
class ToolTemplatingException(Exception):
120+
120121
def __init__(self, *args: object, tool_id: Optional[str], tool_version: str, is_latest: bool) -> None:
121122
super().__init__(*args)
122123
self.tool_id = tool_id
@@ -208,11 +209,21 @@ def set_compute_environment(self, compute_environment: ComputeEnvironment, get_s
208209
incoming.update(model.User.user_template_environment(self._user))
209210

210211
# Build params, done before hook so hook can use
211-
self.param_dict = self.build_param_dict(incoming, inp_data, out_data, output_collections=out_collections)
212+
self.param_dict = self.build_param_dict(
213+
incoming,
214+
inp_data,
215+
out_data,
216+
output_collections=out_collections,
217+
)
212218
self.execute_tool_hooks(inp_data=inp_data, out_data=out_data, incoming=incoming)
213219

214220
else:
215-
self.param_dict = self.build_param_dict(incoming, inp_data, out_data, output_collections=out_collections)
221+
self.param_dict = self.build_param_dict(
222+
incoming,
223+
inp_data,
224+
out_data,
225+
output_collections=out_collections,
226+
)
216227

217228
def execute_tool_hooks(self, inp_data: InpDataDictT, out_data: OutDataDictT, incoming):
218229
# Certain tools require tasks to be completed prior to job execution
@@ -376,7 +387,11 @@ def validate_inputs(input, value, context, **kwargs):
376387

377388
visit_input_values(self.tool.inputs, incoming, validate_inputs)
378389

379-
def _deferred_objects(self, input_datasets: InpDataDictT, incoming: dict) -> dict[str, DeferrableObjectsT]:
390+
def _deferred_objects(
391+
self,
392+
input_datasets: InpDataDictT,
393+
incoming: dict,
394+
) -> dict[str, DeferrableObjectsT]:
380395
"""Collect deferred objects required for execution.
381396
382397
Walk input datasets and collections and find inputs that need to be materialized.
@@ -460,6 +475,7 @@ def do_walk(inputs, input_values):
460475
do_walk(inputs, input_values)
461476

462477
def __populate_wrappers(self, param_dict, input_datasets, job_working_directory):
478+
463479
element_identifier_mapper = ElementIdentifierMapper(input_datasets)
464480

465481
def wrap_input(input_values, input):
@@ -709,7 +725,12 @@ def build(self):
709725
global_tool_logs(
710726
self._create_interactivetools_entry_points, config_file, "Building Interactive Tool Entry Points", self.tool
711727
)
712-
global_tool_logs(self._build_config_files, config_file, "Building Config Files", self.tool)
728+
global_tool_logs(
729+
self._build_config_files,
730+
config_file,
731+
"Building Config Files",
732+
self.tool,
733+
)
713734
global_tool_logs(self._build_param_file, config_file, "Building Param File", self.tool)
714735
global_tool_logs(self._build_command_line, config_file, "Building Command Line", self.tool)
715736
global_tool_logs(self._build_version_command, config_file, "Building Version Command Line", self.tool)
@@ -1024,6 +1045,7 @@ def build(self):
10241045

10251046

10261047
class UserToolEvaluator(ToolEvaluator):
1048+
10271049
param_dict_style = "json"
10281050

10291051
def _build_config_files(self):

0 commit comments

Comments
 (0)