On 07/22/2011 12:12 PM, mark florisson wrote:
For my work on the _memview branch (and also on fused types) I noticed
that UtilityCodes started weighing heavily on me in their current
form, so I wrote a little loader in the _memview branch:

https://github.com/markflorisson88/cython/commit/e13debed2db78680ec0bd8c343433a2b73bd5e64#L2R110

The idea is simple: you put your utility codes in Cython/Utility in
.pyx, .c, .h files etc, and then load them. It works for both
prototypes and implementations, for UtilityCode and CythonUtilityCode:

myutility.c

// UtilityProto: MyUtility
header code here

// UtilityCode: MyUtility
implementation code here

You can add as many other utilities as you like to the same file. You
can then load it using

     UtilityCode.load_utility_from_file("myutility.c", "MyUtility")

Of course you can pass in any other arguments, like proto_block, name,
etc. You can additionally pass it a dict for formatting (for both the
prototypes and the implementation). It will return a UtilityCode
instance ready for use.
You can also simply retrieve a utility code as a string, where it
returns (proto, implementation).

As debated before, an actual template library would be really
convenient. Dag and I had a discussion about it and he suggested
Tempita (by Ian Bicking), it is compatible with Python 2 and Python 3,
and is pure-python. It supports all the good things like iteration,
template inheritance, etc. Now I'm not sure whether it supports python
2.3 as it doesn't compile on my system, but it does support 2.4
(confirmation for 2.3 would be appreciated). On a side note, I'd be
perfectly happy to drop support for 2.3, it's kind of a chore.
The documentation for Tempita can be found here: http://pythonpaste.org/tempita/

Also important:

(master) ~/code/tempita $ sloccount tempita/
SLOC    Directory       SLOC-by-Language (Sorted)
1050    tempita         python=1050

That is, 1050 source code lines. So it can easily (and should probably) be bundled with Cython, in the same way Plex is.

Dag Sverre
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to