+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Replace arm profile with arm64 and emulate_amd64 profiles ([#3689](https://github.com/nf-core/tools/pull/3689))
- Remove workflow.trace from nf-test snapshot ([#3721](https://github.com/nf-core/tools/pull/3721))
- Add GHA to update template nf-test snapshots ([#3723](https://github.com/nf-core/tools/pull/3723))
- add pytest for get_wf_files ([#3725](https://github.com/nf-core/tools/pull/3725))

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

Expand Down
9 changes: 7 additions & 2 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,13 +1573,18 @@ def get_wf_files(wf_path: Path):
"""Return a list of all files in a directory (ignores .gitigore files)"""

wf_files = []

try:
with open(Path(wf_path, ".gitignore")) as f:
lines = f.read().splitlines()
ignore = [line for line in lines if line and not line.startswith("#")]
print(lines)
ignore = [
(str(wf_path / line) + "*" if line.endswith("/") else str(wf_path / line))
for line in lines
if line and not line.startswith("#")
]
except FileNotFoundError:
ignore = []
print(ignore)

for path in Path(wf_path).rglob("*"):
if any(fnmatch.fnmatch(str(path), pattern) for pattern in ignore):
Expand Down
21 changes: 17 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ def test_set_wd(self):

def test_set_wd_revert_on_raise(self):
wd_before_context = Path().resolve()
with pytest.raises(Exception):
with nf_core.utils.set_wd(self.tmp_dir):
raise Exception
assert wd_before_context == Path().resolve()
with mock.patch("nf_core.utils.set_wd", side_effect=Exception("mocked exception")):
with pytest.raises(Exception):
with nf_core.utils.set_wd(self.tmp_dir):
assert wd_before_context == Path().resolve()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this assertion. Doesn't this mean that the wd is the same as before and set_wd didn't do anything?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think this is what the test is supposed to do, based on the name "revert_on_raise"


@mock.patch("nf_core.utils.run_cmd")
def test_fetch_wf_config(self, mock_run_cmd):
Expand All @@ -224,3 +224,16 @@ def test_fetch_wf_config(self, mock_run_cmd):
config = nf_core.utils.fetch_wf_config(".", False)
assert len(config.keys()) == 1
assert "params.param2" in list(config.keys())

def test_get_wf_files(self):
(self.pipeline_obj.wf_path / "work").mkdir()
(self.pipeline_obj.wf_path / "work" / "file.txt").touch()
(self.pipeline_obj.wf_path / ".nextflow.log").touch()
files = nf_core.utils.get_wf_files(self.pipeline_obj.wf_path)
assert str(Path(self.pipeline_dir, "main.nf")) in files
assert str(Path(self.pipeline_dir, "work", "file.txt")) not in files
assert str(Path(self.pipeline_dir, ".nextflow.log")) not in files

def test_get_wf_files_no_gitignore(self):
files = nf_core.utils.get_wf_files(Path("random/path"))
assert files == []
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载