1. Tarek Ziadé
  2. distribute
  3. Pull requests

Pull requests

#13 Declined
Repository
distribute-fixinitencoding
Branch
default
Repository
distribute
Branch
default

Fix for #310: Open __init__.py with the correct encoding

Author
  1. Walter Dörwald
Reviewers
Description

On Python 3 build_py.check_package() fails when the init.py contains non-ASCII chars. This patch fixes the problem by using tokenize.open() or tokenize.detect_encoding() and open() instead of plain open() with the default encoding.

Comments (3)

  1. Jason R. Coombs

    The use of 'with' will break usage on Python 2.4, which distribute still supports.

    Since this function is only seeking to find the bytes 'declare_namespace' somewhere in the file, why not open it as a byte-stream on all versions of Python?

    I'm thinking something like this:

    diff -r 260c852e9b9e setuptools/command/build_py.py
    --- a/setuptools/command/build_py.py    Wed Jul 25 05:11:56 2012 +0200
    +++ b/setuptools/command/build_py.py    Sun Aug 12 20:23:04 2012 -0400
    @@ -215,8 +215,8 @@
             else:
                 return init_py
    
    -        f = open(init_py,'rU')
    -        if 'declare_namespace' not in f.read():
    +        f = open(init_py,'rb')
    +        if 'declare_namespace'.encode() not in f.read():
                 from distutils import log
                 log.warn(
                    "WARNING: %s is a namespace package, but its __init__.py does\n"