[Distutils] setuptools and py3k

Tres Seaver tseaver at palladion.com
Mon Jun 8 14:53:45 CEST 2009

Hash: SHA1

Ronald Oussoren wrote:

> But first a question:  some of the tests use docutils and I'm having a  
> hard time getting those to run with both python3 and python2. The bit  
> that's particularly annoying is this bit of api_tests.txt:
>     Note that asking for a conflicting version of a distribution  
> already in a
>     working set triggers a ``pkg_resources.VersionConflict`` error:
>         >>> ws.find(Requirement.parse("Bar==1.0")) # doctest:  
>         Traceback (most recent call last):
>           ...
>         VersionConflict: (Bar 0.9 (http://example.com/something),
>                        Requirement.parse('Bar==1.0'))
> This passes with 2.6, but fails in 3.1 because it expects  
> 'pkg_resources.VersionConflict' rather than just 'VersionConflict'.  
> What's the best way to work around this issue?

Don't rely on the repr of an exception.  This kind of problem is why I
hate using doctest to test edge cases.  If you must, then something like:

   >>> from pkg_resources import VersionConflict
   >>> try:
   ...     ws.find(Requirement.parse("Bar==1.0"))
   ... except VersionConflict:
   ...     pass
   ... else:
   ...     print 'VersionConflict not raised.'

with no output expected.  Note that this is actually *less* verbose and
easier to understand than the repr bit.  Of course, a traditional unit
test would be even shorter and easier to understand.

> The attached file "setup3.py" is a script that incrementally copies  
> the setuptools source-tree to a temporary directory, runs 2to3 on that  
> copy and exec-s the contents of the translated 'setup.py' file. This  
> seems to be good enough to be able to install setuptools for python2  
> and python3 using the same code-base.   That said, this is just the  
> first step of a python3 port there need to be changes to the  
> setuptools sources to be able to actually use the translated sources.

Great work.

- --
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


More information about the Distutils-SIG mailing list