[Distutils] EasyInstall: svn support

Ian Bicking ianb at colorstudy.com
Sun May 29 23:26:08 CEST 2005

Phillip J. Eby wrote:
>>   Basically it detects the svn index page (for http repositories, 
>> which can't be detected based on the URL), or the svn: URL type, and 
>> downloads from there.  I'd like for it to fix up the version based on 
>> the svn revision, but I haven't looked closely enough at that part 
>> yet, or if it's even possible since setup.py typically has a version 
>> hardcoded in it.  I'm not even sure what the version number should 
>> look like, so that it sorts properly with released versions (or even 
>> if it should sort with released versions at all; should versions also 
>> indicate branches, like stable vs. development?)
> Yeah, I think sticking with the setup.py version is best; EasyInstall 
> and pkg_resources use the generated PKG-INFO to find out stuff like that.

Well, at least for my own packages I'll try to make the version better, 
by dynamically generating it in setup.py; I tried to do this a little 
with Paste, but there's some improvement to be done there as well.  What 
form should it take?

E.g., if the last revision was 0.1, what should the trunk version be? 
0.2alpha-svn2822?  Does the released version need to be 0.2final then? 
Or do are version numbers sorted based on a better algorithm than string 

>> Anyway, I've attached a diff against 0.3a1 and the compete modified 
>> easy_install.py file.
> I was a bit puzzled by the diff at first; looks like you created a 
> reversed diff.

Oops.  I have a hard time with diff for some reason.  Like some kind of 
chronological dyslexia.

>> --- easy_install.py     2005-05-29 14:30:03.858797032 -0500
>> +++ orig/setuptools-0.3a1/easy_install.py       2005-05-28 
>> 21:36:42.000000000 -0500
>> @@ -154,7 +154,6 @@
>>  """
>>  import sys, os.path, pkg_resources, re, zipimport
>> -import shutil
>>  from pkg_resources import *
>> @@ -220,7 +219,7 @@
>>          if isinstance(spec,Requirement):
>>              pass
>>          else:
>> -            scheme = URL_SCHEME(spec).group(1)
> This won't work with non-URL specs.  Note that spec is allowed to be a 
> local filename, or a version requirement (e.g. "FooPackage==1.2").  
> Anyway, I moved the group() to the _download_url() call, where it should 
> accomplish the intent here.

OK.  Or it could be:

   scheme = URL_SCHEME(spec)
   scheme = scheme and scheme.group(1)

It seems like a match object is a little odd to pass around.

> As for this next bit below, you're just skipping the archive checks if 
> the source is a directory, right?  There aren't any changes to the 
> archive handling parts?

Yes, that's all -- since svn co creates a directory, it doesn't need to 
be unpacked.

>> -        if not os.path.exists(destination) or not 
>> self.samefile(egg_path, destination):
>> +        if not self.samefile(egg_path, destination):
> I don't understand what this change is for.  Since install_egg is only 
> called with an existing .egg file or directory, this means that if the 
> destination doesn't exist, it can't be the same file.  So, the addition 
> here seems redundant.

I was getting an error when calling self.samefile(filename, 
filename_that_doesnt_exist).  Maybe self.samefile needs to check 

>> -        # Check if it is a subversion index page:
> Before doing this, I think it would be a good idea to check the headers 
> for a text/html Content-Type, so as not to be readline() a big chunk of 
> binary.  :)

Ah, yes, indeed.

>> -    def _download_svn(self, scheme, url, filename):
>> -        os.system("svn checkout -q %s %s" % (url, filename))
> Why checkout instead of export?  Oh, I see, it's so you can use svn info 
> later.  Never mind.

Yeah, not a big reason.  Though it would be nice if, based on some 
option, it could be an "svn up" instead of a checkout, if there was some 
cache of checkouts.

And annoyingly, you can't use svn info on a remote repository; the only 
way I've figured to get the last changed revision of a remote repository 
is with "svn ls -v parent_dir".

>> -        # Actually, this probably doesn't do anything; but somehow this
>> -        # information should get put into the version string...
> It indeed doesn't do anything; you'd be better off munging the setup.py 
> to change the setup version.
> Maybe what I can do is have the build stuff look for a .svn dir in the 
> build area, and if one is present, grab the revision and add it to the 
> end of the version string supplied to setup().  Or simpler still, I 
> could add a '--tag-svn-revision' option to bdist_egg, that would make 
> *it* do that.  I've been thinking it would be nice to have a 
> '--tag-build=NUMBER' or '--tag-date' option for bdist_egg anyway, to 
> support daily builds and such.  So adding an option to "get the tag 
> value from 'svn info'" would just be a minor variation on the theme.

Yes, that would work well.

> Anyway, do you have some handy svn: and http: subversion URLs that I 
> could play with for testing?

svn://colorstudy.com/trunk/SQLObject and 
http://svn.colorstudy.com/trunk/SQLObject should both be workable, and 
point to the same location.

It should really look for a scheme of 'svn+ssh' as well, but those are a 
pain to make readable ;)  And technically file: should work for svn too, 
which I suppose you could detect because it points to a directory with a 
db/fs-type file.  Eh, those can wait.

Ian Bicking  /  ianb at colorstudy.com  / http://blog.ianbicking.org

More information about the Distutils-SIG mailing list