From f041abcbc3070bd2b60b91216cdb4e1255f1bae4 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Mon, 20 Jul 2020 11:52:07 -0400 Subject: [PATCH] Post-merge pass updating py3 features/standardizing --- lib/galaxy/datatypes/data.py | 4 ++-- lib/galaxy/datatypes/images.py | 8 +++---- lib/galaxy/managers/citations.py | 8 +++---- lib/galaxy/managers/markdown_parse.py | 2 +- lib/galaxy/managers/markdown_util.py | 24 +++++++++---------- .../tool_dependencies/recipe/step_handler.py | 8 +++---- .../tool_util/deps/container_classes.py | 8 +++---- lib/galaxy/tools/actions/__init__.py | 6 ++--- lib/galaxy/util/__init__.py | 2 +- lib/galaxy/web/framework/middleware/error.py | 18 +++++++------- lib/galaxy/webapps/galaxy/api/datatypes.py | 2 +- lib/galaxy/webapps/galaxy/controllers/root.py | 8 +++---- .../webapps/galaxy/controllers/workflow.py | 6 ++--- .../api/test_dataset_collections.py | 2 +- lib/galaxy_test/api/test_datatypes.py | 2 +- lib/galaxy_test/base/env.py | 2 +- 16 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index 060864a672a..6f2f55ca103 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -898,13 +898,13 @@ class Text(Data): lc = self.count_data_lines(dataset) if lc is not None: dataset.metadata.data_lines = lc - dataset.blurb = "%s %s" % (util.commaify(str(lc)), inflector.cond_plural(lc, self.line_class)) + dataset.blurb = "{} {}".format(util.commaify(str(lc)), inflector.cond_plural(lc, self.line_class)) else: dataset.blurb = "Error: Cannot count lines in dataset" else: est_lines = self.estimate_file_lines(dataset) if est_lines is not None: - dataset.blurb = "~%s %s" % (util.commaify(util.roundify(str(est_lines))), inflector.cond_plural(est_lines, self.line_class)) + dataset.blurb = "~{} {}".format(util.commaify(util.roundify(str(est_lines))), inflector.cond_plural(est_lines, self.line_class)) else: dataset.blurb = "Error: Cannot estimate lines in dataset" else: diff --git a/lib/galaxy/datatypes/images.py b/lib/galaxy/datatypes/images.py index 93d9ee50310..8fd4eee22df 100644 --- a/lib/galaxy/datatypes/images.py +++ b/lib/galaxy/datatypes/images.py @@ -172,17 +172,17 @@ class Pdf(Image): def create_applet_tag_peek(class_name, archive, params): text = """ - - """ % (class_name, archive) + """.format(class_name, archive) for name, value in params.items(): text += """""".format(name, value) text += """ - - """ % (class_name, archive) + + """.format(class_name, archive) for name, value in params.items(): text += """""".format(name, value) text += """
You must install and enable Java in your browser in order to access this applet.
diff --git a/lib/galaxy/managers/citations.py b/lib/galaxy/managers/citations.py index 67e407877e3..dcccb70339a 100644 --- a/lib/galaxy/managers/citations.py +++ b/lib/galaxy/managers/citations.py @@ -146,10 +146,10 @@ class DoiCitation(BaseCitation): log.exception("Failed to fetch bibtex for DOI %s", self.__doi) if self.raw_bibtex is DoiCitation.BIBTEX_UNSET: - return """@MISC{%s, - DOI = {%s}, - note = {Failed to fetch BibTeX for DOI.} - }""" % (self.__doi, self.__doi) + return """@MISC{{{}, + DOI = {{{}}}, + note = {{Failed to fetch BibTeX for DOI.}} + }}""".format(self.__doi, self.__doi) else: return self.raw_bibtex diff --git a/lib/galaxy/managers/markdown_parse.py b/lib/galaxy/managers/markdown_parse.py index 93a424c5668..51243101851 100644 --- a/lib/galaxy/managers/markdown_parse.py +++ b/lib/galaxy/managers/markdown_parse.py @@ -42,7 +42,7 @@ GALAXY_FLAVORED_MARKDOWN_CONTAINER_REGEX = r'(?P%s)' % "|".join(GALAX ARG_VAL_REGEX = r'''[\w_\-]+|\"[^\"]+\"|\'[^\']+\'''' FUNCTION_ARG = r'\s*\w+\s*=\s*(?:%s)\s*' % ARG_VAL_REGEX # embed commas between arguments -FUNCTION_MULTIPLE_ARGS = r'(?P%s)(?P(?:,%s)*)' % (FUNCTION_ARG, FUNCTION_ARG) +FUNCTION_MULTIPLE_ARGS = r'(?P{})(?P(?:,{})*)'.format(FUNCTION_ARG, FUNCTION_ARG) FUNCTION_MULTIPLE_ARGS_PATTERN = re.compile(FUNCTION_MULTIPLE_ARGS) FUNCTION_CALL_LINE_TEMPLATE = r'\s*%s\s*\((?:' + FUNCTION_MULTIPLE_ARGS + r')?\)\s*' GALAXY_MARKDOWN_FUNCTION_CALL_LINE = re.compile(FUNCTION_CALL_LINE_TEMPLATE % GALAXY_FLAVORED_MARKDOWN_CONTAINER_REGEX) diff --git a/lib/galaxy/managers/markdown_util.py b/lib/galaxy/managers/markdown_util.py index 4ce63f96ee3..ffd195674bf 100644 --- a/lib/galaxy/managers/markdown_util.py +++ b/lib/galaxy/managers/markdown_util.py @@ -580,34 +580,34 @@ def resolve_invocation_markdown(trans, invocation, workflow_markdown): continue if output_assoc.history_content_type == "dataset": - section_markdown += """#### Output Dataset: %s + section_markdown += """#### Output Dataset: {} ```galaxy -history_dataset_display(output="%s") +history_dataset_display(output="{}") ``` -""" % (output_assoc.workflow_output.label, output_assoc.workflow_output.label) +""".format(output_assoc.workflow_output.label, output_assoc.workflow_output.label) else: - section_markdown += """#### Output Dataset Collection: %s + section_markdown += """#### Output Dataset Collection: {} ```galaxy -history_dataset_collection_display(output="%s") +history_dataset_collection_display(output="{}") ``` -""" % (output_assoc.workflow_output.label, output_assoc.workflow_output.label) +""".format(output_assoc.workflow_output.label, output_assoc.workflow_output.label) elif container == "invocation_inputs": for input_assoc in invocation.input_associations: if not input_assoc.workflow_step.label: continue if input_assoc.history_content_type == "dataset": - section_markdown += """#### Input Dataset: %s + section_markdown += """#### Input Dataset: {} ```galaxy -history_dataset_display(input="%s") +history_dataset_display(input="{}") ``` -""" % (input_assoc.workflow_step.label, input_assoc.workflow_step.label) +""".format(input_assoc.workflow_step.label, input_assoc.workflow_step.label) else: - section_markdown += """#### Input Dataset Collection: %s + section_markdown += """#### Input Dataset Collection: {} ```galaxy -history_dataset_collection_display(input=%s) +history_dataset_collection_display(input={}) ``` -""" % (input_assoc.workflow_step.label, input_assoc.workflow_step.label) +""".format(input_assoc.workflow_step.label, input_assoc.workflow_step.label) else: return line, False return section_markdown, True diff --git a/lib/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py b/lib/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py index 6a1b7453afc..8d5b9538805 100644 --- a/lib/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py +++ b/lib/galaxy/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py @@ -1333,7 +1333,7 @@ class SetupRubyEnvironment(Download, RecipeStep): if os.path.isfile(gem): # we assume a local shipped gem file cmd = '''PATH=$PATH:$RUBY_HOME/bin; export PATH; GEM_HOME=$INSTALL_DIR; export GEM_HOME; - gem install --local %s %s''' % (gem, gem_parameters) + gem install --local {} {}'''.format(gem, gem_parameters) elif gem.find('://') != -1: # We assume a URL to a gem file. url = gem @@ -1341,7 +1341,7 @@ class SetupRubyEnvironment(Download, RecipeStep): checksums = ruby_package_tup_dict.get('checksums', {}) self.url_download(work_dir, gem_name, url, extract=False, checksums=checksums) cmd = '''PATH=$PATH:$RUBY_HOME/bin; export PATH; GEM_HOME=$INSTALL_DIR; export GEM_HOME; - gem install --local %s %s''' % (gem_name, gem_parameters) + gem install --local {} {}'''.format(gem_name, gem_parameters) else: # gem file from rubygems.org with or without version number if gem_version: @@ -1349,11 +1349,11 @@ class SetupRubyEnvironment(Download, RecipeStep): # Use raw strings so that python won't automatically unescape the quotes before passing the command # to subprocess.Popen. cmd = r'''PATH=$PATH:$RUBY_HOME/bin; export PATH; GEM_HOME=$INSTALL_DIR; export GEM_HOME; - gem install %s --version "=%s" %s''' % (gem, gem_version, gem_parameters) + gem install {} --version "={}" {}'''.format(gem, gem_version, gem_parameters) else: # no version number given cmd = '''PATH=$PATH:$RUBY_HOME/bin; export PATH; GEM_HOME=$INSTALL_DIR; export GEM_HOME; - gem install %s %s''' % (gem, gem_parameters) + gem install {} {}'''.format(gem, gem_parameters) cmd = install_environment.build_command(basic_util.evaluate_template(cmd, install_environment)) return_code = install_environment.handle_command(tool_dependency=tool_dependency, cmd=cmd, diff --git a/lib/galaxy/tool_util/deps/container_classes.py b/lib/galaxy/tool_util/deps/container_classes.py index 662f3b33dcf..29dcaf766ff 100644 --- a/lib/galaxy/tool_util/deps/container_classes.py +++ b/lib/galaxy/tool_util/deps/container_classes.py @@ -324,11 +324,11 @@ class DockerContainer(Container, HasDockerLikeVolumes): # Standard error is: # Error response from daemon: Cannot kill container: 2b0b961527574ebc873256b481bbe72e: No such container: 2b0b961527574ebc873256b481bbe72e return """ -_on_exit() { - %s &> /dev/null -} +_on_exit() {{ + {} &> /dev/null +}} trap _on_exit 0 -%s\n%s""" % (kill_command, cache_command, run_command) +{}\n{}""".format(kill_command, cache_command, run_command) def __cache_from_file_command(self, cached_image_file, docker_host_props): images_cmd = docker_util.build_docker_images_command(truncate=False, **docker_host_props) diff --git a/lib/galaxy/tools/actions/__init__.py b/lib/galaxy/tools/actions/__init__.py index 027deabd1a9..9e3f3dda670 100644 --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -515,7 +515,7 @@ class DefaultToolAction: ) if hdca: datasets_to_persist.append(hdca) - log.info("Handled collection output named %s for tool %s %s" % (name, tool.id, handle_output_timer)) + log.info("Handled collection output named {} for tool {} {}".format(name, tool.id, handle_output_timer)) else: handle_output(name, output) log.info("Handled output named {} for tool {} {}".format(name, tool.id, handle_output_timer)) @@ -560,7 +560,7 @@ class DefaultToolAction: current_job=job, out_data=out_data) datasets_to_persist = [] - log.info("Setup for job %s complete, ready to be enqueued %s" % (job.log_str(), job_setup_timer)) + log.info("Setup for job {} complete, ready to be enqueued {}".format(job.log_str(), job_setup_timer)) # Some tools are not really executable, but jobs are still created for them ( for record keeping ). # Examples include tools that redirect to other applications ( epigraph ). These special tools must @@ -589,7 +589,7 @@ class DefaultToolAction: history.add_datasets(trans.sa_session, datasets_to_persist, set_hid=set_output_hid, quota=False, flush=False) job_flush_timer = ExecutionTimer() trans.sa_session.flush() - log.info("Flushed transaction for job %s %s" % (job.log_str(), job_flush_timer)) + log.info("Flushed transaction for job {} {}".format(job.log_str(), job_flush_timer)) # Dispatch to a job handler. enqueue() is responsible for flushing the job app.job_manager.enqueue(job, tool=tool) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 78800ad1500..0280414691c 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -1045,7 +1045,7 @@ def unicodify(value, encoding=DEFAULT_ENCODING, error='replace', strip_null=Fals if not isinstance(value, text_type): value = text_type(value, encoding, error) except Exception as e: - msg = "Value '%s' could not be coerced to Unicode: %s('%s')" % (value, type(e).__name__, e) + msg = "Value '{}' could not be coerced to Unicode: {}('{}')".format(value, type(e).__name__, e) raise Exception(msg) if strip_null: return value.replace('\0', '') diff --git a/lib/galaxy/web/framework/middleware/error.py b/lib/galaxy/web/framework/middleware/error.py index 125408bbb2a..3472bac9113 100644 --- a/lib/galaxy/web/framework/middleware/error.py +++ b/lib/galaxy/web/framework/middleware/error.py @@ -444,10 +444,10 @@ def send_report(rep, exc_data, html=True): traceback.print_exc(file=output) if html: return """ -

Additionally an error occurred while sending the %s report: +

Additionally an error occurred while sending the {} report: -

%s
-

""" % ( +
{}
+

""".format( markupsafe.escape(str(rep)), output.getvalue()) else: return ( @@ -463,11 +463,11 @@ def error_template(head_html, exception, extra): Internal Server Error - %s + {}
@@ -475,14 +475,14 @@ def error_template(head_html, exception, extra):

Galaxy was unable to successfully complete your request

-

%s

+

{}

This may be an intermittent problem due to load or other unpredictable factors, reloading the page may address the problem. - %s + {}
- ''' % (head_html, exception, extra) + '''.format(head_html, exception, extra) def make_error_middleware(app, global_conf, **kw): diff --git a/lib/galaxy/webapps/galaxy/api/datatypes.py b/lib/galaxy/webapps/galaxy/api/datatypes.py index cf4b859a836..3f17f881df6 100644 --- a/lib/galaxy/webapps/galaxy/api/datatypes.py +++ b/lib/galaxy/webapps/galaxy/api/datatypes.py @@ -72,7 +72,7 @@ class DatatypesController(BaseAPIController): n = c.__module__ + "." + c.__name__ types = {n} visit_bases(types, c) - class_to_classes[n] = dict((t, True) for t in types) + class_to_classes[n] = {t: True for t in types} return dict(ext_to_class_name=ext_to_class_name, class_to_classes=class_to_classes) @expose_api_anonymous_and_sessionless diff --git a/lib/galaxy/webapps/galaxy/controllers/root.py b/lib/galaxy/webapps/galaxy/controllers/root.py index da6c4237850..94a4880e128 100644 --- a/lib/galaxy/webapps/galaxy/controllers/root.py +++ b/lib/galaxy/webapps/galaxy/controllers/root.py @@ -278,8 +278,8 @@ class RootController(controller.JSAppLauncher, UsesAnnotations): trans.set_history(new_history) trans.log_event("History imported, id: {}, name: '{}': ".format(str(new_history.id), new_history.name)) return trans.show_ok_message(""" - History "%s" has been imported. Click here - to begin.""" % (new_history.name, web.url_for('/'))) + History "{}" has been imported. Click here + to begin.""".format(new_history.name, web.url_for('/'))) elif not user_history.datasets or confirm: new_history = import_history.copy() new_history.name = "imported: " + new_history.name @@ -297,8 +297,8 @@ class RootController(controller.JSAppLauncher, UsesAnnotations): trans.set_history(new_history) trans.log_event("History imported, id: {}, name: '{}': ".format(str(new_history.id), new_history.name)) return trans.show_ok_message(""" - History "%s" has been imported. Click here - to begin.""" % (new_history.name, web.url_for('/'))) + History "{}" has been imported. Click here + to begin.""".format(new_history.name, web.url_for('/'))) return trans.show_warn_message(""" Warning! If you import this history, you will lose your current history. Click here to confirm. diff --git a/lib/galaxy/webapps/galaxy/controllers/workflow.py b/lib/galaxy/webapps/galaxy/controllers/workflow.py index 9816944f0e5..016491abba5 100644 --- a/lib/galaxy/webapps/galaxy/controllers/workflow.py +++ b/lib/galaxy/webapps/galaxy/controllers/workflow.py @@ -773,9 +773,9 @@ class WorkflowController(BaseUIController, SharableMixin, UsesStoredWorkflowMixi workflow_list_str = "
Return to workflow list." % url_for(controller='workflows', action='list') if myexp_workflow_id: return trans.show_message( - """Workflow '%s' successfully exported to myExperiment.
-
Click here to view the workflow on myExperiment %s - """ % (stored.name, myexp_url, myexp_workflow_id, workflow_list_str), + """Workflow '{}' successfully exported to myExperiment.
+ Click here to view the workflow on myExperiment {} + """.format(stored.name, myexp_url, myexp_workflow_id, workflow_list_str), use_panels=True) else: return trans.show_error_message( diff --git a/lib/galaxy_test/api/test_dataset_collections.py b/lib/galaxy_test/api/test_dataset_collections.py index fffd4f8913b..9da2a1b2d6c 100644 --- a/lib/galaxy_test/api/test_dataset_collections.py +++ b/lib/galaxy_test/api/test_dataset_collections.py @@ -289,7 +289,7 @@ class DatasetCollectionApiTestCase(ApiTestCase): response = self._get(contents_url) self._assert_status_code_is(response, 200) fake_collection_id = '5d7db0757a2eb7ef' - fake_contents_url = '/api/dataset_collections/%s/contents/%s' % (hdca['id'], fake_collection_id) + fake_contents_url = '/api/dataset_collections/{}/contents/{}'.format(hdca['id'], fake_collection_id) error_response = self._get(fake_contents_url) assert_object_id_error(error_response) diff --git a/lib/galaxy_test/api/test_datatypes.py b/lib/galaxy_test/api/test_datatypes.py index 9557ff3ca88..07fd810fd7c 100644 --- a/lib/galaxy_test/api/test_datatypes.py +++ b/lib/galaxy_test/api/test_datatypes.py @@ -48,7 +48,7 @@ class DatatypesApiTestCase(ApiTestCase): datatypes = response_dict["datatypes"] for common_type in ["tabular", "fasta"]: - assert common_type in datatypes, "%s not in %s" % (common_type, datatypes) + assert common_type in datatypes, "{} not in {}".format(common_type, datatypes) def test_sniffers(self): response = self._get("datatypes/sniffers") diff --git a/lib/galaxy_test/base/env.py b/lib/galaxy_test/base/env.py index fc89bc1ab8a..7d3fd620557 100644 --- a/lib/galaxy_test/base/env.py +++ b/lib/galaxy_test/base/env.py @@ -21,7 +21,7 @@ def setup_keep_outdir(): def target_url_parts(): host = socket.gethostbyname(os.environ.get('GALAXY_TEST_HOST', DEFAULT_WEB_HOST)) port = os.environ.get('GALAXY_TEST_PORT') - default_url = "http://%s:%s" % (host, port) + default_url = "http://{}:{}".format(host, port) url = os.environ.get('GALAXY_TEST_EXTERNAL', default_url) return host, port, url