Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIx output reader #146

Merged
merged 13 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pygmsh
seaborn
sphinx == 5.3
sphinx
sphinx-argparse
sphinx-gallery
pydata-sphinx-theme
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import toughio

project = "toughio"
copyright = "2022, Keurfon Luu"
copyright = "2023, Keurfon Luu"
author = "Keurfon Luu"

version = toughio.__version__
Expand Down
87 changes: 87 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import platform
import sys

import pytest

import toughio


@pytest.mark.parametrize(
"exec, workers, docker, wsl, cmd",
[
("tough-exec", None, None, False, "tough-exec INFILE INFILE.out"),
("tough-exec", 8, None, False, "mpiexec -n 8 tough-exec INFILE INFILE.out"),
],
)
def test_run(exec, workers, docker, wsl, cmd):
status = toughio.run(
exec,
{},
workers=workers,
docker=docker,
wsl=wsl,
use_temp=sys.version_info
>= (3, 8), # dirs_exist_ok only works with Python > 3.8
silent=True,
)

assert status.args == cmd


@pytest.mark.skipif(
not platform.system().startswith("Win"), reason="requires Windows platform"
)
@pytest.mark.parametrize(
"exec, workers, docker, wsl, cmd",
[
(
"tough-exec",
None,
"docker-image",
False,
"docker run --rm -v PLACEHOLDER:/shared -w /shared docker-image tough-exec INFILE INFILE.out",
),
("tough-exec", None, None, True, "bash -c 'tough-exec INFILE INFILE.out'"),
(
"tough-exec",
8,
"docker-image",
True,
"""bash -c 'docker run --rm -v PLACEHOLDER:/shared -w /shared docker-image mpiexec -n 8 tough-exec INFILE INFILE.out'""",
),
],
)
def test_run_windows(exec, workers, docker, wsl, cmd):
if os.getenv("ComSpec").endswith("cmd.exe"):
cmd = cmd.replace("PLACEHOLDER", '"%cd%"')

else:
cmd = cmd.replace("PLACEHOLDER", "${PWD}")

test_run(exec, workers, docker, wsl, cmd)


@pytest.mark.skipif(
platform.system().startswith("Win"), reason="requires Unix platform"
)
@pytest.mark.parametrize(
"exec, workers, docker, cmd",
[
(
"tough-exec",
None,
"docker-image",
"docker run --rm PLACEHOLDER -v ${PWD}:/shared -w /shared docker-image tough-exec INFILE INFILE.out",
),
(
"tough-exec",
8,
"docker-image",
"docker run --rm PLACEHOLDER -v ${PWD}:/shared -w /shared docker-image mpiexec -n 8 tough-exec INFILE INFILE.out",
),
],
)
def test_run_unix(exec, workers, docker, cmd):
cmd = cmd.replace("PLACEHOLDER", f"-e LOCAL_USER_ID={os.getuid()}")
test_run(exec, workers, docker, False, cmd)
2 changes: 1 addition & 1 deletion toughio/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.13.0
1.13.1
10 changes: 1 addition & 9 deletions toughio/_io/output/tough/_tough.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,7 @@ def _read_table(f, file_type):
if line[:nwsp].strip() and not line.strip().startswith("ELEM"):
if first:
# Find first floating point
for xf in line.split()[::-1]:
try:
_ = int(xf)

except ValueError:
x = xf
continue

break
x = line.split()[-headers[::-1].index("INDEX")]

# Find end of label(s)
tmp = line[: line.index(x)].rstrip()
Expand Down
22 changes: 14 additions & 8 deletions toughio/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,26 @@ def run(
cmd = f"mpiexec -n {workers} {cmd}"

# Use Docker
is_windows = platform.system().startswith("Win")

if docker:
if platform.system().startswith("Win") and os.getenv("ComSpec").endswith(
"cmd.exe"
):
cwd = "%cd%"
if is_windows and os.getenv("ComSpec").endswith("cmd.exe"):
cwd = '"%cd%"'

else:
cwd = "${PWD}"

cmd = f"docker run --rm -v {cwd}:/work -w /work {docker} {cmd}"
try:
uid = f"-e LOCAL_USER_ID={os.getuid()}"

except AttributeError:
uid = ""

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

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

kwargs = {}
if silent:
Expand All @@ -184,7 +190,7 @@ def run(
simulation_dir,
working_dir,
ignore=shutil.ignore_patterns(*ignore_patterns),
dirs_exist_ok=True,
dirs_exist_ok=True, # Doesn't work with Python 3.7
)
shutil.rmtree(simulation_dir, ignore_errors=True)
os.remove(working_dir / "tempdir.txt")
Expand Down
Loading