Patchwork D7225: import-checker: open all source files as utf-8

login
register
mail settings
Submitter phabricator
Date Nov. 5, 2019, 4:04 p.m.
Message ID <bd2671375410e02657eea8e2ad9c153a@localhost.localdomain>
Download mbox | patch
Permalink /patch/42752/
State Not Applicable
Headers show

Comments

phabricator - Nov. 5, 2019, 4:04 p.m.
Closed by commit rHGa8454e846736: import-checker: open all source files as utf-8 (authored by indygreg).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7225?vs=17547&id=17556

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7225/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7225

AFFECTED FILES
  contrib/import-checker.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -4,6 +4,7 @@ 
 
 import ast
 import collections
+import io
 import os
 import sys
 
@@ -754,7 +755,11 @@ 
             yield src.read(), modname, f, 0
             py = True
     if py or f.endswith('.t'):
-        with open(f, 'r') as src:
+        # Strictly speaking we should sniff for the magic header that denotes
+        # Python source file encoding. But in reality we don't use anything
+        # other than ASCII (mainly) and UTF-8 (in a few exceptions), so
+        # simplicity is fine.
+        with io.open(f, 'r', encoding='utf-8') as src:
             for script, modname, t, line in embedded(f, modname, src):
                 yield script, modname.encode('utf8'), t, line