From 5ef4ac32cb39c3d2f9e205175d6ccc5a3d9f58ac Mon Sep 17 00:00:00 2001 From: Lin Guo Date: Wed, 29 Jan 2025 23:58:41 -0800 Subject: [PATCH] Clean up unused variables ``` pylint --disable=all --enable=W0612 lib/ramble/ramble/* ``` --- lib/ramble/ramble/application.py | 16 ++++++++-------- lib/ramble/ramble/cmd/commands.py | 2 +- lib/ramble/ramble/cmd/config.py | 2 +- lib/ramble/ramble/cmd/license.py | 2 +- lib/ramble/ramble/config.py | 2 +- lib/ramble/ramble/fetch_strategy.py | 2 +- lib/ramble/ramble/main.py | 2 +- lib/ramble/ramble/package_manager.py | 2 +- lib/ramble/ramble/pipeline.py | 14 +++++++------- lib/ramble/ramble/reports.py | 6 +++--- lib/ramble/ramble/repository.py | 8 ++++---- lib/ramble/ramble/spec.py | 2 +- lib/ramble/ramble/test/application_tests.py | 4 ++-- lib/ramble/ramble/test/cmd/workspace.py | 4 ++-- lib/ramble/ramble/test/stage.py | 4 +--- lib/ramble/ramble/util/logger.py | 6 +++--- lib/ramble/ramble/util/naming.py | 10 +++++----- lib/ramble/ramble/util/web.py | 2 +- lib/ramble/ramble/util/yaml_generation.py | 2 +- lib/ramble/ramble/workload.py | 4 ++-- lib/ramble/ramble/workspace/workspace.py | 4 ++-- 21 files changed, 49 insertions(+), 51 deletions(-) diff --git a/lib/ramble/ramble/application.py b/lib/ramble/ramble/application.py index d3ee1d488..b8e50bd97 100644 --- a/lib/ramble/ramble/application.py +++ b/lib/ramble/ramble/application.py @@ -333,22 +333,22 @@ def build_phase_order(self): for mod_inst in self._modifier_instances: # Define phase nodes - for phase, phase_node in mod_inst.all_pipeline_phases(pipeline): + for _, phase_node in mod_inst.all_pipeline_phases(pipeline): self._pipeline_graphs[pipeline].add_node(phase_node, obj_inst=mod_inst) # Define phase edges - for phase, phase_node in mod_inst.all_pipeline_phases(pipeline): + for _, phase_node in mod_inst.all_pipeline_phases(pipeline): self._pipeline_graphs[pipeline].define_edges(phase_node, internal_order=True) if self.package_manager: # Define phase nodes - for phase, phase_node in self.package_manager.all_pipeline_phases(pipeline): + for _, phase_node in self.package_manager.all_pipeline_phases(pipeline): self._pipeline_graphs[pipeline].add_node( phase_node, obj_inst=self.package_manager ) # Define phase edges - for phase, phase_node in self.package_manager.all_pipeline_phases(pipeline): + for _, phase_node in self.package_manager.all_pipeline_phases(pipeline): self._pipeline_graphs[pipeline].define_edges(phase_node, internal_order=True) def set_env_variable_sets(self, env_variable_sets): @@ -369,7 +369,7 @@ def set_variables(self, variables, experiment_set): self.no_expand_vars = set() workload_name = self.expander.workload_name if workload_name in self.workloads: - for name, var in self.workloads[workload_name].variables.items(): + for var in self.workloads[workload_name].variables.values(): if not var.expandable: self.no_expand_vars.add(var.name) @@ -1000,7 +1000,7 @@ def _set_default_experiment_variables(self): workload = self.workloads[self.expander.workload_name] new_env_vars = {} - for name, env_var in workload.environment_variables.items(): + for env_var in workload.environment_variables.values(): action = "set" value = env_var.value @@ -1504,7 +1504,7 @@ def populate_inventory(self, workspace, force_compute=False, require_exist=False # Build inventory of inputs self._inputs_and_fetchers(self.expander.workload_name) - for input_file, input_conf in self._input_fetchers.items(): + for input_conf in self._input_fetchers.values(): if input_conf["fetcher"].digest: self.hash_inventory["inputs"].append( {"name": input_conf["input_name"], "digest": input_conf["fetcher"].digest} @@ -1587,7 +1587,7 @@ def _archive_experiments(self, workspace, app_inst=None): # Copy all figure of merit files criteria_list = workspace.success_list analysis_files, _, _ = self._analysis_dicts(criteria_list) - for file, file_conf in analysis_files.items(): + for file in analysis_files.keys(): if os.path.exists(file): shutil.copy(file, archive_experiment_dir) diff --git a/lib/ramble/ramble/cmd/commands.py b/lib/ramble/ramble/cmd/commands.py index 0602e189d..fc2576c8c 100644 --- a/lib/ramble/ramble/cmd/commands.py +++ b/lib/ramble/ramble/cmd/commands.py @@ -306,7 +306,7 @@ def update_completion(parser, args): times, and to simplify completion update for developers. """ - for shell, shell_args in update_completion_args.items(): + for shell_args in update_completion_args.values(): for attr, value in shell_args.items(): setattr(args, attr, value) _commands(parser, args) diff --git a/lib/ramble/ramble/cmd/config.py b/lib/ramble/ramble/cmd/config.py index 4dbcce412..d1fc815a9 100644 --- a/lib/ramble/ramble/cmd/config.py +++ b/lib/ramble/ramble/cmd/config.py @@ -209,7 +209,7 @@ def config_add(args): setup_parser.add_parser.print_help() exit(1) - scope, section = _get_scope_and_section(args) + scope, _ = _get_scope_and_section(args) if args.file: ramble.config.add_from_file(args.file, scope=scope) diff --git a/lib/ramble/ramble/cmd/license.py b/lib/ramble/ramble/cmd/license.py index 529b5a95d..eefe7184a 100644 --- a/lib/ramble/ramble/cmd/license.py +++ b/lib/ramble/ramble/cmd/license.py @@ -88,7 +88,7 @@ def _all_ramble_files(root=ramble.paths.prefix, modified_only=False): yield from _get_modified_files(root) else: visited = set() - for cur_root, folders, files in os.walk(root): + for cur_root, _, files in os.walk(root): for filename in files: path = os.path.realpath(os.path.join(cur_root, filename)) diff --git a/lib/ramble/ramble/config.py b/lib/ramble/ramble/config.py index d22738931..5ed8d43b0 100644 --- a/lib/ramble/ramble/config.py +++ b/lib/ramble/ramble/config.py @@ -474,7 +474,7 @@ def push_scope(self, scope): @_config_mutator def pop_scope(self): """Remove the highest precedence scope and return it.""" - name, scope = self.scopes.popitem(last=True) + _, scope = self.scopes.popitem(last=True) return scope @_config_mutator diff --git a/lib/ramble/ramble/fetch_strategy.py b/lib/ramble/ramble/fetch_strategy.py index f06a581ec..6963ab0ae 100644 --- a/lib/ramble/ramble/fetch_strategy.py +++ b/lib/ramble/ramble/fetch_strategy.py @@ -355,7 +355,7 @@ def _existing_url(self, url): else: # Telling urllib to check if url is accessible try: - url, headers, response = ramble.util.web.read_from_url(url) + url, _, response = ramble.util.web.read_from_url(url) except ramble.util.web.SpackWebError as werr: msg = "Urllib fetch failed to verify url\ {}\n with error {}".format( diff --git a/lib/ramble/ramble/main.py b/lib/ramble/ramble/main.py index 96d463297..f719598af 100644 --- a/lib/ramble/ramble/main.py +++ b/lib/ramble/ramble/main.py @@ -808,7 +808,7 @@ def _main(argv=None): # them, which reduces startup latency. parser = make_argument_parser() parser.add_argument("command", nargs=argparse.REMAINDER) - args, unknown = parser.parse_known_args(argv) + args, _ = parser.parse_known_args(argv) # Recover stored LD_LIBRARY_PATH variables from ramble shell function # This is necessary because MacOS System Integrity Protection clears diff --git a/lib/ramble/ramble/package_manager.py b/lib/ramble/ramble/package_manager.py index 9b259f24e..7b5a58e42 100644 --- a/lib/ramble/ramble/package_manager.py +++ b/lib/ramble/ramble/package_manager.py @@ -90,7 +90,7 @@ def package_manager_dir(self, workspace): def environment_required(self): app_inst = self.app_inst if hasattr(app_inst, "software_specs"): - for pkg, info in app_inst.software_specs.items(): + for info in app_inst.software_specs.values(): if fnmatch.fnmatch(self.name, info["package_manager"]): return True diff --git a/lib/ramble/ramble/pipeline.py b/lib/ramble/ramble/pipeline.py index 7c0a2c174..ec720deea 100644 --- a/lib/ramble/ramble/pipeline.py +++ b/lib/ramble/ramble/pipeline.py @@ -78,7 +78,7 @@ def _construct_experiment_hashes(self): Populate the workspace inventory information with experiment hash data. """ - for exp, app_inst, _ in self._experiment_set.all_experiments(): + for _, app_inst, _ in self._experiment_set.all_experiments(): app_inst.populate_inventory( self.workspace, force_compute=self.force_inventory, @@ -378,7 +378,7 @@ def _prepare(self): excluded_secrets.add(ramble.application.ApplicationBase.license_inc_name) fs.mkdirp(archive_shared) - for root, dirs, files in os.walk(self.workspace.shared_dir): + for root, _, files in os.walk(self.workspace.shared_dir): for name in files: if name not in excluded_secrets: src_dir = os.path.join(self.workspace.shared_dir, root) @@ -392,7 +392,7 @@ def _prepare(self): self.workspace.latest_archive_path, ramble.workspace.workspace_log_path ) fs.mkdirp(archive_logs) - for root, dirs, files in os.walk(self.workspace.log_dir): + for root, _, files in os.walk(self.workspace.log_dir): for name in files: src_dir = os.path.join(self.workspace.log_dir, root) src = os.path.join(src_dir, name) @@ -561,7 +561,7 @@ def _execute(self): if not self.suppress_run_header: logger.all_msg("Running executors...") - for exp, app_inst, idx in self._experiment_set.filtered_experiments(self.filters): + for _, app_inst, _ in self._experiment_set.filtered_experiments(self.filters): if app_inst.is_template: logger.debug(f"{app_inst.name} is a template. Skipping execution.") continue @@ -617,7 +617,7 @@ def print_archive_files(app_inst, pattern_title, patterns): if not self.suppress_run_header: logger.all_msg("Finding log information...") - for exp, app_inst, idx in self._experiment_set.filtered_experiments(self.filters): + for exp, app_inst, _ in self._experiment_set.filtered_experiments(self.filters): if app_inst.is_template: continue if app_inst.repeats.is_repeat_base: @@ -706,7 +706,7 @@ def _execute(self): def _deployment_files(self): """Yield the full path to each file in a deployment""" - for root, dirs, files in os.walk(self.workspace.named_deployment): + for root, _, files in os.walk(self.workspace.named_deployment): for name in files: yield os.path.join(self.workspace.named_deployment, root, name) @@ -752,7 +752,7 @@ def _complete(self): def _copy_tree(src_dir, dest_dir): """Copy all files in src_dir to dest_dir""" - for root, dirs, files in os.walk(src_dir): + for root, _, files in os.walk(src_dir): for name in files: src = os.path.join(src_dir, root, name) dest = src.replace(src_dir, dest_dir) diff --git a/lib/ramble/ramble/reports.py b/lib/ramble/ramble/reports.py index 26bcae926..eb555c693 100644 --- a/lib/ramble/ramble/reports.py +++ b/lib/ramble/ramble/reports.py @@ -330,7 +330,7 @@ def draw(self, perf_measure, scale_var, series, pdf_report, y_label=None): marker="o", label=f"{perf_measure}", ) - ymin, ymax = ax.get_ylim() + _, ymax = ax.get_ylim() # TODO: the plot can get very compressed for log weak scaling plots if not self.logy: @@ -812,7 +812,7 @@ def draw_multiline(self, perf_measure, scale_var, pdf_report, y_label): alpha=0.2, ) - ymin, ymax = ax.get_ylim() + _, ymax = ax.get_ylim() # TODO: the plot can get very compressed for log weak scaling plots if not self.logy: @@ -835,7 +835,7 @@ def draw_multiline(self, perf_measure, scale_var, pdf_report, y_label): def generate_plot_data(self, pdf_report): super().generate_plot_data(pdf_report) - perf_measure, scale_var, *additional_vars = self.spec + perf_measure, scale_var, *_ = self.spec y_label = perf_measure self.draw_multiline(perf_measure, scale_var, pdf_report, y_label) diff --git a/lib/ramble/ramble/repository.py b/lib/ramble/ramble/repository.py index ea1910974..4a2279961 100644 --- a/lib/ramble/ramble/repository.py +++ b/lib/ramble/ramble/repository.py @@ -773,7 +773,7 @@ def find_module(self, fullname, path=None): """ # namespaces are added to repo, and object modules are leaves. - namespace, dot, module_name = fullname.rpartition(".") + namespace, _, module_name = fullname.rpartition(".") # If it's a module in some repo, or if it is the repo's # namespace, let the repo handle it. @@ -1061,7 +1061,7 @@ def find_module(self, fullname, path=None): if self.is_prefix(fullname): return self - namespace, dot, module_name = fullname.rpartition(".") + namespace, _, module_name = fullname.rpartition(".") if namespace == self.full_namespace: if self.real_name(module_name): return self @@ -1076,7 +1076,7 @@ def load_module(self, fullname): if fullname in sys.modules: return sys.modules[fullname] - namespace, dot, module_name = fullname.rpartition(".") + namespace, _, module_name = fullname.rpartition(".") if self.is_prefix(fullname): module = ObjectNamespace(fullname) @@ -1528,7 +1528,7 @@ def find_spec(self, fullname, python_path, target=None): def compute_loader(self, fullname): # namespaces are added to repo, and object modules are leaves. - namespace, dot, module_name = fullname.rpartition(".") + namespace, _, module_name = fullname.rpartition(".") # If it's a module in some repo, or if it is the repo's # namespace, let the repo handle it. diff --git a/lib/ramble/ramble/spec.py b/lib/ramble/ramble/spec.py index cd3e2b611..1d2958c6e 100644 --- a/lib/ramble/ramble/spec.py +++ b/lib/ramble/ramble/spec.py @@ -139,7 +139,7 @@ def __init__(self, spec_like=None): self.workloads = {} if isinstance(spec_like, str): - namespace, dot, spec_name = spec_like.rpartition(".") + namespace, _, spec_name = spec_like.rpartition(".") if not namespace: namespace = None self.name = spec_name diff --git a/lib/ramble/ramble/test/application_tests.py b/lib/ramble/ramble/test/application_tests.py index 739000b9b..a1179194c 100644 --- a/lib/ramble/ramble/test/application_tests.py +++ b/lib/ramble/ramble/test/application_tests.py @@ -164,7 +164,7 @@ def test_required_builtins(mutable_mock_apps_repo, app): if conf[app_inst._builtin_required_key]: required_builtins.append(builtin) - for workload, wl_conf in app_inst.workloads.items(): + for workload in app_inst.workloads.keys(): exec_graph = app_inst._get_executable_graph(workload) for builtin in required_builtins: assert exec_graph.get_node(builtin) is not None @@ -181,7 +181,7 @@ def test_register_builtin_app(mutable_mock_apps_repo): else: excluded_builtins.append(builtin) - for workload, wl_conf in app_inst.workloads.items(): + for workload in app_inst.workloads.keys(): exec_graph = app_inst._get_executable_graph(workload) for builtin in required_builtins: diff --git a/lib/ramble/ramble/test/cmd/workspace.py b/lib/ramble/ramble/test/cmd/workspace.py index 40f770e84..47cd571ad 100644 --- a/lib/ramble/ramble/test/cmd/workspace.py +++ b/lib/ramble/ramble/test/cmd/workspace.py @@ -69,7 +69,7 @@ def check_basic(ws): for workloads, application_context in ws.all_applications(): if application_context.context_name == "basic": found_basic = True - for experiments, workload_context in ws.all_workloads(workloads): + for _, workload_context in ws.all_workloads(workloads): if workload_context.context_name == "test_wl": found_test_wl = True elif workload_context.context_name == "test_wl2": @@ -88,7 +88,7 @@ def check_no_basic(ws): for workloads, application_context in ws.all_applications(): if application_context.context_name == "basic": found_basic = True - for experiments, workload_context in ws.all_workloads(workloads): + for _, workload_context in ws.all_workloads(workloads): if workload_context.context_name == "test_wl": found_test_wl = True elif workload_context.context_name == "test_wl2": diff --git a/lib/ramble/ramble/test/stage.py b/lib/ramble/ramble/test/stage.py index 5ca422ae8..b041a7475 100644 --- a/lib/ramble/ramble/test/stage.py +++ b/lib/ramble/ramble/test/stage.py @@ -456,9 +456,7 @@ def test_composite_stage_with_noexpand_resource( @pytest.mark.disable_clean_stage_check def test_composite_stage_with_expand_resource(self, composite_stage_with_expanding_resource): - composite_stage, root_stage, resource_stage, mock_resource = ( - composite_stage_with_expanding_resource - ) + composite_stage, root_stage, _, mock_resource = composite_stage_with_expanding_resource composite_stage.create() composite_stage.fetch() diff --git a/lib/ramble/ramble/util/logger.py b/lib/ramble/ramble/util/logger.py index 11a4b675d..9cc391a5d 100644 --- a/lib/ramble/ramble/util/logger.py +++ b/lib/ramble/ramble/util/logger.py @@ -136,7 +136,7 @@ def all_msg(self, *args, **kwargs): print). Perform this action for all logs and the default log (to screen). """ - for idx, log in enumerate(self.log_stack): + for idx, _ in enumerate(self.log_stack): st_kwargs = self._stream_kwargs(default_kwargs=kwargs, index=idx) with self.configure_colors(**st_kwargs): tty.info(*args, **st_kwargs) @@ -203,7 +203,7 @@ def error(self, *args, **kwargs): print). Perform this action all logs, and the default stream (print to screen). """ - for idx, log in enumerate(self.log_stack): + for idx, _ in enumerate(self.log_stack): st_kwargs = self._stream_kwargs(index=idx, default_kwargs=kwargs) with self.configure_colors(**st_kwargs): tty.error(*args, **st_kwargs) @@ -217,7 +217,7 @@ def die(self, *args, **kwargs): print). Perform this action all logs. After all logs are printed to, terminate execution (and error) using tty.die. """ - for idx, log in enumerate(self.log_stack): + for idx, _ in enumerate(self.log_stack): st_kwargs = self._stream_kwargs(index=idx, default_kwargs=kwargs) with self.configure_colors(**st_kwargs): tty.error(*args, **st_kwargs) diff --git a/lib/ramble/ramble/util/naming.py b/lib/ramble/ramble/util/naming.py index a7f1c433c..08ff735c4 100644 --- a/lib/ramble/ramble/util/naming.py +++ b/lib/ramble/ramble/util/naming.py @@ -195,7 +195,7 @@ def __init__(self, separator="."): self._sep = separator def __setitem__(self, namespace, value): - first, sep, rest = namespace.partition(self._sep) + first, _, rest = namespace.partition(self._sep) if not first: self._value = NamespaceTrie.Element(value) @@ -207,7 +207,7 @@ def __setitem__(self, namespace, value): self._subspaces[first][rest] = value def _get_helper(self, namespace, full_name): - first, sep, rest = namespace.partition(self._sep) + first, _, rest = namespace.partition(self._sep) if not first: if not self._value: raise KeyError("Can't find namespace '%s' in trie" % full_name) @@ -223,7 +223,7 @@ def __getitem__(self, namespace): def is_prefix(self, namespace): """True if the namespace has a value, or if it's the prefix of one that does.""" - first, sep, rest = namespace.partition(self._sep) + first, _, rest = namespace.partition(self._sep) if not first: return True elif first not in self._subspaces: @@ -233,7 +233,7 @@ def is_prefix(self, namespace): def is_leaf(self, namespace): """True if this namespace has no children in the trie.""" - first, sep, rest = namespace.partition(self._sep) + first, _, rest = namespace.partition(self._sep) if not first: return bool(self._subspaces) elif first not in self._subspaces: @@ -243,7 +243,7 @@ def is_leaf(self, namespace): def has_value(self, namespace): """True if there is a value set for the given namespace.""" - first, sep, rest = namespace.partition(self._sep) + first, _, rest = namespace.partition(self._sep) if not first: return self._value is not None elif first not in self._subspaces: diff --git a/lib/ramble/ramble/util/web.py b/lib/ramble/ramble/util/web.py index 13129a364..2ca12acaf 100644 --- a/lib/ramble/ramble/util/web.py +++ b/lib/ramble/ramble/util/web.py @@ -612,7 +612,7 @@ def find_versions_of_archive( list_urls |= additional_list_urls # Grab some web pages to scrape. - pages, links = spider(list_urls, depth=list_depth, concurrency=concurrency) + _, links = spider(list_urls, depth=list_depth, concurrency=concurrency) # Scrape them for archive URLs regexes = [] diff --git a/lib/ramble/ramble/util/yaml_generation.py b/lib/ramble/ramble/util/yaml_generation.py index c910ddc35..83a6c7361 100644 --- a/lib/ramble/ramble/util/yaml_generation.py +++ b/lib/ramble/ramble/util/yaml_generation.py @@ -218,7 +218,7 @@ def apply_default_config_values(config_data, app_inst, default_config_string): workload = app_inst.workloads[app_inst.expander.workload_name] # Set all '{default_config_value}' values to value from the base config - for var_name, var_def in workload.variables.items(): + for var_name in workload.variables.keys(): if len(var_name.split(".")) > 1: var_val = app_inst.expander.expand_var(app_inst.expander.expansion_str(var_name)) diff --git a/lib/ramble/ramble/workload.py b/lib/ramble/ramble/workload.py index c453f5b25..3e0fde734 100644 --- a/lib/ramble/ramble/workload.py +++ b/lib/ramble/ramble/workload.py @@ -183,12 +183,12 @@ def as_str(self, n_indent: int = 0): if self.variables: out_str += rucolor.nested_1(f"{indentation} Variables:\n") - for name, var in self.variables.items(): + for var in self.variables.values(): out_str += var.as_str(n_indent + 4) if self.environment_variables: out_str += rucolor.nested_1(f"{indentation} Environment Variables:\n") - for name, env_var in self.environment_variables.items(): + for env_var in self.environment_variables.values(): out_str += env_var.as_str(n_indent + 4) return out_str diff --git a/lib/ramble/ramble/workspace/workspace.py b/lib/ramble/ramble/workspace/workspace.py index 1728415c2..0015a737c 100644 --- a/lib/ramble/ramble/workspace/workspace.py +++ b/lib/ramble/ramble/workspace/workspace.py @@ -1360,7 +1360,7 @@ def concretize(self, force=False, quiet=False): experiment_set = self.build_experiment_set() - for exp, app_inst, _ in experiment_set.all_experiments(): + for _, app_inst, _ in experiment_set.all_experiments(): app_inst.build_modifier_instances() env_name_str = app_inst.expander.expansion_str(ramble.keywords.keywords.env_name) env_name = app_inst.expander.expand_var(env_name_str) @@ -1907,7 +1907,7 @@ def included_config_scopes(self): # highest-precedence scopes are last. includes = config_dict(self.config_sections["workspace"]["yaml"]).get("include", []) missing = [] - for i, config_path in enumerate(reversed(includes)): + for config_path in reversed(includes): # allow paths to contain ramble config/environment variables, etc. config_path = substitute_path_variables( config_path, local_replacements=self.workspace_paths()