Skip to content

Spec for Component.py

Daniel Chatfield edited this page Jul 30, 2013 · 12 revisions

This is very much a work in progress.

Building using component-build

To prevent component.py from adding any noticeable overhead it is neccesary to do similar building as is done with javascript components.

This involves creating a component_config.py file in the build directory which defines all the component contexts and aliases component to username-component.

File structure

Currently component is a single python file, it is possible that in the future it will become a full module but apart from making the name slightly misleading this won't make it backward-incompatible.

Consuming components in python

from component import require

example_component = require("example-component")

Exporting objects

By default requiring a component would just return the module, however if your component is just a function you can decorate it with @export and just the function will be exported.

from component import export

@export
def my_function(){

}

I plan to support the exporting of any python object.

Todo

Library

  • Should cache modules using sys.modules.

Builder

  • Should include builder version number, and required component.py version number in compiled config file so component.py can warn when if it's version isn't compatible with builder version.

Error handling

  • Should warn if component has two dependencies with same name (although this can still work, they just won't be aliased).