diff contrib/check-code.py @ 30665:01721d382c16

py3: add warnings in check-code related to py3 We have our own bytes versions of things like, getopt.getopt, os.sep, os.name, sys.executable, os.environ and few more for python 3 portability. Its better to come up with warnings if someone breaks the things which we have fixed. After this patch, check-code will warn us to use our bytes version. These checks run on mercurial/ and hgext/ and pycompat.py is excluded.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 21 Dec 2016 22:42:31 +0530
parents cbeb54ec0481
children df5d3734b3df
line wrap: on
line diff
--- a/contrib/check-code.py	Mon Dec 19 02:54:49 2016 +0530
+++ b/contrib/check-code.py	Wed Dec 21 22:42:31 2016 +0530
@@ -456,8 +456,26 @@
   [],
 ]
 
+py3pats = [
+  [
+    (r'os\.environ', "use encoding.environ instead (py3)"),
+    (r'os\.name', "use pycompat.osname instead (py3)"),
+    (r'os\.getcwd', "use pycompat.getcwd instead (py3)"),
+    (r'os\.sep', "use pycompat.ossep instead (py3)"),
+    (r'os\.pathsep', "use pycompat.ospathsep instead (py3)"),
+    (r'os\.altsep', "use pycompat.osaltsep instead (py3)"),
+    (r'os\.getenv', "use pycompat.osgetenv instead (py3)"),
+    (r'sys\.platform', "use pycompat.sysplatform instead (py3)"),
+    (r'getopt\.getopt', "use pycompat.getoptb instead (py3)"),
+  ],
+  # warnings
+  [],
+]
+
 checks = [
     ('python', r'.*\.(py|cgi)$', r'^#!.*python', pyfilters, pypats),
+    ('python 3', r'.*(hgext|mercurial).*(?<!pycompat)\.py', '',
+            pyfilters, py3pats),
     ('test script', r'(.*/)?test-[^.~]*$', '', testfilters, testpats),
     ('c', r'.*\.[ch]$', '', cfilters, cpats),
     ('unified test', r'.*\.t$', '', utestfilters, utestpats),