1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
"""sets as working directory the parent of data/
Assumes this file is distributed inside COGENT3_ROOT/doc directory"""
import os
import pathlib
current = pathlib.Path(__file__).absolute().parent
def _data_path(path: os.PathLike) -> os.PathLike:
if path.name != "data":
path = _data_path(path.parent)
return path
def get_data_dir():
"""returns path to cogent3 doc data directory"""
for path in current.glob("*/*"):
if "doc" not in path.parts:
continue
if "data" in path.parts:
if path.parts.index("doc") > path.parts.index("doc"):
continue
path = _data_path(path)
if path.is_dir() and str(path.name) == "data":
return path.parent
raise RuntimeError(f"could not find data dir from {current}")
def get_thumbnail_dir():
"""returns path to directory for writing html thumbnail images"""
thumbdir = pathlib.Path(__file__).parent / "_build" / "html" / "_images"
thumbdir.mkdir(exist_ok=True, parents=True)
return thumbdir
data_dir = get_data_dir()
os.chdir(data_dir)
|