Mercurial > public > mercurial-scm > hg
diff mercurial/ui.py @ 30559:d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
This allows us to write doctests depending on a ui object, but not on global
configs.
ui.load() is a class method so we can do wsgiui.load(). All ui() calls but
for doctests are replaced with ui.load(). Some of them could be changed to
not load configs later.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 22 Oct 2016 14:35:10 +0900 |
parents | 4b0e6677eed1 |
children | bcb858396233 |
line wrap: on
line diff
--- a/mercurial/ui.py Wed Nov 30 19:23:04 2016 +0000 +++ b/mercurial/ui.py Sat Oct 22 14:35:10 2016 +0900 @@ -96,6 +96,12 @@ class ui(object): def __init__(self, src=None): + """Create a fresh new ui object if no src given + + Use uimod.ui.load() to create a ui which knows global and user configs. + In most cases, you should use ui.copy() to create a copy of an existing + ui object. + """ # _buffers: used for temporary capture of output self._buffers = [] # 3-tuple describing how each buffer in the stack behaves. @@ -138,12 +144,18 @@ # shared read-only environment self.environ = os.environ - # we always trust global config files - for f in scmutil.rcpath(): - self.readconfig(f, trust=True) self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm() + @classmethod + def load(cls): + """Create a ui and load global and user configs""" + u = cls() + # we always trust global config files + for f in scmutil.rcpath(): + u.readconfig(f, trust=True) + return u + def copy(self): return self.__class__(self)