Skip to content

Commit eef25d3

Browse files
committed
Use glob not walk for process execution directory search
1 parent 0a128c4 commit eef25d3

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

nextflow/io.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import glob
23
from datetime import datetime
34

45
def get_file_text(path):
@@ -35,10 +36,7 @@ def get_process_ids_to_paths(process_ids, execution_path):
3536

3637
process_ids_to_paths = {}
3738
path = os.path.join(execution_path, "work")
38-
subdirectories = []
39-
for root, dirs, _ in os.walk(path):
40-
for directory in dirs:
41-
subdirectories.append(os.path.join(root, directory))
39+
subdirectories = glob.glob(os.path.join(path, "*", "*"))
4240
for subdirectory in subdirectories:
4341
sub = os.path.sep.join(subdirectory.split(os.path.sep)[-2:])
4442
for process_id in process_ids:

tests/unit/test_io.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ def test_can_handle_no_file(self, mock_getctime):
3838

3939
class ProcessIdsToPathsTest(TestCase):
4040

41-
@patch("os.walk")
42-
def test_can_get_paths(self, mock_walk):
41+
@patch("glob.glob")
42+
def test_can_get_paths(self, mock_glob):
4343
process_ids = ["ab/123456", "cd/7890123"]
44-
mock_walk.return_value = (
45-
("/ex/work", ["xx", "cd"], []),
46-
("/ex/work/xx", ["yyyyyyy"], []),
47-
("/ex/work/cd", ["789012345678"], []),
44+
mock_glob.return_value = (
45+
"/ex/work/xx/yyyyyyy",
46+
"/ex/work/cd/789012345678"
4847
)
4948
paths = get_process_ids_to_paths(process_ids, "/ex")
5049
self.assertEqual(paths, {"cd/7890123": os.path.join("/ex", "work", "cd/789012345678")})
51-
mock_walk.assert_called_with(os.path.join("/ex", "work"))
50+
mock_glob.assert_called_with(os.path.join("/ex", "work", "*", "*"))

0 commit comments

Comments
 (0)