Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 44030:5ac0e6f19eb4
ui: refactor `readconfig()` into a form that can consume resources
The old form can't completely go away, because files outside of packages still
need to be read. The name passed in here is a tuple of `package name, resource`
as needed by the resource API.
I like the idea of stating the config file is embedded in the executable by
listing is as `exe!package.resource`. This would be consistent with how
`debuginstall` points to the executable for the python executable, lib, and
installed modules. While in practice the filesystem path is available from the
backing ResourceReader when the resource is opened, it is a relative path on py2
and absolute on py3. Further, while this would show in the `hg config` output
for each option if set as such here, it doesn't show in the `reading from...`
line when `--debug` is used. The file isn't actually open where that prints, so
there's no way I see to get that info there. So I opted for the simple prefix
to distinguish resources from files.
Differential Revision: https://phab.mercurial-scm.org/D7775
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 29 Dec 2019 20:51:44 -0500 |
parents | 6d3b67a837a6 |
children | 1864efbe90d9 |
comparison
equal
deleted
inserted
replaced
44029:bba9149adc14 | 44030:5ac0e6f19eb4 |
---|---|
43 util, | 43 util, |
44 ) | 44 ) |
45 from .utils import ( | 45 from .utils import ( |
46 dateutil, | 46 dateutil, |
47 procutil, | 47 procutil, |
48 resourceutil, | |
48 stringutil, | 49 stringutil, |
49 ) | 50 ) |
50 | 51 |
51 urlreq = util.urlreq | 52 urlreq = util.urlreq |
52 | 53 |
422 ) | 423 ) |
423 % (f, user, group) | 424 % (f, user, group) |
424 ) | 425 ) |
425 return False | 426 return False |
426 | 427 |
428 def read_resource_config( | |
429 self, name, root=None, trust=False, sections=None, remap=None | |
430 ): | |
431 try: | |
432 fp = resourceutil.open_resource(name[0], name[1]) | |
433 except IOError: | |
434 if not sections: # ignore unless we were looking for something | |
435 return | |
436 raise | |
437 | |
438 self._readconfig( | |
439 b'resource:%s.%s' % name, fp, root, trust, sections, remap | |
440 ) | |
441 | |
427 def readconfig( | 442 def readconfig( |
428 self, filename, root=None, trust=False, sections=None, remap=None | 443 self, filename, root=None, trust=False, sections=None, remap=None |
429 ): | 444 ): |
430 try: | 445 try: |
431 fp = open(filename, 'rb') | 446 fp = open(filename, 'rb') |
432 except IOError: | 447 except IOError: |
433 if not sections: # ignore unless we were looking for something | 448 if not sections: # ignore unless we were looking for something |
434 return | 449 return |
435 raise | 450 raise |
436 | 451 |
452 self._readconfig(filename, fp, root, trust, sections, remap) | |
453 | |
454 def _readconfig( | |
455 self, filename, fp, root=None, trust=False, sections=None, remap=None | |
456 ): | |
437 with fp: | 457 with fp: |
438 cfg = config.config() | 458 cfg = config.config() |
439 trusted = sections or trust or self._trusted(fp, filename) | 459 trusted = sections or trust or self._trusted(fp, filename) |
440 | 460 |
441 try: | 461 try: |