From owner-freebsd-python@FreeBSD.ORG Thu May 29 10:12:45 2014 Return-Path: Delivered-To: freebsd-python@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 15E25208 for ; Thu, 29 May 2014 10:12:45 +0000 (UTC) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.31.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C9D73277D for ; Thu, 29 May 2014 10:12:44 +0000 (UTC) Received: from [89.182.48.251] (helo=localhost) by smtprelay04.ispgateway.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1WpxHt-0004vy-S3 for freebsd-python@freebsd.org; Thu, 29 May 2014 12:10:18 +0200 Date: Thu, 29 May 2014 12:10:18 +0200 From: Marcus von Appen To: freebsd-python@freebsd.org Subject: Enable PYDISTUTILS_SETUP to deal with different encodings in a setup.py file Message-ID: <20140529101018.GA847@medusa.sysfault.org> Reply-To: Marcus von Appen Mail-Followup-To: freebsd-python@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="azLHFNyN32YCQGCU" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Df-Sender: MTEyNTc0Mg== X-BeenThere: freebsd-python@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: FreeBSD-specific Python issues List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2014 10:12:45 -0000 --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Dear all, when trying to update graphics/py-PyX I stumbled across a unicode decode error on reading the setup.py file for PyX version 0.13. Our current approach is to read setup.py into a string buffer, to replace the line endings and pass the result to compile() and exec(). This works great as long as * the execution environment is configured to deal with matching encodings properly (so that locale.getpreferredencoding() returns a file-compatible encoding) * the setup.py file features a proper encoding so that the execution environment can deal with it (see above) The majority of ports uses setup.py files, which use ASCII only. PyX 0.13 however contains some UTF-8 codepoints (umlauts), which causes the error above, if the execution environment does not use some UTF-8 locale. To work around that issue, we just need to read the file contents into a byte buffer instead of converting the file contents to a string buffer: -PYDISTUTILS_SETUP?= -c "import setuptools; __file__='${PYSETUP}'; exec(compile(open(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))" +PYDISTUTILS_SETUP?= -c "import setuptools; __file__='${PYSETUP}'; exec(compile(open(__file__, 'rb').read().replace(b'\\r\\n', b'\\n'), __file__, 'exec'))" If there are no concerns, I'll commit the change this weekend. Cheers Marcus --azLHFNyN32YCQGCU Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (FreeBSD) iEYEARECAAYFAlOHB4oACgkQi68/ErJnpkcmOQCeLJEMJNCRLvPZBe7oWIJyfkeE 2wwAn2UldMCjgUIgxkdGX1wX5XnoZA9e =9pe6 -----END PGP SIGNATURE----- --azLHFNyN32YCQGCU--