Posts

Showing posts from September, 2008

Unit Testing in Python

The "Test Driven Developer", a .NET developer, has been using IronPython - and is " having a good time testing code with its built-in unit test framework ". He posts some example code with tests using the unittest module: Unit Testing in Python " This example should illustrate that we can write some unit tests for our Python code fairly easily and quickly. It's nice to have a built-in framework for unit testing. There is also a "doctest" module available for doing more like system testing. "

IronPython Talks to Google AppEngine

Joseph Jude has continued his experimenting with his time tracking tool and getting a desktop application (written in IronPython of course) - a time tracking tool - to use google authentication via the AppEngine. IronPython Talks to Google AppEngine He has made a new release of the client side tool, with configuration details to talk to his appspot application (the desktop tool can be used standalone without communicating with the server): " I had the idea of having a server which will act as a centralized data repository - laptop/desktop tool, mobile tool should send data to the server and data will be analyzed in the server. " " Next steps? Incorporate with Google Charts to provide some neat analytics reports, so that it really becomes an useful tool. "

Spider Python: Some Notes on IronPython

Some person on the internet has been learning IronPython. In order to learn IronPython he has ported a simple web spider (from a language called Retlang ) and posted the Python code: Spider Python: Some Notes on IronPython He is normally a C# developer (but he has tried Boo). He has also posted some notes on his first impressions of Python: Python list comprehensions can do the same as LINQ for simple cases, but LINQ is much more powerful, and it supports deferred execution, while list comprehensions are evaluated greedily. (Ed: generator expressions are evaluated lazily in Python) Every description of the python syntax I ever see emphasizes the fact you don't need to put in braces. Pity they don't spend more time telling you that you have to put in colons, that would actually be useful knowledge. This really bit me when I learnt boo, which is syntactically very similar. IronPython 1.0 targets CPython 2.4. This sounds fine until you realize that this was released in 2004. A

Surprised While Porting to IronPython 2

Ronnie Maor has blogged about his experiences of porting an IronPython 1 codebase to IronPython 2. The biggest change of course is the hosting API - which has changed completely. From the inside it is "just Python" and so the only changes should be fewer (and different) bugs. However, there are few subtle changes - like the ordering of essentially unordered collections like the dictionary and set - that revealed "hidden assumptions" in his code and tests: Midnight Oil: Surprises while porting to IPy 2 My conclusions from this are: If it's not tested it doesn't work. And when you change the environment under which your code runs you need to retest. The unit tests paid off again, since they allowed me to find many problems in places I didn't expect. I need to do more to flush out these hidden assumptions. One way is to add a randomized test that runs over longer periods and plays with some variables. I could easily randomize the order in which I go over th

Should Python Projects Support IronPython and Jython?

The maintainers of the Spring Framework for Python ( Spring Python ) wonder how much of a priority it is to have compatibility with platforms other than CPython. In other words, should they support IronPython and Jython - and if so what should they do about their C extension dependencies? This question sparks a good discussion and is relevant to many other Python projects and applications: Need for supporting IronPython, Jython? " One of the topics on my mind recently, as we consider refactoring the core container, is how we ensure that when we introduce internal dependencies, such as possibly the Amara libraries for XML processing, what secondary constraints we might be introducing. " " For example, Amara represents a very pythonic and therefore simple to read and use approach to developing XML processing, such as our very own XML application configuration parsers. So from that perspective, things are very attractive. But then you ask the question, "can I run this

Assorted Snippets

Here are a collection of recent blog entries that feature IronPython but don't quite qualify for an IronPython-URLs entry of their own. Starting with two new pages on the IronPython Cookbook : Validating a Filename A short recipe by Davy Mitchell that ensures user input is valid as a possible filename, removing invalid characters. Profiling for Silverlight An entry by Dan Eloff demonstrating performance profiling for IronPython Silverlight applications. Steve Gilham has been doing some odd things. Notably creating Java libraries in Java and Scala and then running them on .NET using the IKVM cross-compiler. I haven't been tracking them on this blog because most of the experiments have only been tangentially related to IronPython, but his latest entry is interesting. Here he is writing Scala (a very statically typed language for the Java Virtual Machine) code and using it from IronPython: Scaling the tower of Babel II Which of course begs the question why ?... it's still c

Running Python from C#

Mark Bloodworth (a Microsoft Architect Evangelist no-less!) posts a code snippet showing how to execute Python code from C# with the IronPython hosting API: Running Python from C# Embedding IronPython in .NET applications (or even embedding new Python engines in IronPython applications) is extremely simple to do. This means that providing user scripting, or even making part of an application dynamic, is much easier than it ever has been. Mark says: " I’m impressed that C# and IronPython can interact like this. The possibilities for extending applications with runtime dynamic code are intriguing - worth looking into. "

NWSGI 0.5 Released

Alongside the new IronPython / ASP.NET release is progress with another web framework for IronPython - NWSGI . NWSGI is a .NET implementation of the Python Web Server Gateway Interface specification. It is implemented as an ASP.NET HttpHandler with the goal of allowing you to run Python web applications / frameworks (such as Django, Trac etc) with the IIS 7 web server. This latest release is version 0.5 and has a couple of new features and breaking changes. Jeff Hardy announces and explains the release on his blog: NWSGI 0.5 Released Jeff also outlines his plans for the future of NWSGI: " I'm working on building an IIS7 admin interface for all of this; it's a bit of a mess right now because the advanced UI tricks aren't really documented that well. I'm hoping to have the IIS7 admin and the installer ready by the time IronPython goes 2.0. "

IronPython and ASP.NET Integration Updated

The IronPython ASP.NET integration has been updated! The new home for " ASP.NET Dynamic Languages Support " is the ASP.NET Codeplex page: ASP.NET on Codeplex Jimmy Schementi (responsible for the Dynamic Languages and Silverlight integration but who has also worked on this project along with David Ebbo and Phil Haack) is excited and invites you to join the party: ASP.NET Dynamic Language Support Refreshed The new refresh includes support for using IronPython with 'normal' ASP.NET (webforms - but now updated to IronPython 2) and with the new ASP.NET MVC framework. For the MVC framework, IronPython is currently only integrated into the Views and not yet Controllers or Models. There are samples plus documentation available and Jimmy's blog entry walks through creating an IronPython webforms site with Visual Studio. Phil Haack, who is now PM for the ASP.NET Dynamic Language Support along with ASP.NET MVC, has also blogged about the new release: Refreshing ASP.NET Dyn

Passing Keyword Args to C# Methods from IronPython

Python has very useful constructs for accepting variable number of positional and keyword arguments: def f(*args, **keywargs): pass The arguments are collected as a tuple and a dictionary. C# can collect an arbitrary number of arguments to a method (no messy functions in this language!) as an array (with the params keyword) - but it has no concept of keyword arguments let alone collecting them as a dictionary. In this blog entry Srivatsn (IronPython tester) introduces the ' ParamDictionaryAttribute ' that is part of the Dynamic Language Runtime ane explains how to use it to write C# classes that can take arbitrary number of keyword arguments: Passing Keyword Args to C# Methods from IronPython

Game Scripting in IronPython

Calbert has written a MUD type game with C# and IronPython on the server, with the user interface in Silverlight. " I wanted to explore this scripting for Perenthia because I want to be able to add dynamic functions or scripts to objects. I wrote this sample to test out using C# as base classes for IronPython classes and passing operations back and forth between the two. As such the source is kind of loose but the concepts are demonstrated. What I have is a basic framework of C# classes that define an Actor (any object in the game), a Client (a connected player), a Game (the logic of the game) and a Server (for handling HTTP communication, etc.). The Actor, Client and Game classes also server as the base classes for IronPython classes or Creatures, NPCs, Players and Rooms. " In his blog entry he shows some of the C# classes and how they are used from IronPython. Game Scripting in IronPython Play Cameron's Dungeon Cameron's Dungeon Source Code (6mb)

DLR Namespace Change Fire Drill

The other significant change in IronPython 2 Beta 5 was a namespace change for one of the core assemblies: Microsoft.Scripting.Core.dll At the heart of the Dynamic Language Runtime are expression trees - the Abstract Syntax Trees of DLR languages. Another part of the .NET framework (at least since .NET 3.5) is LINQ - Language Integrated Query. LINQ makes querying a first class language concept. In its most basic form (over objects) it resembles Python list comprehensions and generator expressions. With the right providers you can also use LINQ to query XML and databases - with your LINQ expressions being 'compiled' to SQL or an appropriate query language. LINQ expression trees represent query expressions. In IronPython 2.0 Beta 4 the DLR expression trees merged with LINQ expression trees and were moved into the same namespace. Unfortunately this caused name collisions all over the shop and made it virtually impossible to use IronPython or the DLR in projects that also used .NET

IronPython 2.0 B5 - New Hosting API

For those interested in embedding IronPython in .NET applications there were two significant changes in IronPython 2 Beta 5. As this is the last beta before the release candidate, integrating this release should be the last changes you need to make. The first change is that a significant portion of the hosting API has changed - and for some (but not all) use cases got a lot simpler. Embedding Dynamic Language Runtime engines (what we are discussing here is the DLR hosting API) uses the App.Config file to configure the languages they intend to use. This part is probably more complicated than before. The DLR Hosting blog has a self-contained Visual Studio 2008 sample demonstrating how it works: DLR Hosting Sample : Simple dlr host using the new App.Config based ScriptRuntime creation For languages like IronPython and IronRuby, convenience classes have been added that make hosting simpler. For IronPython the class is called Python . You can create a ScriptRuntime (one of the core hostin

Custom Fixed Size ListBox Items in IronPython in 30 Seconds

Ross was one of the developers who attended our IronPython tutorial at PyCon UK. Prior to the tutorial he was experimenting with Windows Forms. This recipe is a snippet of code for drawing fixed height custom listbox items (by handling the ' DrawItem ' event): Custom Fixed Size ListBox Items in IronPython in 30 Seconds From another blog entry , he comments on working with Windows Forms from IronPython: "One thing I did notice whilst playing with IronPython and System.Windows.Forms was how relevant any S.W.F. experience you already have is likely to be. Yes, you’ll be writing a lot less code, but apart from the fact you’re using a much nicer language, the way that the UI works is obviously the same - which for some reason wasn’t as obvious to me as it should have been. "

REMLOG and the Dynamic Languages Braintrust

Dave Remy is the uber-commander-in-chief of the dynamic languages at Microsoft, and he blogs. If you've ever wondered what the dynamic language team members look like, Dave has some photos of them from a lunch meeting with the 'brain-trust': Lunch with a Dynamic Languages Braintrust He also got together with Mike Vincent, who is " on the Board of Directors of INETA (International .NET Association) which works to coordinate a huge community of .NET user groups ". INETA is in touch with a large community of .NET developers: " It appears INETA has great momentum, with greater than 250 active user groups and over 100,000 active developers in North America, and a reach of approximately 1.2 million developers world-wide. " Meeting Mike Vincent "One question we asked was how important Mike saw Visual Studio Integration for the Iron languages. We get feedback at times that it is more important to have a lightweight, quick to bring up, quick to close down,

Embedding Boo and IronPython

Nahum Dotan has been trying to evaluate which of Boo and IronPython are more suitable for embedding. ( Boo is a statically typed .NET / Mono programming language with duck typing and a Python inspired syntax.) "In short, I didn’t come to a conclusion. But I did have some fun. I played with the thought that using python’s native dictionary initialization syntax would be nice as a configuration file syntax (e.g. ini files). So I whipped a sample project that would embed both Boo and IronPython and looked at the differences with usage. So far I’m liking IronPython better. This example is ridiculously simple, but you can go ahead and tinker with the engines, its a good timekiller. " Embedding Boo, IronPython

IronPython Bugs

No, this entry isn't about bugs in IronPython - it's about two blog entries by Dave Fugate (an IronPython tester) on the processes around fixing bugs in IronPython. The IronPython issue tracker is hosted on Codeplex . The tracker is triaged weekly to review new bugs and Dave explains the different factors involved in assigning bugs to releases. IronPython Bugs - Codeplex In his next entry, Dave explains the best way to get your bug report noticed and fixed: Getting Your IronPython Bugs Fixed Quickly Use the bug template when reporting on CodePlex Emphasize if the bug blocks an application Email the list as well Provide the simplest repro possible

A Time Tracking Tool, IronPython Learnings & Google Authentication

Joseph Jude has been learning IronPython. He's created a time tracking tool, which tracks how long you use different applications on your PC. He's also posted a blog entry about learning IronPython. This entry covers the tools he uses and some of the problems (with solutions) that he encountered: IronPython Learnings He has also made his 'time tracking tool' available for download: A time tracking tool While I was waiting for Django 1.0 to be released, I wanted to quickly learn to develop desktop applications. I preferred it to be on Python so that I can continue to learn the language. I did an evaluation of different options and settled on IronPython. As a consultant, there is always a need to submit timesheets. By the end of the day/week, it is difficult to remember the tasks done during that time-span (day/week). If somehow a tool can capture applications that were worked on, then it will help. This application polls the active window at an interval of 5 seconds and

Simple IronPython Example Using XML, Oracle and SQL Server

From the " Head Above The Clouds Blog ": This is an IronPython example of using .NET classes to load a XML document, query it with a simple XPath expression, and then using the results to transfer data from an Oracle to a SQL Server database. Simple IronPython Example Using XML, Oracle and SQL Server

Ironclad 0.6 Released and numpy in Resolver One

Since I last updated this blog (yes I've fallen behind in the last couple of weeks - I'll catch up soon) a lot has happened with Resolver One . Resolver One is a spreadsheet development environment created by Resolver Systems and built on IronPython. Version 1.2 was released not long ago. This includes several major new features, including one called ' RunWorkbook ' that greatly helps with our goal of making spreadsheet system design modular, maintainable and resusable. Part of our plan for Resolver One includes being able to use numpy (a C extension). At PyCon UK William Reade demonstrated working with numpy arrays containing one million items from inside Resolver One. This was using an experimental version of Resolver One ported to run on IronPython 2, along with Ironclad - our open source project that allows you to use Python C extensions from IronPython. The Resolver Systems blog includes links to the slides for Giles Thomas's PyCon UK talk and William's

IronPython 2.0 Beta 5 Released

IronPython 2 Beta 5 has just been released. IronPython 2 is an implementation of Python for Mono and the .NET framework and is built on top of the Dynamic Language Runtime. IronPython 2 Beta 5 is intended to be the last beta before the release of IronPython 2 final (although there will probably be at least one release candidate) - so if you want bugs fixing now is the time to test and report them! Download IronPython 2 Beta 5 IronPython 2 Beta 5 Release Notes This release includes fairly major changes to the DLR hosting API, including a new convenience class ' IronPython.Hosting.Python ' that makes a lot of the common patterns for embedding IronPython a lot simpler. It also includes some namespace moves to avoid clashing with .NET 3.5. Over 100 codeplex work items (plus other bugs reported internally at Microsoft) were closed between beta 4 and beta 5. As this number includes items closed as 'duplicate' or 'by design' the actual number of bugs fixed is not repor

DLR Hosting Spec

The DLR Hosting API blog has the details on the latest version of the DLR Hosting Specification that is now available. Since IronPython 2.0 Beta 4 (the most recent released version) the mechanism for initializing engines for hosted Dynamic Language Runtime languages has changed. At the same time a new convenience class has been introduced making it much simpler to work with an embedded IronPython engine. The new spec gives all the details and the blog entry demonstrates initializing an 'arbitrary' language through XML configuration. DLR Hosting API : latest version of the spec is available online (includes changes to runtime initialization) Although the new specifications makes for simple deployment and configuration of systems using a single embedded language it may make them 'interesting' for situations where multiple DLR languages need to be used together.

Reports on IronPython and Dynamic Languages from Recent Conferences

Several reports on talks on IronPython and dynamic languages from the Microsoft TechEd conference (New Zealand) and Microsoft Technology Summit. Scott Yang liked harry Pierson't talk at TechEd: The final show today was the highlight — “Pumping Iron: Dynamic Languages on .NET” where Harry Pierson talked about the benefit of dynamic typing languages and why they are useful to .NET users. Great presentation, and great arguments on why the lack of compile time checking is NOT really an issue. IronPython was used in the code example, which is something I am a bit familiar with. Jamie Penney's notes on the same talk: WEB305: Pumping Iron: Dynamic Languages on .Net - Harry Pierson Tradeoff between Type Safety and Flexibility Rails ActiveRecord example - AR adds the column names of a table as properties on the model class at run time. Real products are being shipped on IronPython - Resolver One Dynamic languages are very productive - good for initial work on greenfield pr

IronPython Tutorial and Twatter on Mono

Image
It's only a few days until PyCon UK . Christian, Menno and I have been preparing the IronPython tutorial and there is new information on the wiki about what you will need if you are attending. IronPython Tutorial on the PyCon UK Wiki Page We will support IronPython on Linux, Mac (both via Mono) or Windows - and you get to take your pick of four different databases. During the tutorial we will work through creating a windows forms based Twitter client called Twatter . There are more details on my blog, along with a screenshot of it running on the Mac and a screenshot of the example application for the early chapters of IronPython in Action . Twatter and MultiDoc on Mono Windows Forms Since I wrote that entry Christian has done some more work, and Twatter now fetches images of tweeters. Here's a screenshot of it running with IronPython 2 and Mono 2.0 preview 3 on the Mac:

Polyglot Python

Adam Wolf decides to learn a new programming language - and in attempt to thin out the number of possibilities he limits the field to those that he can use for both desktop application development and with Silverlight. Naturally this brings him to IronPython. Polyglot Python " The winner is IronPython, a dynamic language used in conjunction with the new .Net Dynamic Language Runtime. Python was created in the 1980s by Guido van Rossum, who is now working at Google. The Python language is a wrist friendly language due to its terse syntax and no need for the normal text enclosures like C# and VB.Net. The language comes with the “batteries included” and this refers to the numerous libraries that come with the language, which will enable you to write almost any type of software. The IronPython implementation on the .Net platform has full access to these standard Python libraries as well as the full .Net Framework. " As an added bonus he decides to learn by reading the early acces

IronPython at PyWorks and PyCon UK Conferences

The PyWorks 2008 conference schedule is now up. This is a new conference, held in Atlanta November 12th-14th, by the same people who bring us the Python Magazine . I'll be speaking at PyWorks on IronPython: Python on .NET and in your Browser. PyWorks 2008 Conference Schedule I'll also be at the UK Python conference (along with most of the Resolver Systems developers) in Birmingham September 12-14th. Three of us (Christian Muirhead, Menno Smits and I) will be giving a half day tutorial on Developing with IronPython (on the Friday morning). In this blog entry I talk about the sample application we'll be building together in the tutorial (come with IDE and ready to code) - plus a call for volunteers for the conference itself: PyCon UK: IronPython Tutorial, Socials and Volunteers Needed " The tutorial is based around a simple Twitter client, which Menno has named Twatter! We've been testing Twatter on Windows, Linux and the Mac (it doesn't look bad on the Mac). &q