On Jan 26, 2010, at 05:53 PM, Lennart Regebro wrote: >On Thu, Jan 7, 2010 at 14:34, Lennart Regebro <rege...@gmail.com> wrote: >> The next problem is that the tests seem to be run on the original, and >> not on the build-copy. And why that is, I don't know, and I have to >> debug that, which I can't do right now. I'll try tonight or tomorrow. >> It's most likely a bug in Distribute. > >Well, kinda. :) > >The problem is this code in setup.py: > > from munepy import __version__ > >That means munepy is already imported, so when it then looks for the >tests to run, it will import it from the already imported munepy
Ah. We've run into similar problems in other contexts. On the face of it, I think it would be wonderful to be able to set the setup.py version number this way, but in practice it seems too problematic. I think this ends up biting namespace packages fairly hard too. >module. Changing it to > > from munepy import __version__ > del sys.modules['munepy'] > >Goes around the problem, but it's admittedly not a pretty fix. >I'm sure others will be bitten by this too. I'm not sure what a good >fix would be, except possibly removing all modules specified in >setup.py from sys.modules before running any commands. I'm going to make the following change to setup.py instead: === modified file 'setup.py' --- setup.py 2010-01-08 21:59:23 +0000 +++ setup.py 2010-01-29 20:55:12 +0000 @@ -18,9 +18,22 @@ import distribute_setup distribute_setup.use_setuptools() +import re import sys -from munepy import __version__ +# Do not import __version__ from munepy. Doing so causes problems with +# doctests running under 2to3. +with open('munepy/__init__.py') as fp: + for line in fp: + if line.startswith('__version__'): + mo = re.search(r'\d+.\d+.\d', line) + assert mo, 'No valid __version__ string found' + __version__ = mo.group(0) + break + else: + raise AssertionError('No __version__ assignment found') + + from setuptools import setup, find_packages However, it would be nice if setuptools/distribute supported something like this out of the box. The important thing is to have exactly one place to set the package's version number. I've had to make a few other changes to the code to get it to pass under 2to3, but I don't think those are on topic for this mailing list, so I'll skip them. Thanks for looking into this! -Barry
signature.asc
Description: PGP signature
_______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig