Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoon committed Oct 17, 2024
1 parent e94210f commit 637b05d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
26 changes: 16 additions & 10 deletions python/src/apbs_binary/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import platform
import subprocess
import sys
from copy import deepcopy
from pathlib import Path
from typing import Any, Literal, overload

Expand Down Expand Up @@ -66,19 +67,24 @@ def process_run(
) -> int | subprocess.CompletedProcess[str | bytes]:
# if mac arm64, set DYLD_LIBRARY_PATH
if sys.platform == "darwin":
my_env = os.environ.copy()
my_env["DYLD_LIBRARY_PATH"] = str(LIB_DIR)
my_env: dict[str, str]
if kwargs.get("env") is not None:
my_env = deepcopy(kwargs["env"])
my_env["DYLD_LIBRARY_PATH"] = str(LIB_DIR)
else:
my_env = os.environ.copy()
my_env["DYLD_LIBRARY_PATH"] = str(LIB_DIR)
complete_process = subprocess.run(
[bin_path(bin_name), *args], env=my_env, **kwargs
)
elif os.name == "nt":
# dll files are together with the binaries.
# so we need to add the directory to PATH
my_env = os.environ.copy()
my_env["PATH"] = f"{BIN_DIR!s};{my_env['PATH']}"
complete_process = subprocess.run(
[bin_path(bin_name), *args], env=my_env, shell=True, **kwargs
)
# elif os.name == "nt":
# # dll files are together with the binaries.
# # so we need to add the directory to PATH
# my_env = os.environ.copy()
# my_env["PATH"] = f"{BIN_DIR!s};{my_env['PATH']}"
# complete_process = subprocess.run(
# [bin_path(bin_name), *args], env=my_env, shell=True, **kwargs
# )
else:
complete_process = subprocess.run([bin_path(bin_name), *args], **kwargs)

Expand Down
59 changes: 39 additions & 20 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from collections.abc import Callable
from pathlib import Path

Expand All @@ -10,6 +11,29 @@
process_run,
)

RETURN_CODE_NO_ARGS = (
[
("apbs", 13),
("multivalue", 1),
("analysis", 2),
("benchmark", 12),
("born", 154),
("coulomb", 154),
("del2dx", 1),
("dx2mol", 1),
("dx2uhbd", 1),
("dxmath", 13),
("mergedx", 255),
("mergedx2", 1),
("mgmesh", 0),
("similarity", 2),
("smooth", 2),
("tensor2dx", 255),
("uhbd_asc2bin", -11),
("value", 2),
],
)


@pytest.mark.parametrize(
"bin_path",
Expand Down Expand Up @@ -56,32 +80,27 @@ def test_execute_noarg(func: Callable, expected_return_code: int):

@pytest.mark.parametrize(
("bin_name", "expected_return_code"),
[
("apbs", 13),
("multivalue", 1),
("analysis", 2),
("benchmark", 12),
("born", 154),
("coulomb", 154),
("del2dx", 1),
("dx2mol", 1),
("dx2uhbd", 1),
("dxmath", 13),
("mergedx", 255),
("mergedx2", 1),
("mgmesh", 0),
("similarity", 2),
("smooth", 2),
("tensor2dx", 255),
("uhbd_asc2bin", -11),
("value", 2),
],
RETURN_CODE_NO_ARGS,
)
def test_process_run_noarg(bin_name: str, expected_return_code: int):
return_code = process_run(bin_name)
assert return_code == expected_return_code


@pytest.mark.parametrize(
("bin_name", "expected_return_code"),
RETURN_CODE_NO_ARGS,
)
def test_process_run_noarg_with_env(bin_name: str, expected_return_code: int):
"""
In macOS, the env variable `DYLD_LIBRARY_PATH` is required to run the binaries. Thus, we check if custom env settings still respect this.
"""
my_env = os.environ.copy()
my_env["PATH"] = "/usr/local/bin" # dummy change. Not important
return_code = process_run(bin_name, env=my_env)
assert return_code == expected_return_code


@pytest.mark.parametrize(
("func", "line_number", "line_match"),
[
Expand Down

0 comments on commit 637b05d

Please sign in to comment.