Skip to content

Commit e05da51

Browse files
authored
Merge pull request #3829 from mashehu/fix-list-indendation-of-bumped-yml
2 parents 1034e3c + e73032f commit e05da51

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
- Update pre-commit hook pre-commit/pre-commit-hooks to v6 ([#3797](https://github.com/nf-core/tools/pull/3797))
8383
- Update dependency python to 3.14 ([#3817](https://github.com/nf-core/tools/pull/3817))
8484
- update Dockerfile to python 3.14 ([#3822](https://github.com/nf-core/tools/pull/3822))
85+
- pipelines bump-version: fix indentation for list in dumped .nf-core.yml ([#3829](https://github.com/nf-core/tools/pull/3829))
8586

8687
## [v3.3.2 - Tungsten Tamarin Patch 2](https://github.com/nf-core/tools/releases/tag/3.3.2) - [2025-07-08]
8788

nf_core/pipelines/bump_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def update_yaml_file(fn: Path, patterns: list[tuple[str, str]], yaml_key: list[s
237237
"""
238238
yaml = YAML()
239239
yaml.preserve_quotes = True
240+
yaml.width = 4096 # Prevent line wrapping
240241
with open(fn) as file:
241242
yaml_content = yaml.load(file)
242243

@@ -259,6 +260,7 @@ def update_yaml_file(fn: Path, patterns: list[tuple[str, str]], yaml_key: list[s
259260
if new_value != current_value:
260261
target[last_key] = new_value
261262
with open(fn, "w") as file:
263+
yaml.indent(mapping=2, sequence=4, offset=2) # from https://stackoverflow.com/a/44389139/1696643
262264
yaml.dump(yaml_content, file)
263265
log.info(f"Updated version in YAML file '{fn}'")
264266
log_change(str(current_value), str(new_value))

tests/pipelines/test_bump_version.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""Some tests covering the bump_version code."""
22

33
import logging
4+
from pathlib import Path
45

56
import yaml
67

78
import nf_core.pipelines.bump_version
89
import nf_core.utils
10+
from nf_core.pipelines.lint_utils import run_prettier_on_file
911

1012
from ..test_pipelines import TestPipelines
1113

@@ -104,3 +106,43 @@ def test_bump_pipeline_version_in_snapshot_no_version(self):
104106
self.caplog.set_level(logging.INFO)
105107
nf_core.pipelines.bump_version.bump_pipeline_version(self.pipeline_obj, "1.1.0")
106108
assert "Could not find version number in " in self.caplog.text
109+
110+
def test_bump_pipeline_version_nf_core_yml_prettier(self):
111+
"""Test that lists in .nf-core.yml have correct formatting after version bump."""
112+
113+
nf_core_yml_path = Path(self.pipeline_dir / ".nf-core.yml")
114+
115+
# Add a list to the .nf-core.yml file to test list indentation
116+
with open(nf_core_yml_path) as fh:
117+
nf_core_yml = yaml.safe_load(fh)
118+
119+
# Add a lint section with a list
120+
if "lint" not in nf_core_yml:
121+
nf_core_yml["lint"] = {}
122+
nf_core_yml["lint"]["files_exist"] = ["assets/multiqc_config.yml", "conf/base.config"]
123+
124+
with open(nf_core_yml_path, "w") as fh:
125+
yaml.dump(nf_core_yml, fh, default_flow_style=False)
126+
127+
# Run prettier to ensure the file is properly formatted before the test
128+
run_prettier_on_file(nf_core_yml_path)
129+
130+
# Bump the version
131+
nf_core.pipelines.bump_version.bump_pipeline_version(self.pipeline_obj, "1.1.0")
132+
133+
# Read the file before prettier to store it
134+
with open(nf_core_yml_path) as fh:
135+
content_before = fh.read()
136+
137+
# Run prettier on the file
138+
run_prettier_on_file(nf_core_yml_path)
139+
140+
# Read the file after prettier
141+
with open(nf_core_yml_path) as fh:
142+
content_after = fh.read()
143+
144+
# If prettier changed the file, the formatting was wrong
145+
assert content_before == content_after, (
146+
"The .nf-core.yml file formatting changed after running prettier. "
147+
"This means the YAML dumping did not use correct indentation settings."
148+
)

0 commit comments

Comments
 (0)