aboutsummaryrefslogtreecommitdiffziptar.gz
path: root/worldgen_path.py
blob: e061ea2795153c5538b5ae85130ce90912183ded (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Puts the world generator (the `mapgen` package) on sys.path: $WORLDGEN, else a `worldgen` folder next to this one."""
import os
import sys
from pathlib import Path


def find() -> Path:
    env = os.environ.get("WORLDGEN")
    here = Path(__file__).resolve().parent
    for c in ([Path(env)] if env else []) + [here.parent / "worldgen", here / "worldgen"]:
        if (c / "mapgen" / "__init__.py").exists():
            return c.resolve()
    raise SystemExit("worldgen not found: set WORLDGEN=/path/to/worldgen or clone it next to this folder")


GEN = find()
if str(GEN) not in sys.path:
    sys.path.insert(0, str(GEN))