curry.backends.py.toolchain module

The build step of the Python backend: ICurry-JSON to a Python module, with its bytecode cache.

A generated file carries a format stamp (compiler.FORMAT_VERSION). Json2Py, the step that writes the file, refuses a cached file of another stamp, or of none; the plan then writes the file again from the JSON file. See is_stale.

class curry.backends.py.toolchain.Json2Py(interp)[source]

Bases: Json2TargetSource

NAME = 'json2py'
SUFFIX = '.py'
is_stale(filename, currypath=None)[source]

Tells whether a cached file of this step is out of date (source_is_stale). The plan then starts again from the JSON file (Plan.prune_stale). The plan asks about the JSON input of this step as well, which is never refused.

curry.backends.py.toolchain.bytecode_file(pyfile)[source]

The bytecode cache of a generated Python file, as importlib names it.

curry.backends.py.toolchain.bytecode_is_current(pyfile)[source]

True when the bytecode cache of pyfile exists and importlib would load it: its header names the size and the time stamp of the file as it is now, or, for a hash-based cache, the hash of its contents.

curry.backends.py.toolchain.compile_bytecode(pyfile)[source]

Writes the bytecode cache of pyfile beside it, under __pycache__. The loader reads the cache instead of the source while the source keeps its size and time stamp. The cache is written whether or not the process runs with -B: it is a product of the toolchain, like the file itself, not a by-product of an import. A cache that cannot be written is logged and skipped; the file loads from source then.

curry.backends.py.toolchain.ensure_bytecode(pyfile)[source]

Writes the bytecode cache of pyfile unless a current one exists.

curry.backends.py.toolchain.extend_plan_skeleton(interp, skeleton)[source]
curry.backends.py.toolchain.format_version(file_in)[source]

The format stamp of a generated file. A file without one is format 1.

curry.backends.py.toolchain.source_is_stale(file_in)[source]

Tells whether a generated Python file is out of date: its format stamp is not the emitter’s (compiler.FORMAT_VERSION). The emitter writes other code now, so the plan writes the file again from the JSON file.