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
34 changes: 9 additions & 25 deletions nf_core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import concurrent.futures
import datetime
import errno
import fnmatch
import hashlib
import io
import json
Expand Down Expand Up @@ -1671,27 +1670,12 @@ def set_wd(path: Path) -> Generator[None, None, None]:


def get_wf_files(wf_path: Path):
"""Return a list of all files in a directory (ignores .gitigore files)"""

wf_files = []

ignore = [".git/*"]
try:
with open(Path(wf_path, ".gitignore")) as f:
for line in f.read().splitlines():
if not line or line.startswith("#"):
continue
# Make trailing-slash patterns match their entire subtree
line = re.sub("/$", "/*", line)
ignore.append(line)
except FileNotFoundError:
pass

for path in Path(wf_path).rglob("*"):
rpath = str(path.relative_to(wf_path))
if any(fnmatch.fnmatch(rpath, pattern) for pattern in ignore):
continue
if path.is_file():
wf_files.append(str(path))

return wf_files
"""Return a list of all files in a directory (respects .gitignore via git ls-files)"""
git_ls_files = subprocess.check_output(
["git", "ls-files"],
cwd=wf_path,
stderr=subprocess.DEVNULL,
).splitlines()
return [
str(Path(wf_path) / fn.decode("utf-8")) for fn in git_ls_files if (Path(wf_path) / fn.decode("utf-8")).is_file()
]
2 changes: 2 additions & 0 deletions tests/pipelines/lint/test_if_empty_null.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import subprocess
from pathlib import Path

import yaml
Expand Down Expand Up @@ -33,6 +34,7 @@ def test_if_empty_null_throws_warn(self):
"| ifEmpty(null)\n",
]
)
subprocess.check_call(["git", "add", "docs/test.txt"], cwd=self.new_pipeline)
lint_obj = nf_core.pipelines.lint.PipelineLint(self.new_pipeline)
lint_obj._load()
result = lint_obj.pipeline_if_empty_null()
Expand Down
7 changes: 6 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests covering for utility functions."""

import os
import subprocess
from pathlib import Path
from unittest import mock

Expand Down Expand Up @@ -228,9 +229,9 @@ def test_fetch_wf_config(self, mock_run_cmd):
@with_temporary_folder
def test_get_wf_files(self, tmpdir):
tmpdir = Path(tmpdir)
subprocess.check_call(["git", "init"], cwd=tmpdir)
(tmpdir / ".gitignore").write_text(".nextflow*\nwork/\nresults/\n")
for rpath in [
".git/should-ignore-1",
"work/should-ignore-2",
"results/should-ignore-3",
".nextflow.should-ignore-4",
Expand All @@ -240,6 +241,10 @@ def test_get_wf_files(self, tmpdir):
p = tmpdir / rpath
p.parent.mkdir(exist_ok=True)
p.touch()
subprocess.check_call(
["git", "add", ".gitignore", "dir1/should-match-1", "should-match-2"],
cwd=tmpdir,
)
files = nf_core.utils.get_wf_files(tmpdir)
files = sorted(str(Path(f).relative_to(tmpdir)) for f in files)
assert files == [".gitignore", "dir1/should-match-1", "should-match-2"]
Loading