Skip to content

Commit

Permalink
Add a hidden argument to retain the tempdir
Browse files Browse the repository at this point in the history
Add spaces around input files in commands. Fixes shell parsing for input
files with spaces
  • Loading branch information
DonFreed committed Jan 5, 2024
1 parent d12f377 commit 0a79561
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 10 additions & 4 deletions sentieon_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def tmp():
"""Create a temporary directory for the current process."""
tmp_base = os.getenv("SENTIEON_TMPDIR")
tmp_dir = tempfile.TemporaryDirectory(dir=tmp_base)
tmp_dir = tempfile.mkdtemp(dir=tmp_base)
return tmp_dir


Expand Down Expand Up @@ -165,6 +165,10 @@ def _path_arg(arg: str) -> pathlib.Path:
"--skip-version-check",
help=argparse.SUPPRESS,
)
@arg(
"--retain-tmpdir",
help=argparse.SUPPRESS,
)
def dnascope_longread(
output_vcf: pathlib.Path,
reference: Optional[pathlib.Path] = None,
Expand All @@ -178,6 +182,7 @@ def dnascope_longread(
dry_run: bool = False,
repeat_model: Optional[pathlib.Path] = None,
skip_version_check: bool = False,
retain_tmpdir: bool = False,
**kwargs: str,
):
"""
Expand All @@ -194,8 +199,8 @@ def dnascope_longread(
for cmd, min_version in TOOL_MIN_VERSIONS.items():
check_version(cmd, min_version)

tmp_dir_obj = tmp()
tmp_dir = pathlib.Path(tmp_dir_obj.name)
tmp_dir_str = tmp()
tmp_dir = pathlib.Path(tmp_dir_str)

if dry_run:
run = print
Expand Down Expand Up @@ -440,7 +445,8 @@ def dnascope_longread(
)
)

shutil.rmtree(tmp_dir)
if not retain_tmpdir:
shutil.rmtree(tmp_dir_str)
return


Expand Down
8 changes: 4 additions & 4 deletions sentieon_cli/command_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def build_cmd(self) -> List[str]:
elif isinstance(v, list):
for i in v:
cmd.append(f"--{k}")
cmd.append(str(i))
cmd.append(f"'{i}'")
elif isinstance(v, bool):
if v:
cmd.append(f"--{k}")
else:
cmd.append(f"--{k}")
cmd.append(str(v))
cmd.append(f"'{v}'")

if "output" in self.__dict__:
cmd.append(str(self.__dict__["output"]))
Expand Down Expand Up @@ -183,13 +183,13 @@ def build_cmd(self) -> List[str]:
elif isinstance(v, list):
for i in v:
cmd.append(f"--{k}")
cmd.append(str(i))
cmd.append(f"'{i}'")
elif isinstance(v, bool):
if v:
cmd.append(f"--{k}")
else:
cmd.append(f"--{k}")
cmd.append(str(v))
cmd.append(f"'{v}'")

for algo in self.algo:
cmd.extend(algo.build_cmd())
Expand Down
6 changes: 3 additions & 3 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def test_one():
def test_tmp():
"""basic test for tmp()"""
tmp_dir = sentieon_cli.tmp()
assert os.path.exists(tmp_dir.name)
assert os.path.isdir(tmp_dir.name)
shutil.rmtree(tmp_dir.name)
assert os.path.exists(tmp_dir)
assert os.path.isdir(tmp_dir)
shutil.rmtree(tmp_dir)


def test_find_script():
Expand Down

0 comments on commit 0a79561

Please sign in to comment.