forked from mdekauwe/CABLE_benchmarking
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add requested changes from code review
- Loading branch information
1 parent
e2813ac
commit 88f2575
Showing
13 changed files
with
487 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""A module containing utility functions that wraps around the `subprocess` module.""" | ||
|
||
import subprocess | ||
import contextlib | ||
import pathlib | ||
from typing import Any, Optional | ||
|
||
|
||
def run_cmd( | ||
cmd: str, | ||
capture_output: bool = False, | ||
output_file: Optional[pathlib.Path] = None, | ||
verbose: bool = False, | ||
) -> subprocess.CompletedProcess: | ||
"""Helper function that wraps around `subprocess.run()`""" | ||
|
||
kwargs: Any = {} | ||
with contextlib.ExitStack() as stack: | ||
if capture_output: | ||
kwargs["capture_output"] = True | ||
kwargs["text"] = True | ||
else: | ||
if output_file: | ||
kwargs["stdout"] = stack.enter_context( | ||
output_file.open("w", encoding="utf-8") | ||
) | ||
else: | ||
kwargs["stdout"] = None if verbose else subprocess.DEVNULL | ||
kwargs["stderr"] = subprocess.STDOUT | ||
|
||
if verbose: | ||
print(cmd) | ||
proc = subprocess.run(cmd, shell=True, check=True, **kwargs) | ||
|
||
return proc |
Oops, something went wrong.