Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run prettier on test yml file after creation #2078

Merged
merged 8 commits into from
Dec 2, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- Extended the chat notifications to Slack ([#1829](https://github.com/nf-core/tools/pull/1829))
- Allow other remote URLs not starting with `http` ([#2061](https://github.com/nf-core/tools/pull/2061))
- Prevent installation with unsupported Python versions ([#2075](https://github.com/nf-core/tools/pull/2075))
- Automatically format `test.yml` content with Prettier ([#2078](https://github.com/nf-core/tools/pull/2078))

### Modules

Expand Down
24 changes: 14 additions & 10 deletions nf_core/modules/test_yml_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import nf_core.utils
from nf_core.components.components_command import ComponentCommand

from ..lint_utils import run_prettier_on_file
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
from .modules_repo import ModulesRepo

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -358,16 +359,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()
mashehu marked this conversation as resolved.
Show resolved Hide resolved

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}'")