Skip to content

Commit 0f2aa7b

Browse files
authored
Merge pull request #40 from Sage-Bionetworks-Workflows/bwmac/orca-234/improved_file_mounting
[ORCA-234] Improve file path handling
2 parents d12968e + 3d86c9e commit 0f2aa7b

File tree

8 files changed

+8
-43
lines changed

8 files changed

+8
-43
lines changed

src/dcqc/file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class File(SerializableMixin):
125125
current work directory (default).
126126
"""
127127

128+
tmp_dir: ClassVar[str] = "dcqc-staged-"
129+
128130
_serialized_properties = ["name", "local_path"]
129131

130132
url: str
@@ -336,9 +338,7 @@ def stage(
336338
if self._local_path is not None:
337339
return self._local_path
338340
else:
339-
# TODO: This prefix is used by nf-dcqc to easily find the staged file.
340-
# It might be worth using a DCQCTMPDIR to avoid hard-coding this.
341-
destination_str = mkdtemp(prefix="dcqc-staged-")
341+
destination_str = mkdtemp(prefix=self.tmp_dir)
342342
destination = Path(destination_str)
343343

344344
# By this point, destination is defined (not None)

src/dcqc/tests/base_test.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,6 @@ def _interpret_process_outputs(self, outputs: dict[str, Path]) -> TestStatus:
202202
status = TestStatus.FAIL
203203
return status
204204

205-
# TODO: make changes to this package or the nextflow
206-
# workflow so that file mounting is handled cleaner
207-
@staticmethod
208-
def _short_string_path(path: Path, substring: str) -> str:
209-
# chech if substring is in path
210-
if substring not in path.as_posix():
211-
raise ValueError(f"{substring} not in {path}")
212-
# get index where staged folder is
213-
index = next(i for i, item in enumerate(path.parts) if substring in item)
214-
# shorten path starting from staged folder
215-
short_path = Path(*path.parts[index:])
216-
# wrap path string in quotes
217-
quote_path = str(short_path)
218-
return f"'{quote_path}'"
219-
220205
# TODO: Include process in serialized test dictionary
221206
# def to_dict(self):
222207
# dictionary = super(ExternalTestMixin, self).to_dict()

src/dcqc/tests/bioformats_info_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ class BioFormatsInfoTest(ExternalBaseTest):
99

1010
def generate_process(self) -> Process:
1111
path = self.target.file.stage()
12-
string_path = self._short_string_path(path, "dcqc-staged-")
1312

1413
command_args = [
1514
"/opt/bftools/showinf",
1615
"-nopix",
1716
"-novalid",
1817
"-nocore",
19-
string_path,
18+
f"'{path.name}'",
2019
]
2120
process = Process(
2221
container="quay.io/sagebionetworks/bftools:latest",

src/dcqc/tests/grep_date_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class GrepDateTest(ExternalBaseTest):
99

1010
def generate_process(self) -> Process:
1111
path = self.target.file.stage()
12-
string_path = self._short_string_path(path, "dcqc-staged-")
1312

1413
command_args = [
1514
"grep",
@@ -18,7 +17,7 @@ def generate_process(self) -> Process:
1817
"-a", # treat input as text
1918
"-q", # suppress output
2019
"'date|time'", # match date or time
21-
string_path,
20+
f"'{path.name}'",
2221
]
2322
process = Process(
2423
container="quay.io/biocontainers/coreutils:8.30--h14c3975_1000",

src/dcqc/tests/libtiff_info_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ class LibTiffInfoTest(ExternalBaseTest):
99

1010
def generate_process(self) -> Process:
1111
path = self.target.file.stage()
12-
string_path = self._short_string_path(path, "dcqc-staged-")
1312

1413
command_args = [
1514
"tiffinfo",
16-
string_path,
15+
f"'{path.name}'",
1716
]
1817
process = Process(
1918
container="quay.io/sagebionetworks/libtiff:2.0",

src/dcqc/tests/ome_xml_schema_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ class OmeXmlSchemaTest(ExternalBaseTest):
99

1010
def generate_process(self) -> Process:
1111
path = self.target.file.stage()
12-
string_path = self._short_string_path(path, "dcqc-staged-")
1312

1413
command_args = [
1514
"/opt/bftools/xmlvalid",
16-
string_path,
15+
f"'{path.name}'",
1716
]
1817
process = Process(
1918
container="quay.io/sagebionetworks/bftools:latest",

src/dcqc/tests/tiff_tag_306_date_time_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ class TiffTag306DateTimeTest(ExternalBaseTest):
99

1010
def generate_process(self) -> Process:
1111
path = self.target.file.stage()
12-
string_path = self._short_string_path(path, "dcqc-staged-")
1312

1413
command_args = [
1514
"tifftools",
1615
"dump",
17-
string_path,
16+
f"'{path.name}'",
1817
"|",
1918
"grep", # pipe the output
2019
"-a", # treat input as text

tests/test_tests.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,3 @@ def test_that_paired_fastq_parity_test_correctly_handles_compressed_fastq_files(
324324
test = tests.PairedFastqParityTest(target)
325325
test_status = test.get_status()
326326
assert test_status == TestStatus.PASS
327-
328-
329-
def test_that_short_string_path_correctly_shortens_file_paths():
330-
substring = "test-substring"
331-
long_path = f"path/needs/to/be/shortened/{substring}/file.txt"
332-
expected_short_path = f"'{substring}/file.txt'"
333-
short_path = ExternalTestMixin._short_string_path(Path(long_path), substring)
334-
assert short_path == expected_short_path
335-
336-
337-
def test_that_short_string_path_raises_valueerror_if_substring_not_in_path():
338-
substring = "test-substring"
339-
long_path = "path/needs/to/be/shortened/fail/file.txt"
340-
with pytest.raises(ValueError):
341-
ExternalTestMixin._short_string_path(Path(long_path), substring)

0 commit comments

Comments
 (0)