[Distutils] setuptools 0.7a for Python 3 fails to build on Windows

Lennart Regebro regebro at gmail.com
Wed Apr 8 21:52:49 CEST 2009


On Wed, Apr 8, 2009 at 21:12, Jason R. Coombs <jaraco at 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


More information about the Distutils-SIG mailing list