extensions: also search for extension in the 'hgext3rd' package

Mercurial extensions are not meant to be normal python package/module. Yet the
lack of an official location to install them means that a lot of them actually
install as root level python package, polluting the global Python package
namespace and risking collision with more legit packages. As we recently
discovered, core python actually support namespace package. A way for multiples
distinct "distribution" to share a common top level package without fear of
installation headache. (Namespace package allow submodule installed in different
location (of the 'sys.path') to be imported properly. So we are fine as long as
extension includes a proper 'hgext3rd.__init__.py' to declare the namespace
package.)

Therefore we introduce a 'hgext3rd' namespace packages and search for extension
in it. We'll then recommend third extensions to install themselves in it.
Strictly speaking we could just get third party extensions to install in 'hgext'
as it is also a namespace package. However, this would make the integration of
formerly third party extensions in the main distribution more complicated as the third
party install would overwrite the file from the main install. Moreover, having an
explicit split between third party and core extensions seems like a good idea.

The name 'hgext3rd' have been picked because it is short and seems explicit enough.
Other alternative I could think of where:

- hgextcontrib
- hgextother
- hgextunofficial
This commit is contained in:
Pierre-Yves David 2016-03-11 10:30:08 +00:00
parent 1d2fb0ab99
commit 5d3d0e1d77
4 changed files with 13 additions and 2 deletions

4
hgext3rd/__init__.py Normal file
View File

@ -0,0 +1,4 @@
# name space package to host third party extensions
from __future__ import absolute_import
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)

View File

@ -105,7 +105,11 @@ def load(ui, name, path):
mod = _importh("hgext.%s" % name)
except ImportError as err:
_reportimporterror(ui, err, "hgext.%s" % name, name)
mod = _importh(name)
try:
mod = _importh("hgext3rd.%s" % name)
except ImportError as err:
_reportimporterror(ui, err, "hgext3rd.%s" % name, name)
mod = _importh(name)
# Before we do anything with the extension, check against minimum stated
# compatibility. This gives extension authors a mechanism to have their

View File

@ -506,7 +506,7 @@ cmdclass = {'build': hgbuild,
packages = ['mercurial', 'mercurial.hgweb', 'mercurial.httpclient',
'mercurial.pure',
'hgext', 'hgext.convert', 'hgext.highlight', 'hgext.zeroconf',
'hgext.largefiles']
'hgext.largefiles', 'hgext3rd']
common_depends = ['mercurial/util.h']

View File

@ -56,6 +56,9 @@ show traceback for ImportError of hgext.name if debug is set
could not import hgext.badext2 (No module named *badext2): trying badext2 (glob)
Traceback (most recent call last):
ImportError: No module named *badext2 (glob)
could not import hgext3rd.badext2 (No module named badext2): trying badext2
Traceback (most recent call last):
ImportError: No module named badext2
*** failed to import extension badext2: No module named badext2
Traceback (most recent call last):
ImportError: No module named badext2