From 3d9329b842fffdadff57ba75b914a034c20f676b Mon Sep 17 00:00:00 2001 From: mirpedrol Date: Fri, 2 Dec 2022 13:38:54 +0100 Subject: [PATCH] run prettier also for subworkflows --- nf_core/subworkflows/test_yml_builder.py | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/nf_core/subworkflows/test_yml_builder.py b/nf_core/subworkflows/test_yml_builder.py index 4d3162bd7c..b2f6cd6ceb 100644 --- a/nf_core/subworkflows/test_yml_builder.py +++ b/nf_core/subworkflows/test_yml_builder.py @@ -28,6 +28,8 @@ from nf_core.modules.modules_json import ModulesJson from nf_core.modules.modules_repo import ModulesRepo +from ..lint_utils import run_prettier_on_file + log = logging.getLogger(__name__) @@ -374,16 +376,19 @@ def print_test_yml(self): """ Generate the test yml file. """ + with tempfile.NamedTemporaryFile(mode="w+") as fh: + yaml.dump(self.tests, fh, Dumper=nf_core.utils.custom_yaml_dumper(), width=10000000) + run_prettier_on_file(fh.name) + fh.seek(0) + prettified_yml = fh.read() if self.test_yml_output_path == "-": console = rich.console.Console() - yaml_str = yaml.dump(self.tests, Dumper=nf_core.utils.custom_yaml_dumper(), width=10000000) - console.print("\n", Syntax(yaml_str, "yaml"), "\n") - return - - try: - log.info(f"Writing to '{self.test_yml_output_path}'") - with open(self.test_yml_output_path, "w") as fh: - yaml.dump(self.tests, fh, Dumper=nf_core.utils.custom_yaml_dumper(), width=10000000) - except FileNotFoundError as e: - raise UserWarning(f"Could not create test.yml file: '{e}'") + console.print("\n", Syntax(prettified_yml, "yaml"), "\n") + else: + try: + log.info(f"Writing to '{self.test_yml_output_path}'") + with open(self.test_yml_output_path, "w") as fh: + fh.write(prettified_yml) + except FileNotFoundError as e: + raise UserWarning(f"Could not create test.yml file: '{e}'")