graintrace.neper_env#

Locate a user-provided NEPER binary and build a subprocess environment for it.

graintrace drives NEPER as an external tool; like CUBIT/SCULPT it is not a pip package and must be installed by the user. Install NEPER once (see https://neper.info/doc/introduction.html#installing-neper) and graintrace will find it, in this order:

  1. an explicit neper_path / env= passed to the builder,

  2. the NEPER environment variable (absolute path to the neper binary),

  3. the neper key of a graintrace_tools.json (see graintrace.mcp.tool_paths),

  4. neper on PATH (shutil.which).

gmsh, by contrast, is a pip package (declared in pyproject.toml and installed with graintrace), so it needs no discovery here.

For the legacy convenience of a from-source build on Linux, pass auto_install=True (opt-in): it builds GSL, OpenBLAS and NEPER into ~/.local exactly as older graintrace did. The default path never downloads or compiles anything.

graintrace.neper_env.find_neper(neper_path=None)[source]#

Resolve the neper binary path, or None if it cannot be found.

Order: explicit neper_path -> NEPER env var -> tools.json neper key -> shutil.which("neper").

Parameters:

neper_path (str | None)

Return type:

str | None

graintrace.neper_env.build_env(neper_bin=None)[source]#

Copy os.environ and, given a neper_bin, put its dir/libs on the path.

Prepends the binary’s directory to PATH and the sibling lib/lib64 of its install prefix to LD_LIBRARY_PATH so a self-built NEPER (e.g. under ~/.local/bin) finds its GSL/OpenBLAS shared libraries.

Parameters:

neper_bin (str | None)

Return type:

dict

graintrace.neper_env.resolve_neper_env(neper_path=None, auto_install=False)[source]#

Return (neper_bin, env) for driving NEPER, or raise a clear error.

Looks NEPER up via find_neper(). If not found and auto_install is True, builds it from source under ~/.local (Linux only); otherwise raises RuntimeError with install guidance.

Parameters:
  • neper_path (str | None)

  • auto_install (bool)

Return type:

Tuple[str, dict]