annotate tests/test-config-env.py @ 44261:04a3ae7aba14

chg: force-set LC_CTYPE on server start to actual value from the environment Python 3.7+ will "coerce" the LC_CTYPE variable in many instances, and this can cause issues with chg being able to start up. D7550 attempted to fix this, but a combination of a misreading of the way that python3.7 does the coercion and an untested state (LC_CTYPE being set to an invalid value) meant that this was still not quite working. This change will cause differences between chg and hg: hg will have the LC_CTYPE environment variable coerced, while chg will not. This is unlikely to cause any detectable behavior differences in what Mercurial itself outputs, but it does have two known effects: - When using hg, the coerced LC_CTYPE will be passed to subprocesses, even non-python ones. Using chg will remove the coercion, and this will not happen. This is arguably more correct behavior on chg's part. - On macOS, if you set your region to Brazil but your language to English, this isn't representable in locale strings, so macOS sets LC_CTYPE=UTF-8. If this value is passed along when ssh'ing to a non-macOS machine, some functions (such as locale.setlocale()) may raise an exception due to an unsupported locale setting. This is most easily encountered when doing an interactive commit/split/etc. when using ui.interface=curses. Differential Revision: https://phab.mercurial-scm.org/D8039
author Kyle Lippincott <spectral@google.com>
date Wed, 29 Jan 2020 13:39:50 -0800
parents 2d4cad94d08a
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
1 # Test the config layer generated by environment variables
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
2
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
3 from __future__ import absolute_import, print_function
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
4
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
5 import os
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
6
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
7 from mercurial import (
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
8 encoding,
43872
527eba3013ea tests: make test-config-env.py a little less hacky
Martin von Zweigbergk <martinvonz@google.com>
parents: 43076
diff changeset
9 extensions,
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
10 rcutil,
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
11 ui as uimod,
31857
08fbc97d1364 tests: print Unix style paths in *.py tests
Matt Harbison <matt_harbison@yahoo.com>
parents: 31685
diff changeset
12 util,
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
13 )
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
14
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
15 from mercurial.utils import procutil
37119
d4a2e0d5d042 procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36730
diff changeset
16
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
17 testtmp = encoding.environ[b'TESTTMP']
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
18
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
19 # prepare hgrc files
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
20 def join(name):
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
21 return os.path.join(testtmp, name)
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
22
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
23
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
24 with open(join(b'sysrc'), 'wb') as f:
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
25 f.write(b'[ui]\neditor=e0\n[pager]\npager=p0\n')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
26
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
27 with open(join(b'userrc'), 'wb') as f:
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
28 f.write(b'[ui]\neditor=e1')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
29
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
30 # replace rcpath functions so they point to the files above
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
31 def systemrcpath():
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
32 return [join(b'sysrc')]
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
33
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
34
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
35 def userrcpath():
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
36 return [join(b'userrc')]
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
37
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
38
44031
1864efbe90d9 ui: add the ability to apply `defaultrc` configs from resources
Matt Harbison <matt_harbison@yahoo.com>
parents: 43872
diff changeset
39 extensions.wrapfunction(rcutil, 'default_rc_resources', lambda orig: [])
43872
527eba3013ea tests: make test-config-env.py a little less hacky
Martin von Zweigbergk <martinvonz@google.com>
parents: 43076
diff changeset
40
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
41 rcutil.systemrcpath = systemrcpath
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
42 rcutil.userrcpath = userrcpath
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
43
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
44 # utility to print configs
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
45 def printconfigs(env):
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
46 encoding.environ = env
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
47 rcutil._rccomponents = None # reset cache
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
48 ui = uimod.ui.load()
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
49 for section, name, value in ui.walkconfig():
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
50 source = ui.configsource(section, name)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
51 procutil.stdout.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
52 b'%s.%s=%s # %s\n' % (section, name, value, util.pconvert(source))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
53 )
37119
d4a2e0d5d042 procutil: bulk-replace util.std* to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36730
diff changeset
54 procutil.stdout.write(b'\n')
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
55
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37119
diff changeset
56
31685
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
57 # environment variable overrides
d83e51654c8a rcutil: let environ override system configs (BC)
Jun Wu <quark@fb.com>
parents:
diff changeset
58 printconfigs({})
36730
a22915edc279 py3: byte-stringify test-config.t and test-config-env.py
Yuya Nishihara <yuya@tcha.org>
parents: 31857
diff changeset
59 printconfigs({b'EDITOR': b'e2', b'PAGER': b'p2'})