Skip to content

Commit

Permalink
update run
Browse files Browse the repository at this point in the history
  • Loading branch information
keurfonluu committed Aug 8, 2023
1 parent 4ce9a51 commit c43fc24
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions toughio/_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import glob
import os
import pathlib
import platform
import shutil
import subprocess
import sys
import tempfile


Expand Down Expand Up @@ -39,7 +39,7 @@ def run(
docker : str, optional, default None
Name of Docker image.
wsl : bool, optional, default False
Only for Windows. If `True`, run the final command as a Bash command. Ignored if `docker` is not None.
Only for Windows. If `True`, run the final command as a Bash command.
working_dir : str, pathlike or None, optional, default None
Working directory. Input and output files will be generated in this directory.
use_temp : bool, optional, default False
Expand Down Expand Up @@ -151,26 +151,31 @@ def run(
if workers is not None and workers > 1:
cmd = f"mpiexec -n {workers} {cmd}"

# Use Docker or WSL
platform = sys.platform

# Use Docker
if docker:
if platform.startswith("win") and os.getenv("ComSpec").endswith("cmd.exe"):
if platform.system().startswith("Win") and os.getenv("ComSpec").endswith(
"cmd.exe"
):
cwd = "%cd%"

else:
cwd = "${PWD}"

cmd = f"docker run --rm -v {cwd}:/work -w /work {docker} {cmd}"

elif wsl and platform.startswith("win"):
# Use WSL
if wsl and platform.system().startswith("Win"):
cmd = f'bash -c "{cmd}"'

kwargs = {}
if silent:
kwargs["stdout"] = subprocess.DEVNULL
kwargs["stderr"] = subprocess.STDOUT

else:
kwargs["stderr"] = subprocess.PIPE
kwargs["universal_newlines"] = True

status = subprocess.run(cmd, shell=True, cwd=str(simulation_dir), **kwargs)

# Copy files from temporary directory and delete it
Expand Down

0 comments on commit c43fc24

Please sign in to comment.