Posts

Showing posts with the label embedding

A Good Mix 33: Embedding Python and Ruby, Profiling IronPython, News on JScript, ctypes and DeviantArt

More IronPython and DLR related projects, articles and news from around the web. Embedded IronRuby and IronPython in Silverlight with Multiple Source Files A  nice example of embedding both IronPython and IronRuby in a single C# project. As an added bonus the project is a Silverlight project so you can add both Python and Ruby scripting to applications that run in the browser. slimtune: A free profiling and performance tuning tool for .NET applications IronPython 2.6 has useful new hooks for profiling and debugging IronPython code. Unfortunately most 'standard' .NET tools don't know how to use these, and if you attempt to profile IronPython code (particularly in an embedded environment) you have to work hard to get useful information about performance of your Python code. It's nice to see a new (and open source) tool that is designed to work with IronPython: SlimTune is a free profiler and performance analysis/tuning tool for .NET based applications, including C#...

Scripting Applications with IronPython (ADAM, Revit, AutoCAD & Postsharp)

IronPython and the Dynamic Language Runtime make it almost ridiculously easy to add scripting to .NET applications. In recent weeks several examples of using IronPython to add scripting or interactive shells to .NET applications have been posted by the .NET community: Command-line scripting of IronPython code in AutoCAD This post was heavily inspired by the code presented by my old friend Albert Szilvasy during his excellent AU class on using .NET 4.0 with AutoCAD . ... In this post we’ll take Albert’s technique and implement a command-line interface for querying and executing IronPython script. This approach could also be adapted to work with other DLR languages such as IronRuby, of course. Here’s the updated C# code which now not only implements PYLOAD functionality, but also a PYEXEC command.   Scriptability via the DLR and PostSharp  Making an application scriptable (particularly in a static language) has historically been difficult. With the advent of the DLR (D...

A Good Mix 32: Alpha Encoding Files, Embedding IronPython in Russian, IronSharePoint, IronRuby, World's Worst Paint Program

More IronPython and DLR related projects, articles and news from around the web. Alpha-encoding file versions  Steve Gilham shows how to generated encoded version strings for installers using IronPython: When building installers the UpgradeVersion must have a unique property value that is an installer public property (upper-case alpha). So, what better way of adding uniqueness than making it have the form "product name + product version" with the version suitably encoded... So, a script for turning a file version (4 x 16bit ints) encoded as a System.Version into a short alpha string, assuming that Major and Minor will be small, and that common approaches are to step Build, to use a stepped Build plus date-stamped Revision, or a timestamp Build and Revision. C# + IronPython: вызов методов An article on IronPython, and in particular using IronPython from C#, in Russian. IronSharePoint Source Code Available   A while ago Christian Glessner announced the start of the I...

Embedding IronPython in Silverlight - Importing

Jimmy Schementi is the Microsoft program manager for the integration of dynamic languages (IronPython and IronRuby) and the Silverlight browser plugin. As well as dynamic languages, Silverlight applications can be written in .NET languages like C# and VB.NET - and these languages can embed IronPython. Although embedding IronPython in a C# Silverlight application is initially straightforward (although a bit more verbose than embedding using the normal .NET framework / Mono as the ScriptRuntime needs to be configured), it gets painful fast. This is especially true when the Python code you execute needs to import anything, which has basically been broken on Silverlight for quite some time. In his latest blog entry Jimmy looks at how embedding from Silverlight has got simpler recently, and also at fixing the import problems. Embedding IronPython in Silverlight - Importing I’ve heard plenty of times on the IronPython Mailing List that embedding IronPython in Silverlight is easy at fi...

Scripting Your .Net Applications with IronPython

One of the major use cases for IronPython is embedding in .NET applications to provide user scripting. The hosting APIs make it easy to experiment with embedding IronPython. Chris Umbel has written up a blog entry demonstrating the IronPython 2.6 hosting API and giving an example of exposing an API to Python scripts from a C# applications. Scripting Your .Net Applications with IronPython At several points in my .Net development career I've had the need to make an application I wrote scriptable. Sometimes it was to provide easy product extension to customers or lower level information workers. Sometimes it was to ease maintenance of very fine grained logic that has the capacity to change frequently or unpredictably. But every time I found it to be one of the more interesting facets of the project at hand. Early in .Net's history this was made easy by using Visual Studio for Applications (VSA) which allowed you to host arbitrary C# or VB.Net code within the executing AppDom...

Getting Started with IronPython and Embedding IronPython

Charlie Calvert is Community Program Manager for the C# group at Microsoft. He has posted a couple of blog entries on using IronPython. The first shows you how to get started with IronPython on Windows, including setting up your path to easily execute Python scripts with ipy.exe. The second entry shows how to execute a Python file from C# when embedding the IronPython engine. Getting Started with IronPython I recently spent some time getting IronPython up and running on my system; I will review what I learned in this post. Hosted inside an interpreter, Python belongs to the same family of scripting tools as VBScript, JavaScript, Perl and Ruby. You can fairly compare Python to a general purpose language such as C#. Developers praise this loosely typed, dynamic language for its ease of use and rapid development capabilities. IronPython is Microsoft’s free version of the open source Python language. IronPython can be hosted inside a C# program as a scripting language. Nonetheless, ...

Lightweight Debugging for Hybrid C#/IronPython Apps

Harry Pierson, IronPython program manager for Microsoft, has written a series of posts on using a new feature in IronPython 2.6 to assist with debugging when embedding IronPython in .NET applications. The focus is not just on embedding for scripting, but actually using IronPython for polyglot programming - writing hybrid applications using both IronPython and C#. Lightweight Debugging for Hybrid C#/IronPython Apps  Seriously, let me introduce you to the worlds simplest Twitter application: GetThings. The app downloads a list of my tweets via the Twitter API and displays them in a list box. The UI is written in C# while the tweet download code is written in Python. Clearly, this is a pretty brain dead app – but the point isn’t to build a great Twitter app but rather to show how to use the settrace API from C#. I’ve stuck the code up on GitHub. If you want to see the basic app in action sans debugging, start with the initial checkin. As you can see here, basic C# / IronPython int...

Using IronPython as a Scripting Engine

IronPython makes adding Python scripting to .NET applications very simple. .NET applications interact with Python code through the DLR hosting API which is easy to use once you get used to the basic principles. You can find a guide to working with the DLR hosting API in IronPython in Action or my series of articles and examples on embedding IronPython . A blogger called rune has been experimenting with embedding IronPython in C# business applications. Using IronPython as a scripting engine In this post I will look into the subject of extending an application written in a traditional .NET language like C# using IronPython. I am not talking about authoring assemblies by writing them in IronPython, though: I’m talking about letting some third party create plug-ins in Python which my application will load and execute at runtime. Let’s say we are C# programmers developing some LOB application for processing orders from a fixed set of customers. Since these are trusted customers, they...

Configuration with IronPython

Mark Bloodworth is an architect evangelist who has blogged several times about IronPython. He has put up two more blog entries on using IronPython as a configuration engine. Configuration with IronPython   Configuring applications in code seems like a good idea.  Configuring them in code written in a dynamic language seems even better.  Let’s look at a simple example with IronPython. ... What next? I’ve kept this example as simple as possible to show the principles.  The advantages of using Python code (it would be simple to use IronRuby, too) are that it’s simpler to write, testable, more powerful and doesn’t need pre-compiling.  And it could do much more than set a couple of properties.  In C# 4.0 the dynamic keyword would allow the Configuration class (and classes like it) to be dynamic, so that the properties and methods could be referenced at runtime without having to be declared ahead of time. Simple Configuration with IronPython and .NET 4...

Catching up with Devhawk: Using Python libraries from C#, the HawkCodeBox and a world tour

Devhawk, otherwise known as Harry Pierson, is the program manager for IronPython on the Microsoft dynamic languages team. He is a prolific, even more than me, has a whole bunch of interesting IronPython related posts that I've fallen behind on. The first set of posts is about building a hybrid Python / C# application, specifically using the awesome Pygments syntax highlighting library from a .NET application. Pygments for Windows Live Writer v1.0.2 Harry has been working on a syntax highlighting plugin for the Windows Live Writer desktop blogging tool. He's using Pygments via IronPython 2.6 Beta 2 to do the highlighting, and barring some problems with the import magic Pygments does (known by the IronPython team as “Harry’s Pygments Import Bug”) it works fine with IronPython. Building a Hybrid C# / IronPython App without Dynamic Type C# 4.0 introduces a new feature, the dynamic type, that will make embedding and interacting with dynamic languages from C# much easier. If you w...

Command Line Options and Configuring Your Engine

Image
The blog entry I'm focusing on here is in Russian. Normally this means I would mention it one of the "good mix" posts but not spend too much time on it, however it makes a useful point that I think is worth explaining: Поддержка sys._getframe в IronPython. First of all the author recommends Eclipse 3.5 , along with PyDev 1.4.7 and IronPython 2.6 Beta 2 - which in itself is an interesting combination for IronPython development. (Ironic that the big Java IDE has much better support for IronPython than the big .NET IDE.) One of the new things in IronPython 2.6, and in fact the reason that PyDev is able to have support for things like debugging IronPython code, is support for Python stack frames and APIs like sys._getframe , sys.settrace and so on. To run IronPython with this enabled you need to use a magic command line switch, of which IronPython has many. You can get a list of them by running ipy.exe -? : None of the ones above are standard to Python, although some of th...

Embedding IronPython as a scripting language

Mark Bloodworth, Microsoft Architect Evangelist, shows how to use IronPython to add scripting to a .NET application. Embedding IronPython as a scripting language A great way of extending an application is to allow users to write their own scripts. Fortunately, with the Dynamic Language Runtime it is fairly simple to provide scripting in your application. Let’s look at how to do it with a simple Windows Forms application and IronPython. ... It’s simple to add powerful scripting support to your applications, while maintaining control over the scripting runtime means that you can restrict what any user entered code can do. I chose to show this example in IronPython, but the principles for doing this with Ironruby are identical (of course you’ll need a reference to IronRuby.) In fact, you could offer users the choice of languages.

A Good Mix 11: A Rules Engine, Embedding, SharePoint and NWSGI

Another selection of blog entries and articles relating to IronPython from the last few weeks. Umm... A blog entry from Dave Fugate (IronPython testing and infrastructure guy) on an exception message that shouldn't be visible. Looks like it is actually a bug in Vista, but as it was triggered by IronPython it gets a mention here: IronPython most definitely should not be able to spawn an error message box that's visible when Vista is locked at the username/password screen. Quite annoying yet very interesting at the same time... Use .NET classes in IronPython Another blog entry from Mark Bloodworth (a Microsoft Architect evangelist) on using IronPython. It demonstrates writing classes in C# and using them from IronPython. The entry is short because this is something that IronPython makes trivially easy: It’s really simple to use a .NET class in IronPython. The first thing to remember is that you’ll need to add a reference (just like you would in .NET). To do that you use the Ad...

Methodist: Make .NET Reflector come alive with IronPython

No, not a reference to a once dynamic spiritual movement that is now largely part of the institutionalised church, but a new plugin for .NET Reflector . Reflector is a tool for exploring and disassembling .NET libraries. From binary assemblies it will show you all the classes and their members including the relationships between them. It will also disassemble them back into C# or VB.NET source code; invaluable for understanding the behavior of objects but a nightmare if you feel the need to protect your source. Ben Hall , UK MVP, C# expert and dynamic languages enthusiast has created a plugin for Reflector which makes it even more useful. Part of the power of dynamic languages is how easy they make exploration from the interactive environment. Ben has brought this to Reflector by embedding an IronPython interpreter (REPL). Whilst you are looking at the available methods and their arguments and return values you can actually instantiate classes and use them from the interpreter. As wel...

A Good Mix 8: Python 101, Regular Expressions, Silverlight, IronRuby and More

The Coding Geekette is a Python and .NET developer who has spoken on IronPython at many developer conferences including PyCon . Her next adventure is teaching .NET developers Python in Cleveland: Python 101 for the .NET Developer What: "Python 101 for the .NET Developer" with Sarah Dutkiewicz, Cleveland C#/VB.NET SIG When: Tuesday, June 23, 6:30-8:30pm Where: Beacon Place Conference Center, Beacon Place Office Building, 6055 Rockside Woods Blvd, Lower Level, Independence, OH 44131 Python and .NET Regular Expressions at the Interactive Interpreter This blog entry (non-English) shows two interactive sessions using the System.Text.RegularExpressions.Regex class; performing the same task from both IronPython (2.6 beta) and IronRuby (0.4). The interactive interpreter is a great environment for experimenting, and the sessions ably demonstrate this. Of course you could also achieve the same thing with the Python re module . This is true of many things in IronPython, file and path ...

DLR Hosting in Silverlight

The Dynamic Language Runtime is the framework created by Microsoft for building and running dynamic languages on the .NET framework on Mono. The major language implemented on top of the DLR is IronPython, with IronRuby rapidly heading towards completion. As well as being a fine language for application development, the DLR has been designed to be easy to embed into .NET applications; to provide user scripting and extensible architectures. The .NET framework comes in three distinct varieties: The 'standard' .NET framework for the desktop and server computers The .NET compact framework for running on mobile and gaming devices like the XBox 360 The CoreCLR which is included in Silverlight, the browser plugin Of these three the DLR will run on the first and third. The compact framework lacks the Reflection.Emit libraries which the DLR uses for code generation. Just as IronPython can be embedded in .NET applications it can also be embedded into Rich Internet Applications through Si...

Lang.NET and Microsoft Dynamics

Image
The Microsoft Lang.NET Conference 2009 has come and gone. The conference is not just about Microsoft languages and platforms, but has speakers on Smalltalk, the JVM and more: Lang.NET is a forum for discussion of programming languages, managed execution environments, compilers, multi-language libraries, and integrated development environments. It provides an excellent opportunity for programming language implementers and researchers from both industry and academia to meet and share their knowledge, experience, and suggestions for future research and development in the area of programming languages. The best news from the conference was the arrival of IronPython in Action of course. In this photo Jimmy Schementi is reading the dead-tree version: There were plenty of interesting talks. You can watch the videos here . One of the talks is about a Microsoft product which ships IronPython (another one - IronPython is turning up in more and more places in the Microsoft ecosystem): Microso...

Using IronPython for Converters in Silverlight

Another blog entry from David Seruyange on using IronPython with Silverlight, and another example of using IronPython for binding dynamic types in WPF . Using IronPython for Converters in Silverlight The concept is a really nice one but I’m not wild about having to write a class that implements the IValueConverter interface every time I need some ad-hoc tweaking of the values I get from being data bound and how I’d like to use them within XAML. What set me off this track was a case where I simply needed to invert a boolean – what should just be “ not myvalue ” ended up requiring a class, an interface, and so on. Dynamic languages excel at this sort of thing and since they support the ability to evaluate code on the fly I thought it would make sense to write a single implementation of IValueConverter and host Python inside of it to evaluate binding expressions that are passed in. No magic, just instantiate the Python runtime and then proceed to leverage it in the Convert phase by taki...

Your next text editor is... MetaNote!

One of the classic use cases of IronPython for .NET developers is embedding it into applications written in C#. The DLR is designed to be used in this way and has a nice API for embedding. This makes it easy to add user scripting to applications. It also allows for a more general extensible architecture , where part of the application is written in IronPython and it can also be extended with IronPython. One application that takes this approach is Intellipad , an editor that is part of the Microsoft Oslo framework . Another editor that takes a similar approach is the newly created MetaNote editor, the brainchild of Leon Bambrick: Your next text editor is... MetaNote! MetaNote is a text editor. Ultimately, MetaNote intends to be the most versatile editor imaginable. See that button in the toolbar? Right click on it, and edit the code behind it. Don't like the way 'Find' works? -- right click on it, and edit the code. Need a new button in the toolbar? So add it already, with ...

The Not Python Edition: Ioke, Cobra and IronRuby

In this IronPython-URLs entry we look at four different topics on three languages; none of them Python - but all on .NET. Ioke for the CLR Released Ioke is a dynamic language created by Ola Bini , one of the core developers of JRuby (Ruby on the JVM). Ioke aims to be a highly expressive language, influenced by Io, Smalltalk, Lisp and Ruby. The primary implementation of Ioke runs on the JVM; but Ola recently unveiled the .NET (and Mono) implementation: Ioke for the CLR: Ioke E ikc is the first release of the ikc Ioke machine. The ikc machine is implemented in C# and F# and run’s on Mono and .NET. It includes all the features of Ioke E ikj, except for Java integration. Integration with .NET types will come in another release. There are several interesting pieces in ikc. Among them I can mention a new regular expression engine (called NRegex), a port of many parts of gnu.math, providing arbitrary precision math, and also an implementation of BigDecimal in C#. Cobra February 2009 Update C...