[Distutils] setuptools and py3k

Ronald Oussoren ronaldoussoren at mac.com
Mon Jun 8 17:27:32 CEST 2009


On 8 Jun, 2009, at 5:53, Tres Seaver wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> 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:
>> +NORMALIZE_WHITESPACE*
>>        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.

I like your workaround. A tradition unittest would be better, but I'd  
prefer to keep the patches for py3k support as small as possible.
>
>> 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.

This is only a first step, I'm found a number of annoying issues that  
might require interface changes to get right (such a number of  
functions in pkg_resources that claim to return a string, but actually  
return bytes (by opening a file in binary mode and returning the file  
contents).  Hopefully I'll have a set of patches soonish, that would  
make discussion easier.

Ronald
>
>
> Tres.
> - --
> ===================================================================
> Tres Seaver          +1 540-429-0999          tseaver at palladion.com
> Palladion Software   "Excellence by Design"    http://palladion.com
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFKLQnZ+gerLs4ltQ4RAh3cAJ4wHai8q+svdYKjDLB3sk8LwshIMgCg1PDL
> xFCDzoM52IwA1n0rUlBsWpU=
> =zl9H
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Distutils-SIG maillist  -  Distutils-SIG at python.org
> http://mail.python.org/mailman/listinfo/distutils-sig



More information about the Distutils-SIG mailing list