comparison mercurial/rcutil.py @ 43075:57875cf423c9

style: run a patched black on a subset of mercurial This applied black to the 20 smallest files in mercurial/: ls -S1 mercurial/*.py | tail -n20 | xargs black --skip-string-normalization Note that a few files failed to format, presumably due to a bug in my patch. The intent is to be able to compare results to D5064 with https://github.com/python/black/pull/826 applied to black. I skipped string normalization on this patch for clarity - in reality I think we'd want one pass without string normalization, followed by another to normalize strings (which is basically replacing ' with " globally.) # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6342
author Augie Fackler <augie@google.com>
date Sat, 05 Oct 2019 10:29:34 -0400
parents edbcf5b239f9
children 687b865b95ad
comparison
equal deleted inserted replaced
43074:9cc55b743713 43075:57875cf423c9
22 22
23 fallbackpager = scmplatform.fallbackpager 23 fallbackpager = scmplatform.fallbackpager
24 systemrcpath = scmplatform.systemrcpath 24 systemrcpath = scmplatform.systemrcpath
25 userrcpath = scmplatform.userrcpath 25 userrcpath = scmplatform.userrcpath
26 26
27
27 def _expandrcpath(path): 28 def _expandrcpath(path):
28 '''path could be a file or a directory. return a list of file paths''' 29 '''path could be a file or a directory. return a list of file paths'''
29 p = util.expandpath(path) 30 p = util.expandpath(path)
30 if os.path.isdir(p): 31 if os.path.isdir(p):
31 join = os.path.join 32 join = os.path.join
32 return sorted(join(p, f) for f, k in util.listdir(p) 33 return sorted(
33 if f.endswith('.rc')) 34 join(p, f) for f, k in util.listdir(p) if f.endswith('.rc')
35 )
34 return [p] 36 return [p]
37
35 38
36 def envrcitems(env=None): 39 def envrcitems(env=None):
37 '''Return [(section, name, value, source)] config items. 40 '''Return [(section, name, value, source)] config items.
38 41
39 The config items are extracted from environment variables specified by env, 42 The config items are extracted from environment variables specified by env,
53 if envname not in env: 56 if envname not in env:
54 continue 57 continue
55 result.append((section, configname, env[envname], '$%s' % envname)) 58 result.append((section, configname, env[envname], '$%s' % envname))
56 return result 59 return result
57 60
61
58 def defaultrcpath(): 62 def defaultrcpath():
59 '''return rc paths in default.d''' 63 '''return rc paths in default.d'''
60 path = [] 64 path = []
61 defaultpath = os.path.join(util.datapath, 'default.d') 65 defaultpath = os.path.join(util.datapath, 'default.d')
62 if os.path.isdir(defaultpath): 66 if os.path.isdir(defaultpath):
63 path = _expandrcpath(defaultpath) 67 path = _expandrcpath(defaultpath)
64 return path 68 return path
69
65 70
66 def rccomponents(): 71 def rccomponents():
67 '''return an ordered [(type, obj)] about where to load configs. 72 '''return an ordered [(type, obj)] about where to load configs.
68 73
69 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is 74 respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is
90 _rccomponents = normpaths(defaultrcpath() + systemrcpath()) 95 _rccomponents = normpaths(defaultrcpath() + systemrcpath())
91 _rccomponents.append(envrc) 96 _rccomponents.append(envrc)
92 _rccomponents.extend(normpaths(userrcpath())) 97 _rccomponents.extend(normpaths(userrcpath()))
93 return _rccomponents 98 return _rccomponents
94 99
100
95 def defaultpagerenv(): 101 def defaultpagerenv():
96 '''return a dict of default environment variables and their values, 102 '''return a dict of default environment variables and their values,
97 intended to be set before starting a pager. 103 intended to be set before starting a pager.
98 ''' 104 '''
99 return {'LESS': 'FRX', 'LV': '-c'} 105 return {'LESS': 'FRX', 'LV': '-c'}