comparison tests/test-extension.t @ 33052:45b0e9d05ee9

extensions: register functions always at loading extension (issue5601) Before this patch, functions defined in extensions are registered via extra loaders only in _dispatch(). Therefore, loading extensions in other code paths like below omits registration of functions. - WSGI service - operation across repositories (e.g. subrepo) - test-duplicateoptions.py, using extensions.loadall() directly To register functions always at loading new extension, this patch moves implementation for extra loading from dispatch._dispatch() to extensions.loadall(). AFAIK, only commands module causes cyclic dependency between extensions module, but this patch imports all related modules just before extra loading in loadall(), in order to centralize them. This patch makes extensions.py depend on many other modules, even though extensions.py itself doesn't. It should be avoided if possible, but I don't have any better idea. Some other places like below aren't reasonable for extra loading, IMHO. - specific function in newly added module: existing callers of extensions.loadall() should invoke it, too - hg.repository() or so: no-repo commands aren't covered by this. BTW, this patch removes _loaded.add(name) on relocation, because dispatch._loaded is used only for extraloaders (for similar reason, "exts" variable is removed, too).
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sat, 24 Jun 2017 02:39:20 +0900
parents b6776b34e44e
children fce4ed2912bb
comparison
equal deleted inserted replaced
33051:15a79ac823e8 33052:45b0e9d05ee9
75 > print "2) %s uisetup" % name 75 > print "2) %s uisetup" % name
76 > def extsetup(): 76 > def extsetup():
77 > print "3) %s extsetup" % name 77 > print "3) %s extsetup" % name
78 > def reposetup(ui, repo): 78 > def reposetup(ui, repo):
79 > print "4) %s reposetup" % name 79 > print "4) %s reposetup" % name
80 >
81 > # custom predicate to check registration of functions at loading
82 > from mercurial import (
83 > registrar,
84 > smartset,
85 > )
86 > revsetpredicate = registrar.revsetpredicate()
87 > @revsetpredicate(name, safe=True) # safe=True for query via hgweb
88 > def custompredicate(repo, subset, x):
89 > return smartset.baseset([r for r in subset if r in {0}])
80 > EOF 90 > EOF
81 91
82 $ cp foo.py bar.py 92 $ cp foo.py bar.py
83 $ echo 'foo = foo.py' >> $HGRCPATH 93 $ echo 'foo = foo.py' >> $HGRCPATH
84 $ echo 'bar = bar.py' >> $HGRCPATH 94 $ echo 'bar = bar.py' >> $HGRCPATH
85 95
86 Command with no output, we just want to see the extensions loaded: 96 Check normal command's load order of extensions and registration of functions
87 97
88 $ hg paths 98 $ hg log -r "foo() and bar()" -q
89 1) foo imported 99 1) foo imported
90 1) bar imported 100 1) bar imported
91 2) foo uisetup 101 2) foo uisetup
92 2) bar uisetup 102 2) bar uisetup
93 3) foo extsetup 103 3) foo extsetup
94 3) bar extsetup 104 3) bar extsetup
95 4) foo reposetup 105 4) foo reposetup
96 4) bar reposetup 106 4) bar reposetup
97 107 0:c24b9ac61126
98 Check hgweb's load order: 108
109 Check hgweb's load order of extensions and registration of functions
99 110
100 $ cat > hgweb.cgi <<EOF 111 $ cat > hgweb.cgi <<EOF
101 > #!$PYTHON 112 > #!$PYTHON
102 > from mercurial import demandimport; demandimport.enable() 113 > from mercurial import demandimport; demandimport.enable()
103 > from mercurial.hgweb import hgweb 114 > from mercurial.hgweb import hgweb
115 2) bar uisetup 126 2) bar uisetup
116 3) foo extsetup 127 3) foo extsetup
117 3) bar extsetup 128 3) bar extsetup
118 4) foo reposetup 129 4) foo reposetup
119 4) bar reposetup 130 4) bar reposetup
131
132 (check that revset predicate foo() and bar() are available)
133
134 $ REQUEST_METHOD='GET' PATH_INFO='/shortlog' SCRIPT_NAME='' \
135 > QUERY_STRING='rev=foo() and bar()' \
136 > SERVER_PORT='80' SERVER_NAME='localhost' python hgweb.cgi \
137 > | grep '<a href="/rev/[0-9a-z]*">'
138 <a href="/rev/c24b9ac61126">add file</a>
120 139
121 $ echo 'foo = !' >> $HGRCPATH 140 $ echo 'foo = !' >> $HGRCPATH
122 $ echo 'bar = !' >> $HGRCPATH 141 $ echo 'bar = !' >> $HGRCPATH
123 142
124 Check "from __future__ import absolute_import" support for external libraries 143 Check "from __future__ import absolute_import" support for external libraries