[Reproducible-builds] [dh-python] 156/183: Assume UTF-8 encoding also in non UTF-8 environments while opening text files

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Sep 19 15:30:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository dh-python.

commit fdc948d8200cabd40e1bcc45146d011c6fbdb2d2
Author: Piotr Ożarowski <piotr at debian.org>
Date:   Mon Jan 27 21:56:02 2014 +0100

    Assume UTF-8 encoding also in non UTF-8 environments while opening text files
---
 debian/changelog                   |  2 ++
 dh_python2                         |  8 ++++----
 dhpython/build/plugin_distutils.py |  2 +-
 dhpython/debhelper.py              | 14 +++++++-------
 dhpython/pydist.py                 |  6 +++---
 dhpython/tools.py                  |  4 ++--
 6 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 031b85d..096d26c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -5,6 +5,8 @@ dh-python (1.20131021-2) UNRELEASED; urgency=low
     when more than one Python 3 version is supported (closes: 733128)
   * Make sure only first line is taken into account while checking shebangs
     (closes: 732308)
+  * Assume UTF-8 encoding also in non UTF-8 environments while opening text
+    files (closes: 735370)
 
  -- Piotr Ożarowski <piotr at debian.org>  Tue, 05 Nov 2013 22:57:20 +0100
 
diff --git a/dh_python2 b/dh_python2
index 5c37dcc..f7f96c0 100755
--- a/dh_python2
+++ b/dh_python2
@@ -345,7 +345,7 @@ def main():
 
     if not options.vrange and exists('debian/pyversions'):
         log.debug('parsing version range from debian/pyversions')
-        with open('debian/pyversions') as fp:
+        with open('debian/pyversions', encoding='utf-8') as fp:
             for line in fp:
                 line = line.strip()
                 if line and not line.startswith('#'):
@@ -355,7 +355,7 @@ def main():
     # disable PyDist if dh_pydeb is used
     if options.guess_deps:
         try:
-            rules = open('debian/rules', 'r').read()
+            rules = open('debian/rules', 'r', encoding='utf-8').read()
         except IOError:
             log.warning('cannot open debian/rules file')
         else:
@@ -432,7 +432,7 @@ def main():
             if len(ps) > 1 and ps[0] == 'python':
                 dh.addsubstvar(package, 'python:Provides',
                                ', '.join("python%s-%s" % (i, ps[1])
-                               for i in sorted(stats['public_vers'])))
+                                         for i in sorted(stats['public_vers'])))
 
         pyclean_added = False  # invoke pyclean only once in maintainer script
         if stats['compile']:
@@ -511,7 +511,7 @@ def main():
             dstdir = join('debian', package, 'usr/share/python/ns/')
             if not exists(dstdir):
                 os.makedirs(dstdir)
-            with open(join(dstdir, package), 'a') as fp:
+            with open(join(dstdir, package), 'a', encoding='utf-8') as fp:
                 fp.writelines("%s\n" % i for i in nsp)
 
         pyshared = join('debian', package, 'usr/share/pyshared/')
diff --git a/dhpython/build/plugin_distutils.py b/dhpython/build/plugin_distutils.py
index cd9274a..2a74db7 100644
--- a/dhpython/build/plugin_distutils.py
+++ b/dhpython/build/plugin_distutils.py
@@ -40,7 +40,7 @@ def create_pydistutils_cfg(func):
     def wrapped_func(self, context, args, *oargs, **kwargs):
         fpath = join(args['home_dir'], '.pydistutils.cfg')
         if not exists(fpath):
-            with open(fpath, 'w') as fp:
+            with open(fpath, 'w', encoding='utf-8') as fp:
                 fp.writelines(['[clean]\n',
                                'all=1\n',
                                '[build]\n',
diff --git a/dhpython/debhelper.py b/dhpython/debhelper.py
index dfca0d2..9c519f0 100644
--- a/dhpython/debhelper.py
+++ b/dhpython/debhelper.py
@@ -118,7 +118,7 @@ class DebHelper:
             for when, templates in autoscripts.items():
                 fn = "debian/%s.%s.debhelper" % (package, when)
                 if exists(fn):
-                    with open(fn, 'r') as datafile:
+                    with open(fn, 'r', encoding='utf-8') as datafile:
                         data = datafile.read()
                 else:
                     data = ''
@@ -131,7 +131,7 @@ class DebHelper:
                                      "autoscripts/%s" % tpl_name)
                         if not exists(fpath):
                             fpath = "/usr/share/debhelper/autoscripts/%s" % tpl_name
-                        with open(fpath, 'r') as tplfile:
+                        with open(fpath, 'r', encoding='utf-8') as tplfile:
                             tpl = tplfile.read()
                         if self.options.compile_all and args:
                             # TODO: should args be checked to contain dir name?
@@ -144,7 +144,7 @@ class DebHelper:
                 if new_data:
                     data += '\n# Automatically added by dhpython:' +\
                             '{}\n# End automatically added section\n'.format(new_data)
-                    fp = open(fn, 'w')
+                    fp = open(fn, 'w', encoding='utf-8')
                     fp.write(data)
                     fp.close()
 
@@ -155,7 +155,7 @@ class DebHelper:
                 continue
             fn = "debian/%s.substvars" % package
             if exists(fn):
-                with open(fn, 'r') as datafile:
+                with open(fn, 'r', encoding='utf-8') as datafile:
                     data = datafile.read()
             else:
                 data = ''
@@ -181,7 +181,7 @@ class DebHelper:
                     data += "%s=%s\n" % (name, ', '.join(items))
             data = data.replace('\n\n', '\n')
             if data:
-                fp = open(fn, 'w')
+                fp = open(fn, 'w', encoding='utf-8')
                 fp.write(data)
                 fp.close()
 
@@ -196,7 +196,7 @@ class DebHelper:
                 makedirs(d)
             fn = "%s/%s.rtupdate" % (d, package)
             if exists(fn):
-                data = open(fn, 'r').read()
+                data = open(fn, 'r', encoding='utf-8').read()
             else:
                 data = "#! /bin/sh\nset -e"
             for dname, args in values:
@@ -206,7 +206,7 @@ class DebHelper:
                 if cmd not in data:
                     data += "\n%s" % cmd
             if data:
-                fp = open(fn, 'w')
+                fp = open(fn, 'w', encoding='utf-8')
                 fp.write(data)
                 fp.close()
                 chmod(fn, 0o755)
diff --git a/dhpython/pydist.py b/dhpython/pydist.py
index 3d37953..28d09f2 100644
--- a/dhpython/pydist.py
+++ b/dhpython/pydist.py
@@ -59,7 +59,7 @@ REQUIRES_RE = re.compile(r'''
 
 def validate(fpath):
     """Check if pydist file looks good."""
-    with open(fpath) as fp:
+    with open(fpath, encoding='utf-8') as fp:
         for line in fp:
             line = line.strip('\r\n')
             if line.startswith('#') or not line:
@@ -94,7 +94,7 @@ def load(impl):
 
     result = {}
     for fpath in to_check:
-        with open(fpath) as fp:
+        with open(fpath, encoding='utf-8') as fp:
             for line in fp:
                 line = line.strip('\r\n')
                 if line.startswith('#') or not line:
@@ -213,7 +213,7 @@ def parse_pydep(impl, fname):
             else:
                 processed.append(line)
     if modified:
-        with open(fname, 'w') as fp:
+        with open(fname, 'w', encoding='utf-8') as fp:
             fp.writelines(i + '\n' for i in processed)
     return result
 
diff --git a/dhpython/tools.py b/dhpython/tools.py
index e2f944b..1aa922e 100644
--- a/dhpython/tools.py
+++ b/dhpython/tools.py
@@ -144,7 +144,7 @@ def parse_ns(fpaths, other=None):
     """Parse namespace_packages.txt files."""
     result = set(other or [])
     for fpath in fpaths:
-        with open(fpath, 'r') as fp:
+        with open(fpath, 'r', encoding='utf-8') as fp:
             for line in fp:
                 if line:
                     result.add(line.strip())
@@ -208,7 +208,7 @@ def execute(command, cwd=None, env=None, log_output=None):
     elif log_output:
         if isinstance(log_output, str):
             close = True
-            log_output = open(log_output, 'a')
+            log_output = open(log_output, 'a', encoding='utf-8')
         log_output.write('\n# command executed on {}'.format(datetime.now().isoformat()))
         log_output.write('\n$ {}\n'.format(command))
         log_output.flush()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dh-python.git



More information about the Reproducible-builds mailing list