Skip to content

Commit

Permalink
add option container_name
Browse files Browse the repository at this point in the history
  • Loading branch information
keurfonluu committed Jan 9, 2024
1 parent b0da3bf commit f840cfe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_run(exec, workers, docker, wsl, cmd):
use_temp=sys.version_info >= (3, 8),
ignore_patterns=["INFILE"],
silent=True,
container_name="CONTAINER",
)

assert status.args == cmd
Expand All @@ -44,15 +45,15 @@ def test_run(exec, workers, docker, wsl, cmd):
None,
"docker-image",
False,
"docker run --rm -v PLACEHOLDER:/shared -w /shared docker-image tough-exec INFILE INFILE.out",
"docker run --name CONTAINER --rm --volume PLACEHOLDER:/shared --workdir /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'""",
"""bash -c 'docker run --name CONTAINER --rm --volume PLACEHOLDER:/shared --workdir /shared docker-image mpiexec -n 8 tough-exec INFILE INFILE.out'""",
),
],
)
Expand Down
5 changes: 4 additions & 1 deletion toughio/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def run(
silent=False,
petsc_args=None,
docker_args=None,
container_name=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -60,6 +61,8 @@ def run(
List of arguments passed to PETSc solver (written to `.petscrc`).
docker_args : list or None, optional, default None
List of arguments passed to `docker run` command.
container_name : str or None, optional, default None
Name of Docker container.
Other Parameters
----------------
Expand Down Expand Up @@ -223,7 +226,7 @@ def run(
is_windows = platform.system().startswith("Win")

if docker:
container_name = f"toughio_{secrets.token_hex(4)}"
container_name = container_name if container_name else f"toughio_{secrets.token_hex(4)}"

if is_windows and os.getenv("ComSpec").endswith("cmd.exe"):
cwd = '"%cd%"'
Expand Down

0 comments on commit f840cfe

Please sign in to comment.