Friday, May 01, 2009

A Good Mix 4: NWSGI, AutoCAD, Another ctypes and C# in Depth

Another fine selection of IronPython related links for your delectation.
NWSGI is "a .NET implementation of the Python WSGI specification for IronPython. It is implemented as an ASP.NET HttpHandler for use with IIS 6 and 7" created by Jeff Hardy. The goal is to be able to run Python applications like Django, Trac and Pylons on IronPython. It can also be used on the Microsoft Azure (cloud computing) platform.

This new release is a pre-release which depends on IronPython 2.6 Alpha 1. The following features/changes have been added to NWSGI:
  • Add "callable" attribute to scriptMapping to specify the callable for that script.
  • Allow for "virtual" scripts by extending callables to allow for package.module:callable.
  • This can avoid creating a .wsgi file in many scenarios. This can be used with wildcard mappings by specifying wildcardModule=":callable".
  • Use the "debug" attribute on system.web/compilation instead of on wsgi.

This is quite a long entry, but almost entirely example code. It continues the "Through the Interface" blog series on Automating AutoCAD with IronPython. This entry ports an example of using the AutoCAD 2010 overrule API from C# to IronPython.
Jeff Hardy has started an implementation of the Python FFI ctypes for IronPython, written in C#. As more and more standard library modules are implemented using ctypes rather than as traditional C extensions, it is becoming more important to have a working ctypes for IronPython. Even more so as Jython and PyPy both have ctypes - so using ctypes is one way of making extension libraries compatible across different implementations of Python.

Jeff has made what he has done so far available for download, with a fairly big caveat:
Support isn't anywhere close to complete – it passes a whopping 5/101 tests. IronPython 2.6 is required.

What's complete:
  • Primitive (c_*) types
  • Simple structures, nested structures
  • Loading DLLs
  • Calling functions
  • byref() parameters
What's missing:
  • Unions
  • Subclassed structures
  • Arrays
  • Probably lots of other stuff…
It does work for simple functions
Unfortunately (for Jeff), after he announced this on the mailing list Dino Veihland (core IronPython developer) chipped in to say that actually he'd been working on ctypes and intended to include it in IronPython 2.6 - he just hadn't told anyone... Ouch! It was this mixup that prompted the creation of the IronPython 2.6 roadmap - with details of what will be included.
C# in depth is one of the best regarded books on C#. In a request for comments on proposed changes and additions for the second edition, author John Skeet mentions IronPython in chapter 13:
Chapter 13: Dynamic binding in a static language
  • Introduction to the DLR, IronPython, IronRuby
  • Calling dynamically – the dynamic keyword
  • Reacting dynamically – implementing IDynamicObject
  • Applications for dynamic code
  • Summary

No comments:

Post a Comment

Note: only a member of this blog may post a comment.