Skip to content

Commit fc095fe

Browse files
committed
Improve path resolution
Now tutorial api checks both source tree relative paths and path.cwd which helps docs builds. This needs to support both cloned repo and root repo.
1 parent 9274957 commit fc095fe

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

uxarray/tutorial/__init__.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
from uxarray.tutorial.registry import DATASETS, Component, TutorialDataset
66

7-
_MESHFILES_PATH = Path(__file__).resolve().parents[2] / "test" / "meshfiles"
8-
97

108
def available_datasets() -> tuple[str, ...]:
119
"""Return the names of available tutorial datasets."""
@@ -31,7 +29,7 @@ def file_path(name: str, component: Component | None = None) -> Path:
3129
component = components[0]
3230

3331
path_parts = _get_component_path(dataset, name, component)
34-
path = _MESHFILES_PATH.joinpath(*path_parts)
32+
path = _meshfiles_path().joinpath(*path_parts)
3533

3634
if not path.exists():
3735
raise FileNotFoundError(
@@ -51,7 +49,8 @@ def file_paths(name: str) -> tuple[Path, ...]:
5149
"Use uxarray.tutorial.file_path(...) instead."
5250
)
5351

54-
paths = tuple(_MESHFILES_PATH.joinpath(*parts) for parts in dataset.data_files)
52+
meshfiles_path = _meshfiles_path()
53+
paths = tuple(meshfiles_path.joinpath(*parts) for parts in dataset.data_files)
5554

5655
for path in paths:
5756
if not path.exists():
@@ -126,6 +125,24 @@ def _get_dataset_entry(name: str) -> TutorialDataset:
126125
return dataset
127126

128127

128+
def _meshfiles_path() -> Path:
129+
"""Support both local development from a cloned
130+
repo and cwd fallback supports docs builds that run from the root repo"""
131+
candidates = (
132+
Path(__file__).resolve().parents[2] / "test" / "meshfiles",
133+
Path.cwd() / "test" / "meshfiles",
134+
)
135+
136+
for path in candidates:
137+
if path.exists():
138+
return path
139+
140+
checked = ", ".join(str(path) for path in candidates)
141+
raise FileNotFoundError(
142+
f"Could not locate the tutorial dataset directory. Checked: {checked}"
143+
)
144+
145+
129146
def _available_components(dataset: TutorialDataset) -> tuple[Component, ...]:
130147
if dataset.data is None:
131148
return ("grid",)

0 commit comments

Comments
 (0)