setuptools 0.7a for Python 3 fails to build on Windows
Thanks to Lennart Regebro for putting together a build of setuptools for Python 3 here: http://regebro.wordpress.com/2009/02/01/setuptools-and-easy_install-for-pyth on-3/ Unfortunately, the package fails to build on Windows. Refer to the blog post (and comments) for details. The problem occurs when get_script_args calls resource_string for the 'cli.exe' launcher. It turns out that in Python 3, the following command yields the same error:
open('setuptools/cli.exe', 'rt').read()
resource_string ultimately executes the same command, which is why the build fails. The correct thing to do in this particular case is to open the file in binary mode, which returns `bytes` instead of a Unicode `str`. Unfortunately, I'm not sure what negative impact would come from altering pkg_resources.DefaultProvider._get to always read bytes, and that doesn't strike me as the correct solution. So, I'm writing here to ask: what should be done about pkg_resources in Python 3 to support getting a package resource that's binary data? As I see it, there are a few options, - always have pkg_resources providers return bytes. - read the bytes and try converting to str, falling back to bytes on failure. - require a parameter to indicate what type of content is expected. There are probably others. Any suggestions are appreciated. Regards, Jason
On Wed, Apr 8, 2009 at 21:12, Jason R. Coombs <jaraco@jaraco.com> wrote:
Unfortunately, I'm not sure what negative impact would come from altering pkg_resources.DefaultProvider._get to always read bytes, and that doesn't strike me as the correct solution.
No, if you do that everything explodes, and you can't even run python3.0 setup.py anymore. So that's definitely not right. :-)
So, I'm writing here to ask: what should be done about pkg_resources in Python 3 to support getting a package resource that's binary data?
As I see it, there are a few options, - always have pkg_resources providers return bytes. - read the bytes and try converting to str, falling back to bytes on failure.
That change does still run all the tests at least, so it's worth a try. I changed DefaultProvider._get to: def _get(self, path): stream = open(path, 'rb') try: data = stream.read() return data.decode() except UnicodeDecodeError: return data finally: stream.close() Try if that makes a difference.
- require a parameter to indicate what type of content is expected.
Tricky, since _get is called from somewhere else than where the fact that it's cli.exe thet should be opened is set. There is too much iterators and indirection in pkg_resources for my small brain. I usually get a headache. :-) -- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64
Lennart, That seems to have done the trick. Between that fix and using the 64-bit cli.exe and gui.exe from http://bugs.python.org/setuptools/issue2, I was able to install setuptools on Python 3.0.1 64-bit on Windows Vista SP1 and run easy_install. For that build in particular, a Windows installer is available at http://dl.getdropbox.com/u/54081/setuptools-0.7a1.win-amd64.exe. I'll try to put together a 32-bit build also later. Thanks so much for doing the Python 3 port. I'll be sure to report back if I encounter any further problems. Now I can get started porting my namespace packages to Python 3. Jason
-----Original Message----- From: Lennart Regebro [mailto:regebro@gmail.com] Sent: Wednesday, 08 April, 2009 15:53 To: Jason R. Coombs Cc: distutils-sig@python.org Subject: Re: [Distutils] setuptools 0.7a for Python 3 fails to build on Windows
On Wed, Apr 8, 2009 at 21:12, Jason R. Coombs <jaraco@jaraco.com> wrote:
Unfortunately, I'm not sure what negative impact would come from altering pkg_resources.DefaultProvider._get to always read bytes, and that doesn't strike me as the correct solution.
No, if you do that everything explodes, and you can't even run python3.0 setup.py anymore. So that's definitely not right. :-)
So, I'm writing here to ask: what should be done about pkg_resources in Python 3 to support getting a package resource that's binary data?
As I see it, there are a few options, - always have pkg_resources providers return bytes. - read the bytes and try converting to str, falling back to bytes on failure.
That change does still run all the tests at least, so it's worth a try. I changed DefaultProvider._get to:
def _get(self, path): stream = open(path, 'rb') try: data = stream.read() return data.decode() except UnicodeDecodeError: return data finally: stream.close()
Try if that makes a difference.
- require a parameter to indicate what type of content is expected.
Tricky, since _get is called from somewhere else than where the fact that it's cli.exe thet should be opened is set. There is too much iterators and indirection in pkg_resources for my small brain. I usually get a headache. :-)
-- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64
On Wed, Apr 8, 2009 at 23:37, Jason R. Coombs <jaraco@jaraco.com> wrote:
Lennart, That seems to have done the trick. Between that fix and using the 64-bit cli.exe and gui.exe from http://bugs.python.org/setuptools/issue2, I was able to install setuptools on Python 3.0.1 64-bit on Windows Vista SP1 and run easy_install. For that build in particular, a Windows installer is available at http://dl.getdropbox.com/u/54081/setuptools-0.7a1.win-amd64.exe. I'll try to put together a 32-bit build also later.
Thanks so much for doing the Python 3 port. I'll be sure to report back if I encounter any further problems.
Now I can get started porting my namespace packages to Python 3.
OK, Cool. I'll try to put in the 2to3 support that I have made for zope.interfaces soon. That should easy porting as well. -- Lennart Regebro: Pythonista, Barista, Notsotrista. http://regebro.wordpress.com/ +33 661 58 14 64
participants (2)
-
Jason R. Coombs
-
Lennart Regebro