setuptools and use_2to3
![](https://secure.gravatar.com/avatar/d995b462a98fea412efa79d17ba3787a.jpg?s=120&d=mm&r=g)
I'm trying to convert a setup.py to use setuptools (specifically the docutils build, FWIW). The existing setup.py has some custom command stuff to run 2to3 on build. As I understand it, setuptools should do this automatically by using use_2to3=True. So, I've changed the code to just do: setup( ... packages=find_packages(), use_2to3=True, ... ) However, when I do python setup.py bdist_wheel, I find that docutils/__init__.py within the wheel still contains (for example) class ApplicationError(StandardError): ... So the StandardError -> Exception fixer isn't being run. Am I doing something wrong here? The setuptools documentation isn't very clear on what I should do, or what to expect. Thanks, Paul
![](https://secure.gravatar.com/avatar/9381c7f1185e9c17527fccef45bdc09c.jpg?s=120&d=mm&r=g)
On Mon, Nov 11, 2013 at 04:29:32PM +0000, Paul Moore wrote:
I'm trying to convert a setup.py to use setuptools (specifically the docutils build, FWIW). The existing setup.py has some custom command stuff to run 2to3 on build.
Aside: I believe there's consensus now that 2to3 is not the best way to support Python 2.x and 3.x. It's not that hard to have a single source tree in a portable subset of Python 2.x and 3.x. See python3porting.com and https://pypi.python.org/pypi/six.
As I understand it, setuptools should do this automatically by using use_2to3=True.
So, I've changed the code to just do:
setup( ... packages=find_packages(), use_2to3=True, ... )
However, when I do python setup.py bdist_wheel, I find that docutils/__init__.py within the wheel still contains (for example)
class ApplicationError(StandardError): ...
So the StandardError -> Exception fixer isn't being run.
Am I doing something wrong here? The setuptools documentation isn't very clear on what I should do, or what to expect.
I wouldn't be surprised to learn that bdist_wheel doesn't support use_2to3, but I don't actually *know* that for a fact, since I never used 2to3. Marius Gedminas -- What goes up, must come down. Ask any system administrator.
![](https://secure.gravatar.com/avatar/d995b462a98fea412efa79d17ba3787a.jpg?s=120&d=mm&r=g)
On 11 November 2013 17:26, Marius Gedminas <marius@pov.lt> wrote:
On Mon, Nov 11, 2013 at 04:29:32PM +0000, Paul Moore wrote:
I'm trying to convert a setup.py to use setuptools (specifically the docutils build, FWIW). The existing setup.py has some custom command stuff to run 2to3 on build.
Aside: I believe there's consensus now that 2to3 is not the best way to support Python 2.x and 3.x. It's not that hard to have a single source tree in a portable subset of Python 2.x and 3.x. See python3porting.com and https://pypi.python.org/pypi/six.
Yes, I realise that. I'm not a fan of 2to3 at all myself, but it's what docutils uses and I'm not trying to do a full docutils port to shared source, just a quick local fork of setup.py to allow me to make some simple changes (using entry points rather than custom scripts, in particular). I only started looking at the 2to3 stuff because docutils' setup.py does some complex distutils customisation that I thought might give setuptools some problems. And as all it was doing was implementing things that are built into setuptools, it seemed worth looking at as a simplification.
I wouldn't be surprised to learn that bdist_wheel doesn't support use_2to3, but I don't actually *know* that for a fact, since I never used 2to3.
It's possible I guess. But I thought bdist_wheel used the normal build command, so stuff like 2to3 support should be unchanged. Thanks for the comments anyway, Paul
![](https://secure.gravatar.com/avatar/9ff70f96fa67c2a3c80ecf0486138bc2.jpg?s=120&d=mm&r=g)
On Mon, Nov 11, 2013 at 6:26 PM, Marius Gedminas <marius@pov.lt> wrote:
Aside: I believe there's consensus now that 2to3 is not the best way to support Python 2.x and 3.x. It's not that hard to have a single source tree in a portable subset of Python 2.x and 3.x. See python3porting.com and https://pypi.python.org/pypi/six.
Well, that depends. Mainly on what Python versions you need to support.
![](https://secure.gravatar.com/avatar/9ff70f96fa67c2a3c80ecf0486138bc2.jpg?s=120&d=mm&r=g)
On Mon, Nov 11, 2013 at 5:29 PM, Paul Moore <p.f.moore@gmail.com> wrote:
I'm trying to convert a setup.py to use setuptools (specifically the docutils build, FWIW). The existing setup.py has some custom command stuff to run 2to3 on build.
As I understand it, setuptools should do this automatically by using use_2to3=True.
So, I've changed the code to just do:
setup( ... packages=find_packages(), use_2to3=True, ... )
However, when I do python setup.py bdist_wheel, I find that docutils/__init__.py within the wheel still contains (for example)
class ApplicationError(StandardError): ...
So the StandardError -> Exception fixer isn't being run.
Am I doing something wrong here? The setuptools documentation isn't very clear on what I should do, or what to expect.
If 2to3 is being run you'll get quite a lot of fairly obvious output to that effect. So it sounds like it's not. A quick look at bdist_egg seems to indicate that it never runs the build_py step, which is what runs 2to3. So this may be a bug. //Lennart
![](https://secure.gravatar.com/avatar/d995b462a98fea412efa79d17ba3787a.jpg?s=120&d=mm&r=g)
On 11 November 2013 20:45, Lennart Regebro <regebro@gmail.com> wrote:
If 2to3 is being run you'll get quite a lot of fairly obvious output to that effect. So it sounds like it's not.
A quick look at bdist_egg seems to indicate that it never runs the build_py step, which is what runs 2to3. So this may be a bug.
Good thought. python setup.py build does run 2to3, and as you say the output is not something you can miss. So setup.py bdist_wheel isn't running build, which is likely a bug (but also not hard to work around). That's probably good enough for now - this whole exercise is a local hack, so just getting it to work is likely good enough. I'm not enough of a fan of the whole 2to3 process to be bothered spending time producing a reproducible test case, etc, for a good-quality bug report. I might just report it as it stands and leave it at that, though, so at least it doesn't get forgotten. Thanks. Paul
participants (3)
-
Lennart Regebro
-
Marius Gedminas
-
Paul Moore