“My Code is Self-Documenting”
Self-documenting code is one of the biggest documentation myths in the software industry. This view generally conflates documentation with code comments. I’d like to make two arguments in this post:
Django, Python, and the tools of the trade. Much of it from the early years.
Self-documenting code is one of the biggest documentation myths in the software industry. This view generally conflates documentation with code comments. I’d like to make two arguments in this post:
Javascript has always been the bane of my existence as a developer. It was the part of the process of developing that I would dread. On the last project I worked on, I found a very simple change that significantly improved my experience writing Javascript.
I helped organize my first conference last year, Write the Docs. It was a great experience, but was also rather stressful. Organizing things is an interesting exercise in managing fear and risk. There are so many possible outcomes, and this is scary as hell.
Reviewboard is a great tool for managing the process of Code Reviews. It has pretty good git support, but it might not be obvious what the best way is to use it. At work, I have a couple of different ways of pushing up code for reviews, which I’ll talk about.
I have seen a lot of talk over the past couple years about how to handle different settings files and databases, synced between production and development. I have happened onto a way of doing it that makes me happy, and figured I would share it with the world.
At work, we have a wiki page that’s called Required Reading. Named after that oh-so-lovely tradition in high school or college of having books that you needed to read over the summer before you started class. The idea being that they are relics of the culture of the company, and if you read everything, you will understand a lot about how work (and play) is done.
Over on ReadTheDocs, I wanted to build search around the documentation that we’re hosting. I chose Haystack and Solr for this, because it’s the best way to do search in Django these days. However, I’ve only ever used Haystack to index content that is in the database. I thought about trying to add all the rendered HTML from the documentation into the database, but that was a non-starter.
In my work in ReadTheDocs, we now support all of the major VCS repositories: svn, bzr, hg, and git. At this point in time we’re only checking out the repos to their default branches, and then trying to trying to update them again to another revision. While writing this code I have had at least 3 different bugs that caused the repos not to be updated correctly. So I’m going to detail here the exact code that allows me to do this for each of these types of repos, hopefully so that when you or I need to do this in the future, we can at least start from here.
Today I went ahead and flipped the switch on a couple of server migrations I’ve had queued up. One of these updates is moving ReadTheDocs over to its own dedicated server, that I built up over the week in my Chef Tutorials.
Alternate title: There’s no place like home!
Alternate title: Show the world what you’ve got.
Alternate title: Actually doing something useful.
Alternate title: Fucking Chef, How does it work?
I use IRC for work, play, and generic open source questions and support. I think it’s a pretty integral part of my existence as a developer. Today I’m going to write about why using an IRC bouncer makes IRC a ton better and show you how to get one setup.
When I was setting up the Django Hudson instance, I ran into a problem that seems like it should be pretty easy to solve. However, I couldn’t figure out a way. So at this point it’s looking like we’re going to have to use buildbot to build out what we want instead of Hudson. Wondering if I missed something obvious, or if this is a missing feature.
Duplicate implicit target name: “django testing mailing list”.
Following on yesterday’s post about Virtualenv Tips, I will be talking about celery tips. Yesterday I talked about how to run celery with upstart easily, and today I’ll be expanding on that below as well as talking about how to set it up using supervisord.
Virtualenv is a project that is indispensable for most Python devs these days. I am writing down some tips here so mainly for personal reference, and because I found them useful.
Continuing from my previous post about Django Dash, I will be talking about another thing that I learned from the dash. This isn’t as big of a post, but just something that we ran into that caused us some trouble.
I have written a couple of different services that have needed to be required when your repository has had code committed to it. The normal path of getting this to happen is to ask your users to add your special URL to their list of post-commit hooks for their repository. However, once you have 3 or 4 or 10 services that need to do this, it becomes cumbersome. If I am a user that has 5 repos and I want to use 5 services, this is 25 times that I need to copy/paste some URLs into a form on a website.
This is going to be a series of posts that talk about what I learned from the Django Dash. I think it’s a really fun competetion that is also a great learning experience. I hope that this series catch on, and other people write about some of the things that they learned in the Django Dash.
[This is part of the Large Problems in Django Series, see previous entries about: Documentation, APIs, Search, and Database Migrations]
Django itself has shipped with a “semi-private” introspection API,
_meta, for a long time. I have created a drop-dead simple
wrapper on top of this.
* UPDATE*: There is a new thread about the roles and implementation of a Design Czar up on the Django Developers mailing list. Please contribute there as well, if you have thoughts and ideas.
* [This is part of the `Large Problems in Django Series <http://ericholscher.com/tag/largeproblems/>`_, see previous entries about: `APIs <http://ericholscher.com/blog/2009/nov/11/large-problems-django-mostly-solved-rest-api/>`_, `Search <http://ericholscher.com/blog/2009/nov/2/large-problems-django-mostly-solved/>`_, and `Database Migrations <http://ericholscher.com/blog/2009/nov/6/large-problems-database-migrations/>`_]*
A couple things I want to talk about. First of all, I will be participating in project52; which is a competetion to write a blog post in every week of the year. The last 2 years I have done the november post-a-day, and gotten about 25 of the 30 required posts. So hopefully writing twice that number of posts in 12 times the amount of time will be easy, right? Anyways, this is the first post in that series, so stay tuned for more regular and hopefully useful content :)
With Kong, I have been trying to figure out a way to provide
overridden model defaults. At work, our pythonpath’s default to
/home/code, however your setup is probably different. It would
be useful if there was a simple way to let you override the
defaults for your Kong installation.
When working on side projects, usually you wear all of the hats. Sysadmin, developer, designer, marketing, etc. You have to do all of them, and presumably you do one or two of them well, and the others well enough to get by. Working at the Journal World has been the first time that I have worked with real designers, and it has been a learning experience.
On Monday at work, our sites started to slow to a crawl. We looked to diagnose the problem, and found that the database server had a load of 10, and was struggling to keep up with the morning rush of traffic. After EXPLAINing the slow queries from the slow query log, we noticed that a lot of sequence scans were happening. This shouldn’t be happening because these queries should have indexes on them. We realized somewhere in the porting process that we had lost a bunch of indexes.
At work we have to manage a ton of Django based sites. Just for our World Company sites, we have over 50 different settings files, and this doesn’t take into account the sites that we host for other clients. At this size it becomes basically impossible to test each site in a browser when you push things to production. To solve this problem I have written a very basic server description tool. This allows you to describe sites (settings file, python path, url, etc.) and servers.
As part of the summer of code 2009, Django test coverage has been developed. I mentored Kevin Kusabik, who developed the code. It is hopefully going to be merged in 1.2, but there are still a few issues to be worked out in the implementation. That said, it currently works, and provides a nice introspective view of your code. This post will tell you how to run coverage on your code base.
This is the third part of my Large Problems Series. The first two were Search and Database Migrations.
Updated at the bottom of the post.
At work, a lot of our sites have sweet mobile versions. The problem is how to educate people of their existence. Currently we just have little ads that show up on the site that promote the mobile site, which seems a subpar solution. So I was tasked with doing providing a way to redirect to the mobile sites. Luckily, as a lot of the time with Django, most of my work was done for me.
Continuing in the series of big problems that are mostly solved, we have database migrations. A couple days ago I talked about Search.
Python packaging has been in a bit of a state of disarray for as long as I’ve been using it. Pip has come along to make installing python packages easier. It has a lot of features that are useful, but they have been talked about in many other blog posts.
In my previous post about template tags, I discussed the two steps required for template tags. Today I will be focusing on Parsing of template tags, and how they may be improved in the framework of Class Based Template Tags from yesterday. I have talked about problems with template parsing in the past as well. This post will offer 2 different approaches to making parsing better.
In Django, template tags currently are separated between a Node class and a “parsing function”. The parsing function takes the tag, represented as a string, parses the input, and passes the correct arguments to a Node class. The Node class then does whatever rendering it does, or updating of the context, and then renders itself in a form suitable for the template.
It’s been a little over a year since I started doing Django development full-time, for one of them real jobs. Around that time, there were a few large problems in the community that hadn’t been solved yet. They were kind of blemishes when you would talk to people about Django, and I’m happy that most of them have been solved.
Update As of Django 1.2, Django ships with default test settings for sqlite. They require two databases to be defined, because of Multidb. More information at Django advent and in the docs
Continuing on with the simple tricks that make everyone’s life a little bit better, I know a lot of people hate that Django’s 500 pages don’t get rendered as a RequestContext. This means that if you have context processors (like one that sets a MEDIA_URL), they don’t get called. This was causing our 500 pages not only to make users sad because something broke, but knock them out of context becaue our entire design blew up.
There are the slides to my Token Testing Talk from Djangocon. I’m hoping the videos will be posted soon, but I think that it went well. There were a lot of good questions, and I need to put some recap posts up, but for now here is a copy of the slides. PDF
In a previous post I talked about a neat middleware to debug production environments in Django. It basically checked to see if you were a superuser, or if you were in settings.INTERNAL_IPS, and if so, then it displayed a technical 500 page for you (The yellow one you know and love). Anyway, at that point it was more of a simple idea, and not really used in production.
Setuptools comes with a way to
run the tests on your application.
This allows the user of your software to download it, and run
python setup.py test and check to see if the tests in your
application pass. This is really useful for distribution, because
the user doesn’t need to know or care how to run your tests (nose,
django, unittest, py.test, or whatever else), and can simply see if
they pass.
Migrating test fixtures is one of the biggest pains of testing. If you create your tests too early, then change your schema, you have to go back and touch all your old test fixtures. This discourages people from writing tests until their app is relatively ‘stable’. As we all know, this may never happen :) This solves half of the problem, the part where you have to manually change a bunch of fixtures to reflect changes in your schema or data.
Any sufficiently large Django project starts to have a wide variety of Template Tags and Filters. Even Django ships with a dizzying array of them that allow you to do all sorts of fun and interesting things. Ellington, our CMS at work, has a ton, and I’ve been thinking about ways to make tags and filters a bit more accessible to people who are using the CMS.
Just got off the stage at EuroDjangocon, which was my first real talk in front of the Django Community. I hope that people enjoyed it, and that it was informational. Here are the slides to my talk in PDF Form, and on slideshare.
Today is the day that Google has announced the accepted projects for the Summer of Code. Django has 6 spots this year, with a bunch of exciting projects. I am lucky enough to be mentoring Kevin Kubasik with his project “Upgrade the Awesomness Quotient of the Django Test Utils and Regression Suite”. I’m really excited for the opportunity to help improve Django by overseeing Windmill testing of the admin, and lots of other small testing improvements that will hopefully make it into trunk.
A lot of the Django code we use at work has a special case for AJAX. It has been a kind of a pain to test, because the test client by default doesn’t use AJAX. Luckily the is_ajax call in the Django HttpRequest object is a simple check of an HTTP Environmental variable.
This is just a reminder for myself later, or people looking on Google. Also note, that this method is useful for putting any Javascript content into your sphinx docs, but Analytics tracking is a common use case.
Duplicate implicit target name: “google summer of code”.
Lately I’ve been delving into Django development a bit more, and applying people’s patches has been a bit of a hassle. You know you want to apply someones patch, but there are about five steps in between you and applying their patch to your source tree.
So at work we have a lot of different django environments, scattered across varies servers. All of this information is kept in a central resource. We have the pythonpath, settings file, and the remote server that the client is on. So every time that I want to go do work on a different site, I have to ssh into that server, set the PYTHONPATH and DJANGO_SETTINGS_MODULE environmental variable, and then do what I want to do. This is not a huge deal, but it is annoying when you’re doing it 10-20 times a day.
Just a quick warning/tip on using Django with rsync, for other people pulling their hair out later.
So about a month ago I started a project on my blog called the Django Conventions Project. It was an attempt to document and record conventions that are used across the community. Conventions are a great thing, with Python and Django relying on them a great deal. Things like private methods being underscored aren’t enforced on a language level, but are more of a gentleman’s agreement.
5 second review: Reading this book will make you a much better Django Programmer.
As of Changeset 9756, Django’s test suite is A HELL OF A LOT FASTER. This was one of the 1.1 Features and probably the one I was looking forward to the most. Django Unit Tests now run inside of a transaction.
Well it’s been a crazy roller coaster year for me. So this post is going to be the typical recap of what’s gone on with my life and my blog over the past year. I’m really happy with where I’m at both professionally and personally, and 2008 has been an interesting year for me.
During the last month I have proposed some conventions for Django, mostly in the realm of templates. In doing so I have looked around for other documented places where conventions are mentioned. I haven’t found a really good reference for Django conventions. Brian’s post was a good example of reusable app conventions, and the Pinax Project is a great reference implementation. However, I couldn’t find any simple reference for regularly used conventions in the Django world.
It’s the end of the Post a day for a month. I did pretty well, but fell off about 3 weeks in because of work. First some stats.
A couple posts ago, I talked about how we should have conventions for the names that we use in Django Template Blocks. Today I will be talking about the value that is gained from this kind of structure.
About a week ago, I went ahead and re-wrote testmaker and moved it into my django-test-utils project on github. The syntax is now a bit different, and the whole thing is much improved. This is version 0.2. The screencast from the last release still shows the gist of the project, except for the changed syntax.
I have been doing some more work on my Django Community Aggregator / Django People v2 project. A big feature that I want to incorporate is tagging. I want people to be able to sort data by tag, among other things. I think that this is a pretty killer feature.
Note: This isn’t a technical post. If you don’t want to be getting posts like this, you can sign up for just my Django feed. This is my personal blog, so stuff like this pops up from time to time :).
There are a lot of reusable apps out in the Django Ecosystem. I wrote a previous post about why I think that reusable apps should come with templates. There is a problem about distributing templates that I want to address with this post: the problem of Django Template Block names.
So at work since I started for Mediaphormedia, currently World Online, and the birthplace of Django, I have been tasked with porting Ellington. Ellington is the CMS that we create and sell, and is what Django originally was. Django was pulled out of Ellington and Open Sourced.
Well I spent all day Saturday, and all night. Into Sunday morning hacking on some code. Probably the most productive 24 hours of my life. I have a couple of announcements, but in the spirit of post-a-day, I’ll spread them out over a couple days :).
Nick had a nice post about setting DEBUG based on the hostname of the server that you’re site is running on. This allows you to set DEBUG to True for your staging site, and False for your production site.
There is a debate among the Django community about whether people should include templates in their reusable apps.
This is the fourth in a series of Django testing posts. Check out the others in my Testing series if you want to read more. Today is the start of a sub-series, which is practical examples. This series will be going through each of the different kinds of tests in Django, and showing how to do them. I will also try to point out what you want to be doing to make sure you’re getting good code coverage and following best practices.
Today I’m going to be releasing a new project, called django-test-utils. It’s rather empty at the moment, but it does have one cool feature. That is my Django Crawler. I have some big plans for this little guy, but for the moment it has enough functionality to make it pretty useful.
A couple posts back, I was talking about software that I use all the time. I was going through and linking to all of the software. I would go to google, type in the project name, go to the first result, and copy that URL back into my post. I figured that there had to be a better way. Any software project worth it’s name owns the top result in google.
There are a lot of things that I love about Django. Template tags are one of them. However, they do have a couple of warts that bother me. I know that there’s a problem when I actively look for another way to accomplish something instead of writing a template tag. I view them as a kind of last resort; thinking ‘can’t we accomplish this with a Manager instead’? I think that we need to work on making useful template tags a little bit easier to make. Django goes a long way in doing this with the simple_tag and inclusion_tag types of tags. However, I think there needs to be something more.
Stealing an idea/meme from Mark Pilgrim I’m going to do a post of the essential software that I use in a day to day basis. Justin also did a similar post a couple days back. I think it is interesting to talk about what kind of tools you use, because it gives people an understanding into how you work, and also some pointers at stuff that maybe they too should be using.
My workload at work is about to get a lot less critical and time consuming, so I was looking for a project to start on. I am really interested in the social aspects of the web, and below I will outline an idea that I think will be my next project.
In the first two posts of this series, we
talked about how to get the basic infrastructure for your tests up
and running. You should have a file with doc tests and one with
unit tests. They should be linked into your django project with an
__init__.py file. If you were feeling adverterous you may have
even added some real content to them. Today we’re going to start
going down the road of getting some data into your tests.
Last post we talked about how to set up and use doc tests inside of Django. Today, in the second post of the series, we’ll be talking about how to use the other testing framework that comes with Python, unittest. unittest is a xUnit type of testing system (JUnit from the java world is another example) implemented in Python. It is a much more robust solution for testing than Doc tests, and allows for a lot more organization of code. We’ll get into that in the next post in the series, comparing Unit and Doc tests.
Note: I’m launching a redesign today to address the styling issues. Please bear with me
This is the first in a series of blog posts and screencasts that will walk you through how to test your Django application. These posts will focus more on how to get things done in Django, but note that a lot of the content is applicable to pure python as well. A lot of best practices are codified into Django’s testing framework, so that we don’t have to worry about them! I will try to point them out as we are using them through, because they are good things to know.
November blog posting month has a special moment in my Django history. It was this time last year that I really got serious into Django. With the help of James Bennett’s and Marty Alchin’s blog post a month streak, I got an incredibly valuable insight into Django. It showed me a lot of the power and other great things about Django (especially the community).
We were talking about things that we wish we had known before while developing for Django the other day in IRC. I proclaimed that we should write them down somewhere. So I’m writing a post to get this effort started. Please feel free to leave comments with your own tips and tricks, and I’ll compile them in some kind of good fashion. These are mostly just pointers, and not full-blown writeups, just more of a big list of stuff you should think about. I think these tips will really help out new people when they’re trying to get the hang of Django.
I went ahead today and figured that I would try out Pinax, seeing as it’s been getting a lot of good press in the Django community lately. The talk from James Tauber at Djangocon was really good, and I certainly recommend checking it out. This is going to be a basic introduction to pinax.
This is a screencast on the Django Command Extensions project. It is one of my favorite third party apps, and it gets installed in every Django environment I work in. It provides a plethora of useful manage.py commands, and a couple other little goodies as well.
Today’s screencast is about pdb again. This time we are going to be debugging management commands, and unit tests for django. This is a little bit more powerful than the previous screencast which just introduced the basic debugging commands.
I had a couple of comments about my last post saying that I should be sending all of the screencasts to the aggregator because this is content and isn’t spam. So I’m going to do that. Thanks for all the feedback everyone! Hope you’re enjoying the series.
This is the second screencast of a week long series.
This is part 1 of a week long series of screencasts
Today I ran into a fun problem when writing template tags at work. (I’ll write another post later on the fun-ness that is testing of template tags :) In ellington we have some templatetags that test for the current time of day. ifmorning, ifnight and so on. These template tags are using datetime.datetime.now() to check to see if the time is within a certain range. This is impossible to test in a standard way without doing some hacking on the datetime.datetime object.
First off let me say that I know that not everyone likes setuptools and that is fine. distutils works well and is included with python. However, I believe that Python needs to get some parity with what Perl has with CPAN. Pypi is Python’s alternative, so tools that integrate with it are good.
Okay, Well I have been hacking away at django-testmaker for the last couple of days based on some ideas from the community. It has gotten a lot better, so here is another blog post showing what’s new.
I was just convinced to setup mod_wsgi on my server instead of mod_python, and I’m going to write up how I did it. All of the documentation I found on the internet was really hard to follow, so I’m going to distill it here the best that I can.
Eek! The job starts Monday! That is like, 36 hours from now. I’m really excited and slightly nervous. The excited feeling comes from the place I’ll be working. For posterities sake, here is the series of interactions that landed me the job:
Had an interesting conversation with my roomate Mike last night. It helped me clarify something I have always understood, but never found a good way to say. This is probably going to be another failed attempt, but here goes.
This is an amazing video of some dynamic 3d work a guy did for his PhD Thesis. Johnny Lee is a PhD student at CMU, and he modified a display to use the wiimote and a special headset to give real 3D effects. It actually changes the picture on the screen based on your proximity and angle to the screen. Amazing.
Starting the good ol’ job hunt. Trying to figure out what I’m going to be doing with myself for the next couple years of my life. Big ol’ decision that it is.
This is a really cool Ford ad. I’m glad companies are starting to understand that commericals are content too. If you make them worth watching, they will get spread and your message will be heard a lot more places. Somebody has been listening to Seth Godin :)
Just posting some books that I want to read this upcoming semester.
The code for the website is now located on launchpad. I am using their bazaar version control system that is kick ass. It’s a Distributed VCS which means that you can run it completely locally, without a server. I use the server of course, but it allows you to do work on your code without internet access and other neat things.
Never heard of a band called Battle before. They have a really neat video that I got pointed to from a really cool advertising blog
EDIT: Hey everyone, I wrote an updated post that actually tells how to setup a django app (and any python app) using easy install. Check it out!
My first four browser tabs have been the same for the past couple hours. The first is the root of all evils, and the other three are productive!
Testing Django Awesomeness
Wordpress you were good to me. I’m going to migrate all my posts over to a new Django blogging app I’m writing. Part of my website for the Event Calendar and learning Django Done soonish hopefully
Basically just a knowledge dump of The firefox extensions I use and where to get them for future reference.
This neat little program lets you use your network as a KVM. You set up a ‘server’ computer where you use the mouse and keyboard, and then ‘client’ computers on the right of left of your server, and when you go off the screen of the server, it automagically goes to control the mouse and KB of the client machine. Really neat.