Craftr Magic Explained

Craftr uses some magic tricks behind the scenes to make the interface as convenient as possible. Most of the magic comes from the craftr.magic module!

Proxies

Craftr uses the werkzeug.local module to provide the craftr.session and craftr.module proxies that represent the current session and currently executed module respectively. This is how the craftr.Target constructor (and subsequently all functions that create a Target) knows in what module the target is being declared.

Target Name Deduction

Target names are automatically deduced from the variable name that the declared target is assigned to. This is enabled by parsing the bytecode of the global stackframe of the current module. This is more convenient that writing the name of the target twice by passing the name parameter to the craftr.Target constructor or a rule function.

objects = Target(
  command = 'gcc $in -o $out -c',
  inputs = sources,
  outputs = objects,
)
assert objects.name == 'objects'

Check the craftr.magic.get_assigned_name() function for details on the implementation of this feature.

Craftr RTS

The Craftr Runtime Server is a socket server that is started on a random port on the localhost when Craftr is started. The craftr-rts command can connect to that server and execute Python functions in the original Craftr process. See RTS & Python Tools for more information.