|
| 1 | +import os |
1 | 2 | from pathlib import Path |
2 | 3 | from platform import system |
3 | 4 |
|
4 | 5 | import pytest |
| 6 | +from modflow_devtools.download import download_and_unzip |
5 | 7 | from modflow_devtools.misc import is_in_ci |
6 | 8 |
|
7 | 9 | pytest_plugins = ["modflow_devtools.fixtures"] |
|
12 | 14 | EXCLUDED_EXAMPLES = [] |
13 | 15 |
|
14 | 16 |
|
| 17 | +def _get_dfn_path(tmp_path_factory): |
| 18 | + """Get path to MF6 DFN files, checking local repos or downloading if needed.""" |
| 19 | + |
| 20 | + # Check REPOS_PATH environment variable (modflow-devtools convention) |
| 21 | + repos_path = os.environ.get("REPOS_PATH") |
| 22 | + if repos_path: |
| 23 | + dfn_path = Path(repos_path) / "modflow6" / "doc" / "mf6io" / "mf6ivar" / "dfn" |
| 24 | + if dfn_path.exists(): |
| 25 | + return dfn_path |
| 26 | + |
| 27 | + # Check if modflow6 repo exists as sibling to this project |
| 28 | + sibling_path = PROJ_ROOT_PATH.parent / "modflow6" / "doc" / "mf6io" / "mf6ivar" / "dfn" |
| 29 | + if sibling_path.exists(): |
| 30 | + return sibling_path |
| 31 | + |
| 32 | + # Download from GitHub if not found locally |
| 33 | + tmp_dir = tmp_path_factory.mktemp("mf6_dfn") |
| 34 | + url = "https://github.com/MODFLOW-USGS/modflow6/archive/refs/heads/develop.zip" |
| 35 | + download_and_unzip(url, tmp_dir, verbose=False) |
| 36 | + |
| 37 | + # Find the extracted directory (will have a prefix like 'modflow6-develop') |
| 38 | + extracted_dirs = [d for d in tmp_dir.iterdir() if d.is_dir() and d.name.startswith("modflow6")] |
| 39 | + if not extracted_dirs: |
| 40 | + pytest.fail(f"Failed to extract modflow6 from {url}") |
| 41 | + |
| 42 | + dfn_path = extracted_dirs[0] / "doc" / "mf6io" / "mf6ivar" / "dfn" |
| 43 | + if not dfn_path.exists(): |
| 44 | + pytest.fail("DFN directory not found in downloaded modflow6 repo") |
| 45 | + |
| 46 | + return dfn_path |
| 47 | + |
| 48 | + |
| 49 | +@pytest.fixture(scope="session") |
| 50 | +def dfn_path(tmp_path_factory): |
| 51 | + """Get the path to MF6 DFN files.""" |
| 52 | + return _get_dfn_path(tmp_path_factory) |
| 53 | + |
| 54 | + |
15 | 55 | @pytest.fixture(scope="session", autouse=True) |
16 | 56 | def patch_macos_ci_matplotlib(): |
17 | 57 | # use noninteractive matplotlib backend if in Mac OS CI to avoid pytest-xdist node failure |
|
0 commit comments