Patchwork D11072: check-code: add a rules to catch os.path.abspath

login
register
mail settings
Submitter phabricator
Date July 10, 2021, 5:46 p.m.
Message ID <differential-rev-PHID-DREV-mr6cgz3bowl7goiftjw3-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49385/
State Superseded
Headers show

Comments

phabricator - July 10, 2021, 5:46 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  All previous usages have been migrated. So let us add a check-code rules to
  catch future usages.
  
  We restrict it to mercurial/ and hgext/ because multiple other script never
  depends on Mercurial modules.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  contrib/check-code.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -545,6 +545,22 @@ 
     ),
 ]
 
+# pattern only for mercurial and extensions
+core_py_pats = [
+    [
+        # Windows tend to get confused about capitalization of the drive letter
+        #
+        # see mercurial.windows.abspath for details
+        (
+            r'os\.path\.abspath',
+            "use util.abspath instead (windows)",
+            r'#.*re-exports',
+        ),
+    ],
+    # warnings
+    [],
+]
+
 # filters to convert normal *.py files
 pyfilters = [] + commonpyfilters
 
@@ -700,6 +716,13 @@ 
         pyfilters,
         py3pats,
     ),
+    (
+        'core files',
+        r'.*(hgext|mercurial)/(?!demandimport|policy|pycompat).*\.py',
+        '',
+        pyfilters,
+        core_py_pats,
+    ),
     ('test script', r'(.*/)?test-[^.~]*$', '', testfilters, testpats),
     ('c', r'.*\.[ch]$', '', cfilters, cpats),
     ('unified test', r'.*\.t$', '', utestfilters, utestpats),