Home | Download/Install | Documentation | Packages | Screenshots | News | Forum/Mailing-lists | Contact | GForge

Automagic Package generation

Problem

Use case : Developer should be able to create a Package from an existing library with a minimal effort.

Pb : Whereas introspection and decoration would allow to define factories, a user have to register manually all the Factory in a wralea file. How to minimize the development effort to ease package creation on a decorated Python library? What are the syntax of the decorator to be implemented? How to integrate this in the setup.py and with the Package Manager?

Proposed solution

We propose to change the package declaration as follow :

  • A package = A dynamically created module define by an entry_point.
  • Decorators
Decorator
@factory
def f(*args):
    """
    f(a: int = 3, b: float = 1., c: bool = True) -> z: int
    """
 
@inputs('a: expression =val', 'b : IFloat = default', 'c=True')
@factory
def f(*args):
    """
    f(*args) -> z: int
    """
 
@outputs('z: interface')
@factory
def f(a=3, b=1., c=True):
    """
    My super fonction
    """
 
@inputs('a: expression =val', 'b : IFloat = default', 'c=True')
@outputs('z: interface')
@factory
def f(a,b,c):
    """
    f(a: int = 3, b: float = 1., c: bool = True) -> z: int
    """
 
@widget(MyWidget)
@factory
class Plant(object):
 
    @factory
    def f(self):
      pass 
 
Package

How to declare the module as a package?

Solution 1

In a file wralea.py or an entry_point named wralea:

from openalea.core import Package
Package(name='MyPackage.Foo', module='mypackage.foo')

Solution 2

In a file wralea.py or an entry_point named wralea:

__name__='MyPackage.Foo'
__package__ = 'mypackage.foo'

Solution 3

In a setup.py

from openalea.deploy import generate_wralea
 
wraleas = generate_wralea('src')
setup(entry_points= {'wralea'=wraleas})

Solution 4

In a setup.py

from openalea.deploy import find_openalea_package
 
pkgs = find_openalea_package('src')
# pkgs : ['name': 'package']
setup(entry_points= {'openalea.packages'=pkgs})
Signature

The expected/potential signature of decorated function should follow PEP-362 implementation rules.

Pep Function Annotations: http://www.python.org/dev/peps/pep-3107/

todo:

  • make new version of Signature
  • replace signature in factory_parser.make_module by new version
  • make a (1-line) serialization of Factory
  • implement todo in openalea.core.node.NodeFactory.instanstiate (l 1145). Update inputs and outputs data from decorator annotations
  • rename NodeFactory in Factory. keep NodeFactory as an alias?
  • finish test_signature2.py (and so complete signature2.py)
  • BUG: factory decorator fails if module is not in standard path.

To define

  • How to handle caption, category, … ex: @factory(caption=…) or @caption(…)
  • If @inputs or @outputs is defined, is it necessary to define @factory ?
  • Currently, if @factory is defined, func name is appended to current module. Maybe this information could be stored in a general singleton

nota : …

 
documentation/core/propositions/104_automagic_package_generation.txt · Last modified: 2013/12/12 18:16 by user   Back to top
INRIA   INRA     CIRAD     AGROPOLIS IBC
INRIA GForge RSS feed Valid XHTML 1.0 Valid CSS Driven by DokuWiki