30def ensure_flow(explicit_build=None):
31 """Import and return the `peclet.flow` module, resolved per the module docstring's precedence.
33 `explicit_build`, if given, is a directory to try (e.g. from a script's own --build CLI flag)
34 with the same standing as PECLET_FLOW_BUILD: consulted only when `peclet.flow` is not already
35 importable, and only if PECLET_FLOW_BUILD itself is unset.
37 Always prints one line to stderr naming the resolved module file or inserted directory. Raises
38 SystemExit with a corrective message if `peclet.flow` cannot be found at all.
43 build_dir = os.environ.get(
"PECLET_FLOW_BUILD")
or explicit_build
46 "peclet.flow not importable: set PYTHONPATH=<build tree> "
47 "(e.g. PYTHONPATH=$PWD/build) or PECLET_FLOW_BUILD=<build tree> "
48 "(e.g. PECLET_FLOW_BUILD=$PWD/build_mpi) and rerun."
50 build_dir = os.path.abspath(build_dir)
51 sys.path.insert(0, build_dir)
54 except ImportError
as exc:
56 f
"peclet.flow not importable from build dir {build_dir!r}: {exc}\n"
57 "Fix: point PECLET_FLOW_BUILD (or PYTHONPATH) at a directory containing the "
58 "built peclet/flow/_flow*.so."
60 print(f
"peclet.flow: using build dir {build_dir} -> {flow.__file__}", file=sys.stderr)
62 print(f
"peclet.flow: already importable -> {flow.__file__}", file=sys.stderr)