Patchwork [4,of,8] extensions: deprecate extsetup without a `ui` argument (API)

login
register
mail settings
Submitter Matt Harbison
Date Dec. 28, 2018, 6:47 a.m.
Message ID <2b04921466a9ff3428ac.1545979638@Envy>
Download mbox | patch
Permalink /patch/37373/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 28, 2018, 6:47 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1545965163 18000
#      Thu Dec 27 21:46:03 2018 -0500
# Node ID 2b04921466a9ff3428ac83a0ae9da35ee2d75dd5
# Parent  60d298e4ddb59bee804766c9fd95a552bfd8d56a
extensions: deprecate extsetup without a `ui` argument (API)

9.5 years should be enough time, but there were some tests for the old style
still (which are now updated).  Exthelper doesn't fallback to the old API, so
this is for consistency.

.. api::

   The extension hook ``extsetup`` without a `ui` argument has been deprecated,
   and will be removed in the next version.  Add a `ui` argument to avoid the
   deprecation warning.

Patch

diff --git a/hgext/highlight/__init__.py b/hgext/highlight/__init__.py
--- a/hgext/highlight/__init__.py
+++ b/hgext/highlight/__init__.py
@@ -87,7 +87,7 @@  def generate_css(web):
     ]))
     return web.res.sendresponse()
 
-def extsetup():
+def extsetup(ui):
     # monkeypatch in the new version
     extensions.wrapfunction(webcommands, '_filerevision',
                             filerevision_highlight)
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -226,6 +226,8 @@  def _runextsetup(name, ui):
             except TypeError:
                 if pycompat.getargspec(extsetup).args:
                     raise
+                ui.deprecwarn("extsetup for '%s' must take a ui argument"
+                              % name, "4.9")
                 extsetup() # old extsetup with no ui argument
         except Exception as inst:
             ui.traceback(force=True)
diff --git a/tests/notcapable b/tests/notcapable
--- a/tests/notcapable
+++ b/tests/notcapable
@@ -7,7 +7,7 @@  fi
 
 cat > notcapable-$CAP.py << EOF
 from mercurial import extensions, localrepo, repository
-def extsetup():
+def extsetup(ui):
     extensions.wrapfunction(repository.peer, 'capable', wrapcapable)
     extensions.wrapfunction(localrepo.localrepository, 'peer', wrappeer)
 def wrapcapable(orig, self, name, *args, **kwargs):
diff --git a/tests/test-dirstate-race.t b/tests/test-dirstate-race.t
--- a/tests/test-dirstate-race.t
+++ b/tests/test-dirstate-race.t
@@ -53,7 +53,7 @@  confused with a file with the exec bit s
   >     context,
   >     extensions,
   > )
-  > def extsetup():
+  > def extsetup(ui):
   >     extensions.wrapfunction(context.workingctx, '_checklookup', overridechecklookup)
   > def overridechecklookup(orig, self, files):
   >     # make an update that changes the dirstate from underneath
diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -279,7 +279,7 @@  limit mark, regardless of importing modu
   > NO_CHECK_EOF
   $ cat > loadabs.py <<NO_CHECK_EOF
   > import mod.ambigabs as ambigabs
-  > def extsetup():
+  > def extsetup(ui):
   >     print('ambigabs.s=%s' % ambigabs.s, flush=True)
   > NO_CHECK_EOF
   $ "$PYTHON" $TESTTMP/unflush.py loadabs.py
@@ -295,7 +295,7 @@  limit mark, regardless of importing modu
   > NO_CHECK_EOF
   $ cat > loadrel.py <<NO_CHECK_EOF
   > import mod.ambigrel as ambigrel
-  > def extsetup():
+  > def extsetup(ui):
   >     print('ambigrel.s=%s' % ambigrel.s, flush=True)
   > NO_CHECK_EOF
   $ "$PYTHON" $TESTTMP/unflush.py loadrel.py
diff --git a/tests/test-http-bundle1.t b/tests/test-http-bundle1.t
--- a/tests/test-http-bundle1.t
+++ b/tests/test-http-bundle1.t
@@ -186,7 +186,7 @@  test http authentication
   >     if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user',
   >                                                             b'pass']:
   >         raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
-  > def extsetup():
+  > def extsetup(ui):
   >     common.permhooks.insert(0, perform_authentication)
   > EOT
   $ hg serve --config extensions.x=userpass.py -p $HGPORT2 -d --pid-file=pid \
diff --git a/tests/test-http.t b/tests/test-http.t
--- a/tests/test-http.t
+++ b/tests/test-http.t
@@ -181,7 +181,7 @@  test http authentication
   >                 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')])
   >     if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']:
   >         raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
-  > def extsetup():
+  > def extsetup(ui):
   >     common.permhooks.insert(0, perform_authentication)
   > EOT
   $ hg serve --config extensions.x=userpass.py -p $HGPORT2 -d --pid-file=pid \
@@ -526,7 +526,7 @@  We raise HTTP 500 because its message is
   >     if not cookie:
   >         raise common.ErrorResponse(common.HTTP_SERVER_ERROR, b'no-cookie')
   >     raise common.ErrorResponse(common.HTTP_SERVER_ERROR, b'Cookie: %s' % cookie)
-  > def extsetup():
+  > def extsetup(ui):
   >     common.permhooks.insert(0, perform_authentication)
   > EOF
 
diff --git a/tests/test-largefiles-wireproto.t b/tests/test-largefiles-wireproto.t
--- a/tests/test-largefiles-wireproto.t
+++ b/tests/test-largefiles-wireproto.t
@@ -430,7 +430,7 @@  a large file from the server rather than
   >                 [(b'WWW-Authenticate', b'Basic Realm="mercurial"')])
   >     if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user', b'pass']:
   >         raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
-  > def extsetup():
+  > def extsetup(ui):
   >     common.permhooks.insert(0, perform_authentication)
   > EOT
   $ hg serve --config extensions.x=userpass.py -R credentialmain \
diff --git a/tests/test-lfs-serve-access.t b/tests/test-lfs-serve-access.t
--- a/tests/test-lfs-serve-access.t
+++ b/tests/test-lfs-serve-access.t
@@ -404,7 +404,7 @@  the GET/PUT request.
   >     if base64.b64decode(auth.split()[1]).split(b':', 1) != [b'user',
   >                                                             b'pass']:
   >         raise common.ErrorResponse(common.HTTP_FORBIDDEN, b'no')
-  > def extsetup():
+  > def extsetup(ui):
   >     common.permhooks.insert(0, perform_authentication)
   > EOF