← board

Document __file__ and where a NilPy program's data files live

What to write, and where

The NilPy target page (docs/targets/nil-python.md) is the home; it already carries the "what differs from CPython" material a reader needs this next to.

The one paragraph that matters to a user:

A compiled NilPy program has no source file at run time, so __file__ names the executable: for the main module it is the binary's own path, and for an imported module it is that binary's directory plus the module's file name — a path that need not exist. sys.executable is the same binary. This means os.path.dirname(os.path.abspath(__file__)) — the usual way to find data files that ship with a program — resolves to the directory the executable is in. Put your data files next to the binary.

Then the two consequences, stated plainly rather than buried:

Tone: this is a property, not an apology

Frozen Python (PyInstaller, cx_Freeze) makes the same choice for the same reason, and it is worth one sentence saying so — a reader who has shipped a frozen app already knows this shape. Do not present it as a limitation; present it as "here is where a compiled program's data lives".

Do not document --data-root: it is deliberately unbuilt (see the decision ticket). If it lands later, this page is where it goes.

Cross-references to keep in step

If the behaviour is ever revisited — a new use case, a change of mind — these four must move together:

Gate

Docs internally consistent; every snippet compiled against $(PXX_STABLE) and its printed output checked, running the binary from a different directory than it was compiled in — otherwise the example demonstrates nothing (the CWD and the source directory coincide, which is exactly the blind spot that hid this bug until 2026-08-13).

Log