changeset 30666:6ada1658fc6b

py3: use python 3 compatible variables in hgext/fsmontor/__init__.py Earlier this was left thinking that its part of pywatchman package. This patch replaces variables os.sep, sys.platform and os.envrion with their py3 compatible ones.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 21 Dec 2016 23:40:38 +0530
parents 01721d382c16
children 5861bdbeb9a3
files hgext/fsmonitor/__init__.py tests/test-check-code.t
diffstat 2 files changed, 7 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/fsmonitor/__init__.py	Wed Dec 21 22:42:31 2016 +0530
+++ b/hgext/fsmonitor/__init__.py	Wed Dec 21 23:40:38 2016 +0530
@@ -94,15 +94,16 @@
 import hashlib
 import os
 import stat
-import sys
 
 from mercurial.i18n import _
 from mercurial import (
     context,
+    encoding,
     extensions,
     localrepo,
     merge,
     pathutil,
+    pycompat,
     scmutil,
     util,
 )
@@ -292,7 +293,7 @@
     if normalize:
         foldmap = dict((normcase(k), k) for k in results)
 
-    switch_slashes = os.sep == '\\'
+    switch_slashes = pycompat.ossep == '\\'
     # The order of the results is, strictly speaking, undefined.
     # For case changes on a case insensitive filesystem we may receive
     # two entries, one with exists=True and another with exists=False.
@@ -392,8 +393,8 @@
 
     def _cmpsets(l1, l2):
         try:
-            if 'FSMONITOR_LOG_FILE' in os.environ:
-                fn = os.environ['FSMONITOR_LOG_FILE']
+            if 'FSMONITOR_LOG_FILE' in encoding.environ:
+                fn = encoding.environ['FSMONITOR_LOG_FILE']
                 f = open(fn, 'wb')
             else:
                 fn = 'fsmonitorfail.log'
@@ -434,7 +435,7 @@
     updatestate = (parentworking and match.always() and
                    not isinstance(ctx2, (context.workingcommitctx,
                                          context.memctx)) and
-                   'HG_PENDING' not in os.environ)
+                   'HG_PENDING' not in encoding.environ)
 
     try:
         if self._fsmonitorstate.walk_on_invalidate:
@@ -545,7 +546,7 @@
 
 def extsetup(ui):
     wrapfilecache(localrepo.localrepository, 'dirstate', wrapdirstate)
-    if sys.platform == 'darwin':
+    if pycompat.sysplatform == 'darwin':
         # An assist for avoiding the dangling-symlink fsevents bug
         extensions.wrapfunction(os, 'symlink', wrapsymlink)
 
--- a/tests/test-check-code.t	Wed Dec 21 22:42:31 2016 +0530
+++ b/tests/test-check-code.t	Wed Dec 21 23:40:38 2016 +0530
@@ -9,21 +9,6 @@
 
   $ hg locate -X contrib/python-zstandard -X hgext/fsmonitor/pywatchman |
   > sed 's-\\-/-g' | xargs "$check_code" --warnings --per-file=0 || false
-  hgext/fsmonitor/__init__.py:295:
-   >     switch_slashes = os.sep == '\\'
-   use pycompat.ossep instead (py3)
-  hgext/fsmonitor/__init__.py:395:
-   >             if 'FSMONITOR_LOG_FILE' in os.environ:
-   use encoding.environ instead (py3)
-  hgext/fsmonitor/__init__.py:396:
-   >                 fn = os.environ['FSMONITOR_LOG_FILE']
-   use encoding.environ instead (py3)
-  hgext/fsmonitor/__init__.py:437:
-   >                    'HG_PENDING' not in os.environ)
-   use encoding.environ instead (py3)
-  hgext/fsmonitor/__init__.py:548:
-   >     if sys.platform == 'darwin':
-   use pycompat.sysplatform instead (py3)
   Skipping i18n/polib.py it has no-che?k-code (glob)
   mercurial/demandimport.py:309:
    >     if os.environ.get('HGDEMANDIMPORT') != 'disable':