Skip to content

Commit 7645d0a

Browse files
committed
add common workspace dir
1 parent 9b62653 commit 7645d0a

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

pyvcell/vcml/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from pyvcell.vcml.vcml_reader import VcmlReader
4141
from pyvcell.vcml.vcml_writer import VcmlWriter
42+
from pyvcell.vcml.workspace import get_workspace_dir, set_workspace_dir
4243

4344
__all__ = [
4445
"VCMLDocument",
@@ -79,4 +80,6 @@
7980
"load_vcml_file",
8081
"load_sbml_file",
8182
"load_antimony_file",
83+
"get_workspace_dir",
84+
"set_workspace_dir",
8285
]

pyvcell/vcml/workspace.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from os import PathLike
2+
from pathlib import Path
3+
4+
workspace_dir: Path = Path.cwd() / "workspace"
5+
6+
7+
def set_workspace_dir(path: PathLike[str]) -> None:
8+
"""Set the workspace directory for VCell simulations."""
9+
global workspace_dir
10+
workspace_dir = Path(path)
11+
12+
13+
def get_workspace_dir() -> Path:
14+
"""Get the current workspace directory for VCell simulations."""
15+
if not workspace_dir.exists():
16+
workspace_dir.mkdir(parents=True, exist_ok=True)
17+
return workspace_dir

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
solver_output_simid_jobid,
55
temp_sim_946368938_path,
66
zarr_path,
7+
temp_workspace
78
)
89
from tests.fixtures.model_fixtures import ( # noqa: F401
910
sbml_spatial_bunny_3d_path,

tests/fixtures/data_fixtures.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import shutil
12
import tarfile
23
import tempfile
34
from collections.abc import Generator
45
from pathlib import Path
56

67
import pytest
78

9+
from pyvcell.vcml import get_workspace_dir, set_workspace_dir
10+
811
ROOT_DIR = Path(__file__).parent.parent.parent
912
FIXTURE_DATA_DIR = ROOT_DIR / "tests" / "fixtures" / "data"
1013

@@ -37,3 +40,16 @@ def temp_sim_946368938_path() -> Generator[Path, None, None]:
3740
@pytest.fixture
3841
def fielddata_file_path() -> Path:
3942
return FIXTURE_DATA_DIR / "SimID_1232918682_0_test2_lsm_DEMO_species0_cyt_0_5_Volume.fdat"
43+
44+
45+
@pytest.fixture(scope="function", autouse=True)
46+
def temp_workspace() -> Generator[Path, None, None]:
47+
with tempfile.TemporaryDirectory() as temp_dir:
48+
temp_dir_path = Path(temp_dir)
49+
temp_dir_path.mkdir(parents=True, exist_ok=True)
50+
saved_workspace_dir = get_workspace_dir()
51+
set_workspace_dir(temp_dir_path)
52+
53+
yield temp_dir_path
54+
55+
set_workspace_dir(saved_workspace_dir)

0 commit comments

Comments
 (0)