As most .NET developers do at some point or other, I was recently faced with a need for an automated build tool. For various reasons I’ve come to the point where I’m not really satisfied with any of the ones currently available, so I decided to write one. Pyke is the result of that itch.
Not invented here syndrome?
Yeah, I’ll admit it, I have a tendency to be an opinionated developer. Maybe even a little more than most. But having worked with both NAnt and MSBuild more than I’d care to admit in the past, I have no desire at all anymore to willingly drown myself in angle brackets just to automate a few simple tasks. I tried my hand at using Rake with Albacore a time or two as well, and for one reason or another, I was never able to actually get it working for the simplest of tasks…my guess would that it was because I was trying (heaven forbid) to actually use Ruby on Windows. The two just don’t seem to get along.
When I started this little project, I actually inteded and attempted to write it in Powershell. I don’t know if its just me (I kinda doubt it, because I’ve talked about this with others who agree with me), but the documentation and available examples on the internet leave much to be desired with regards to just getting started doing some incredibly basic tasks like file I/O (walking directory structures recursively, creating/updating/deleting files, etc), and I just couldn’t get going with it. After two to three hours working with it, I wasn’t even able to get basic function to walk a directory working.
So I decided to give Python a shot…
Learning something new
As a professional software developer, its a fairly widely held belief that its important to expand your skills by learning a new language each year. I’ve agreed with that sentiment ever since I first heard it, but I’ve never embraced it seriously enough to actually follow through and do it. I decided this (and another prospective side-project) was potentially a good opportunity to try to learn Python. One of my best friends has been a Python fanboy for quite a while now, and has often encouraged me to give it a shot, so I figured I would at least have one good resource to turn to if I got stuck on anything, but it turned out I didn’t need to. The online documentation for Python is really good, with lots of good examples available as well. Overall it has taken me a total of probably around 10 hours work time to get Pyke to the state its in now, which I’m pretty happy with (though it still needs some work).
Also, I’m hosting the project on Github, so it has had the additional bonus of being a great opportunity to get to learn git better, which is cool.
What does it do?
Another part of the reason why I decided to just roll my own was because my needs were really fairly straight forward. I don’t really need all that much from a build tool. My immediate needs were pretty simple:
- Generate a version number: I just needed something that could automate the generation of a unique version number.
- Apply the version to assemblies: Find all of the AssemblyInfo files in a given directory structure, and create new ones with a set of custom assembly metadata applied.
- Compile to a custom output directory: Pretty simple, just compile a given solution or project, and push the output to a given directory.
- Generate a NuGet package: I wanted it to be able to build a NuGet package and upload it to an internal Nuget package feed (which, since its internal, really just means copying the generated package to a network share).
- Utility functions: I also need it to have a few basic utility functions for build cleanup and moving things around.
Told ya…not really all that much to it. There are obviously a few more things that I’d like it to do when all is said and done (see the TODO list on the github page), but for now, its suiting my needs nicely. I’ve been actively working with it for the past week and it has done exactly what I asked of it, and given me no problems at all so far.
How does it work?
I’m working on getting some comprehensive usage samples put together for all of the features, but here is a stripped-down example that should at least give you a quick taste of how to use it.
First, you’ll need to download pyke.py (see the “How can I get it?” section below) and drop it in the folder that your build script will be in. No installation necessary, just stick it in the same folder, and reference it in your build script. Then, a build script (I call mine build.py) would look something like this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
Like I said, that’s a fairly basic example, and there are other options as well, but that’s a decent summary of the basics. Also understand that, build.py is obviously just another python script, so you can do anything you want/need in it to support your build process. Pyke just makes some of those things a little easier (at least I think so anyway).
How can I get it?
Pyke is hosted on github, so you can either clone the project, or just download the zip, whichever you’re more comfortable with.
Enough already…
Yeah, I really need to wrap this up, I know. This ended up being a bit more long-winded than I had expected it would be…if you made it this far…congratulations…YOU HAVE NO LIFE! :) No, seriously…thanks for taking the time to read about Pyke, and if you happen to have any more time…
One last thought…I’ll share the same disclaimer here that I added to the README on the project page: Pyke is literally the first python code I have ever written. I’m nearly 100% positive that there is a LOT of code in it that could probably be done better. Constructive feedback is always welcome.