We just spend two hours chasing down a bug in our code. Internally, we use subversion as we have to manage xml content that gets edited by multiple people and that we want to manage multiple versions of. So subversion matches quite well.
At some point in time, it was decided that py.path‘s svn wrapper would be handy. For some things, it really is.
But watch out: there’s an internal well-hidden cache for storing svn info for up to 20 seconds. This includes revision number information. So in our doctest we modify something, commit it (using py.path), do an “svn up” (using py.path) and... the revision number is still stuck at the old value.
What? Debugging time! Checking the directory: yeah, everything is updated just fine. So where’s the problem? This is where the power of open source comes in: you can just look at the original source code and discover where the problem is. Ah, some information is stored for performance reasons in a module-level dictionary that functions as a singleton.
In our code (luckily only in one place) we now solve it by clearing the dictionary that is used as a cache:
from py.__.path.svn import cache # cache is a dictionary that is used as a singleton def some_method(): ... cache.clear() ...
py.__.path.svn looks like madness. Double underscores in an import?
It is apparently valid. Probably an “inventive” way to keep stuff private.
I’d rather not have such inventive dirty rotten maggot-invested flea-ridden
junk in my code, however.
Update: a less intrusive fix is to pass
usecache=False to the
info() call. You need to do that everywhere. Luckily we already make a
subclass of the related py.path class to override some things, so a custom
info() method doesn’t hurt that much.
My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):