[Python-checkins] cpython: Issue #12112: fix the encoding of setup.py in the packaging module
victor.stinner
python-checkins at python.org
Thu May 19 21:45:24 CEST 2011
http://hg.python.org/cpython/rev/a636cb1b7f84
changeset: 70210:a636cb1b7f84
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Thu May 19 21:42:47 2011 +0200
summary:
Issue #12112: fix the encoding of setup.py in the packaging module
* read: use tokenize.detect_encoding()
* write: use 'utf-8'
files:
Lib/packaging/create.py | 5 ++++-
Lib/packaging/util.py | 6 +++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/Lib/packaging/create.py b/Lib/packaging/create.py
--- a/Lib/packaging/create.py
+++ b/Lib/packaging/create.py
@@ -32,6 +32,7 @@
import re
import shutil
import sysconfig
+import tokenize
from configparser import RawConfigParser
from textwrap import dedent
from hashlib import md5
@@ -116,7 +117,9 @@
This function load the setup file in all cases (even if it have already
been loaded before, because we are monkey patching its setup function with
a particular one"""
- with open("setup.py") as f:
+ with open("setup.py", "rb") as f:
+ encoding, lines = tokenize.detect_encoding(f.readline)
+ with open("setup.py", encoding=encoding) as f:
imp.load_module("setup", f, "setup.py", (".py", "r", imp.PY_SOURCE))
diff --git a/Lib/packaging/util.py b/Lib/packaging/util.py
--- a/Lib/packaging/util.py
+++ b/Lib/packaging/util.py
@@ -346,9 +346,9 @@
logger.info("writing byte-compilation script '%s'", script_name)
if not dry_run:
if script_fd is not None:
- script = os.fdopen(script_fd, "w")
+ script = os.fdopen(script_fd, "w", encoding='utf-8')
else:
- script = open(script_name, "w")
+ script = open(script_name, "w", encoding='utf-8')
with script:
script.write("""\
@@ -1087,7 +1087,7 @@
if os.path.exists("setup.py"):
raise PackagingFileError("a setup.py file alreadyexists")
- with open("setup.py", "w") as fp:
+ with open("setup.py", "w", encoding='utf-8') as fp:
fp.write(_SETUP_TMPL % {'func': getsource(cfg_to_args)})
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list