Patchwork [V2] extensions: add notloaded method to return extensions failed to load

login
register
mail settings
Submitter Jun Wu
Date Feb. 15, 2016, 3:45 p.m.
Message ID <f618a6ad59097fcb3e69.1455551116@x1c>
Download mbox | patch
Permalink /patch/13213/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Feb. 15, 2016, 3:45 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1455123574 0
#      Wed Feb 10 16:59:34 2016 +0000
# Node ID f618a6ad59097fcb3e696e6e06fbf88915ba0e31
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
extensions: add notloaded method to return extensions failed to load

Before this patch, there is no easy way to detect if there are extensions
failed to load. While this is okay for most situations, chgserver is designed
to preload all extensions specified in config and does need the information.
This patch adds extensions.notloaded() to return names of extensions failed
to load.
Yuya Nishihara - Feb. 16, 2016, 2:43 p.m.
On Mon, 15 Feb 2016 15:45:16 +0000, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1455123574 0
> #      Wed Feb 10 16:59:34 2016 +0000
> # Node ID f618a6ad59097fcb3e696e6e06fbf88915ba0e31
> # Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
> extensions: add notloaded method to return extensions failed to load
> 
> Before this patch, there is no easy way to detect if there are extensions
> failed to load. While this is okay for most situations, chgserver is designed
> to preload all extensions specified in config and does need the information.
> This patch adds extensions.notloaded() to return names of extensions failed
> to load.
> 
> diff --git a/mercurial/extensions.py b/mercurial/extensions.py
> --- a/mercurial/extensions.py
> +++ b/mercurial/extensions.py
> @@ -456,6 +456,10 @@
>  
>      return exts
>  
> +def notloaded():
> +    '''return short names of extensions that failed to load'''
> +    return [name for name, mod in _extensions.items() if mod is None]

LGTM. I'll change it to .iteritems() and push to the clowncopter, thanks.
Jun Wu - Feb. 16, 2016, 3:48 p.m.
On 02/16/2016 02:43 PM, Yuya Nishihara wrote:
> LGTM. I'll change it to .iteritems() and push to the clowncopter,
> thanks.

OpenStack also faces Python 2 to 3 issue like us. They have a style
guide at https://wiki.openstack.org/wiki/Python3 (which recommends items
over iteritems). I wonder if we want a similar style guide to make
Python 3 transition easier.
Yuya Nishihara - Feb. 16, 2016, 4:26 p.m.
On Tue, 16 Feb 2016 15:48:56 +0000, Jun Wu wrote:
> On 02/16/2016 02:43 PM, Yuya Nishihara wrote:
> > LGTM. I'll change it to .iteritems() and push to the clowncopter,
> > thanks.
> 
> OpenStack also faces Python 2 to 3 issue like us. They have a style
> guide at https://wiki.openstack.org/wiki/Python3 (which recommends items
> over iteritems). I wonder if we want a similar style guide to make
> Python 3 transition easier.

We have lots of .iteritems(). I don't know if we can rewrite all of them,
so it doesn't make sense to switch to .items() right now.

But I agree we'll need something for Py3k support.
Martijn Pieters - Feb. 17, 2016, 9:51 a.m.
On Tue, Feb 16, 2016 at 3:48 PM, Jun Wu <quark@fb.com> wrote:
> OpenStack also faces Python 2 to 3 issue like us. They have a style
> guide at https://wiki.openstack.org/wiki/Python3 (which recommends items
> over iteritems). I wonder if we want a similar style guide to make
> Python 3 transition easier.


The alternative is to add the `six` library or a similar compatibility
layer, and use a helper function. See
https://bitbucket.org/gutworth/six/src/3deee854df8a5f1cc04dd721c18dee2128584f8c/six.py?fileviewer=file-view-default#six.py-573
for the six implementation.
Augie Fackler - Feb. 22, 2016, 11 p.m.
On Wed, Feb 17, 2016 at 01:26:24AM +0900, Yuya Nishihara wrote:
> On Tue, 16 Feb 2016 15:48:56 +0000, Jun Wu wrote:
> > On 02/16/2016 02:43 PM, Yuya Nishihara wrote:
> > > LGTM. I'll change it to .iteritems() and push to the clowncopter,
> > > thanks.
> >
> > OpenStack also faces Python 2 to 3 issue like us. They have a style
> > guide at https://wiki.openstack.org/wiki/Python3 (which recommends items
> > over iteritems). I wonder if we want a similar style guide to make
> > Python 3 transition easier.
>
> We have lots of .iteritems(). I don't know if we can rewrite all of them,
> so it doesn't make sense to switch to .items() right now.
>
> But I agree we'll need something for Py3k support.

I suspect the best option is a 2to3 rule for that. We probably don't
want the RAM overhead of the copy that .items() implies on 2.6 and
2.7.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Gregory Szorc - Feb. 28, 2016, 5:49 a.m.
On Mon, Feb 22, 2016 at 3:00 PM, Augie Fackler <raf@durin42.com> wrote:

> On Wed, Feb 17, 2016 at 01:26:24AM +0900, Yuya Nishihara wrote:
> > On Tue, 16 Feb 2016 15:48:56 +0000, Jun Wu wrote:
> > > On 02/16/2016 02:43 PM, Yuya Nishihara wrote:
> > > > LGTM. I'll change it to .iteritems() and push to the clowncopter,
> > > > thanks.
> > >
> > > OpenStack also faces Python 2 to 3 issue like us. They have a style
> > > guide at https://wiki.openstack.org/wiki/Python3 (which recommends
> items
> > > over iteritems). I wonder if we want a similar style guide to make
> > > Python 3 transition easier.
> >
> > We have lots of .iteritems(). I don't know if we can rewrite all of them,
> > so it doesn't make sense to switch to .items() right now.
> >
> > But I agree we'll need something for Py3k support.
>
> I suspect the best option is a 2to3 rule for that. We probably don't
> want the RAM overhead of the copy that .items() implies on 2.6 and
> 2.7.


You can alias dict.items and dict.iteritems to a local symbol and then call
it with the instance of the dict you are iterating over. e.g.

if sys.version_info[0] == 2:
    iteritems = dict.iteritems
else:
    iteritems = dict.items
...
for k, v in iteritems(d):

We will likely want to throw such helper symbols in py3kcompat.py or
util.py.

BTW, I just sent a series that kills 2to3. I'm very adamant that we run all
the Pythons from the same code install without source transformation. See
previous work around the module importer that allows pure and non-pure
running from the same install.

Patch

diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -456,6 +456,10 @@ 
 
     return exts
 
+def notloaded():
+    '''return short names of extensions that failed to load'''
+    return [name for name, mod in _extensions.items() if mod is None]
+
 def moduleversion(module):
     '''return version information from given module as a string'''
     if (util.safehasattr(module, 'getversion')
diff --git a/tests/test-bad-extension.t b/tests/test-bad-extension.t
--- a/tests/test-bad-extension.t
+++ b/tests/test-bad-extension.t
@@ -38,3 +38,16 @@ 
   *** failed to import extension badext2: No module named badext2
   Traceback (most recent call last):
   ImportError: No module named badext2
+
+names of extensions failed to load can be accessed via extensions.notloaded()
+
+  $ cat <<EOF > showbadexts.py
+  > from mercurial import cmdutil, commands, extensions
+  > cmdtable = {}
+  > command = cmdutil.command(cmdtable)
+  > @command('showbadexts', norepo=True)
+  > def showbadexts(ui, *pats, **opts):
+  >     ui.write('BADEXTS: %s' % ' '.join(sorted(extensions.notloaded())))
+  > EOF
+  $ hg --config extensions.badexts=showbadexts.py showbadexts 2>&1 | grep ^BADEXTS
+  BADEXTS: badext badext2