# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1484466425 -19800 # Node ID 6a70cf94d1b5f77a2747e3fcaff11be873e79ac4 # Parent 897726622877df430f6c9e8399e9a37bb8d55ce4 py3: replace pycompat.getenv with encoding.environ.get pycompat.getenv returns os.getenvb on py3 which is not available on Windows. This patch replaces them with encoding.environ.get and checks to ensure no new instances of os.getenv or os.setenv are introduced. diff -r 897726622877 -r 6a70cf94d1b5 contrib/check-code.py --- a/contrib/check-code.py Sun Jan 15 16:33:15 2017 +0900 +++ b/contrib/check-code.py Sun Jan 15 13:17:05 2017 +0530 @@ -465,9 +465,10 @@ (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)"), + (r'os\.getenv', "use encoding.environ.get instead"), + (r'os\.setenv', "modifying the environ dict is not preferred"), ], # warnings [], diff -r 897726622877 -r 6a70cf94d1b5 hgext/largefiles/lfutil.py --- a/hgext/largefiles/lfutil.py Sun Jan 15 16:33:15 2017 +0900 +++ b/hgext/largefiles/lfutil.py Sun Jan 15 13:17:05 2017 +0530 @@ -19,6 +19,7 @@ from mercurial import ( dirstate, + encoding, error, httpconnection, match as matchmod, @@ -74,19 +75,19 @@ if path: return path if pycompat.osname == 'nt': - appdata = pycompat.osgetenv('LOCALAPPDATA',\ - pycompat.osgetenv('APPDATA')) + appdata = encoding.environ.get('LOCALAPPDATA',\ + encoding.environ.get('APPDATA')) if appdata: return os.path.join(appdata, longname) elif platform.system() == 'Darwin': - home = pycompat.osgetenv('HOME') + home = encoding.environ.get('HOME') if home: return os.path.join(home, 'Library', 'Caches', longname) elif pycompat.osname == 'posix': - path = pycompat.osgetenv('XDG_CACHE_HOME') + path = encoding.environ.get('XDG_CACHE_HOME') if path: return os.path.join(path, longname) - home = pycompat.osgetenv('HOME') + home = encoding.environ.get('HOME') if home: return os.path.join(home, '.cache', longname) else: diff -r 897726622877 -r 6a70cf94d1b5 mercurial/profiling.py --- a/mercurial/profiling.py Sun Jan 15 16:33:15 2017 +0900 +++ b/mercurial/profiling.py Sun Jan 15 13:17:05 2017 +0530 @@ -12,8 +12,8 @@ from .i18n import _ from . import ( + encoding, error, - pycompat, util, ) @@ -120,7 +120,7 @@ Profiling is active when the context manager is active. When the context manager exits, profiling results will be written to the configured output. """ - profiler = pycompat.osgetenv('HGPROF') + profiler = encoding.environ.get('HGPROF') if profiler is None: profiler = ui.config('profiling', 'type', default='stat') if profiler not in ('ls', 'stat', 'flame'): diff -r 897726622877 -r 6a70cf94d1b5 mercurial/pycompat.py --- a/mercurial/pycompat.py Sun Jan 15 16:33:15 2017 +0900 +++ b/mercurial/pycompat.py Sun Jan 15 13:17:05 2017 +0530 @@ -46,7 +46,6 @@ ospathsep = os.pathsep.encode('ascii') ossep = os.sep.encode('ascii') osaltsep = os.altsep - osgetenv = os.getenvb if osaltsep: osaltsep = osaltsep.encode('ascii') # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which @@ -169,7 +168,6 @@ sysargv = sys.argv sysplatform = sys.platform getcwd = os.getcwd - osgetenv = os.getenv sysexecutable = sys.executable shlexsplit = shlex.split diff -r 897726622877 -r 6a70cf94d1b5 mercurial/url.py --- a/mercurial/url.py Sun Jan 15 16:33:15 2017 +0900 +++ b/mercurial/url.py Sun Jan 15 13:17:05 2017 +0530 @@ -15,10 +15,10 @@ from .i18n import _ from . import ( + encoding, error, httpconnection as httpconnectionmod, keepalive, - pycompat, sslutil, util, ) @@ -81,7 +81,7 @@ class proxyhandler(urlreq.proxyhandler): def __init__(self, ui): proxyurl = (ui.config("http_proxy", "host") or - pycompat.osgetenv('http_proxy')) + encoding.environ.get('http_proxy')) # XXX proxyauthinfo = None if proxyurl: @@ -99,7 +99,7 @@ no_list.extend([p.lower() for p in ui.configlist("http_proxy", "no")]) no_list.extend([p.strip().lower() for - p in pycompat.osgetenv("no_proxy", '').split(',') + p in encoding.environ.get("no_proxy", '').split(',') if p.strip()]) # "http_proxy.always" config is for running tests on localhost if ui.configbool("http_proxy", "always"):