D6189: py2exe: add workaround to allow bundling of hgext3rd.* extensions
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Wed Apr 3 11:53:07 EDT 2019
durin42 created this revision.
durin42 added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
py2exe doesn't know how to handle namespace packages *at all*, so it treats
them like normal packages. As a result, if we try and bundle hgext3rd.evolve
in a py2exe build, it won't work if we install evolve into the virtualenv. In
order to work around this, tortoisehg installs hgext3rd.evolve etc into its
staged hg directory, since it doesn't use a virtualenv. As a workaround for us,
we'll just allow any extra packages users want bundled are part of hg during
the pseudo-install phase that py2exe uses. I'm not happy about this, but it
As a sample of how you'd make an MSI with evolve bundled:
"""Stage evolve for inclusion in py2exe binary."""
with tempfile.TemporaryDirectory() as temp:
evolve = os.path.join(temp, "evolve")
dest = os.path.join('..', 'hgext3rd', 'evolve')
shutil.copytree(os.path.join(evolve, "hgext3rd", "evolve"), dest)
if __name__ == "__main__":
is a script you can pass to the wix/build.py as --extra-packages-script,
and the resulting .msi will have an hg binary with evolve baked in. users
will still need to enable evolve in their hgrc, so you'd probably also
want to bundle configs in your msi for an enterprise environment, but that's
already easy to do with the support for extra features and wxs files in the
wix build process.
diff --git a/setup.py b/setup.py
@@ -975,6 +975,12 @@
+if 'HG_PY2EXE_EXTRA_INSTALL_PACKAGES' in os.environ:
+ # py2exe can't cope with namespace packages very well, so we have to
+ # install any hgext3rd.* extensions that we want in the final py2exe
+ # image here. This is gross, but you gotta do what you gotta do.
+ packages.extend(os.environ['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'].split(' '))
common_depends = ['mercurial/bitmanipulation.h',
diff --git a/contrib/packaging/hgpackaging/py2exe.py b/contrib/packaging/hgpackaging/py2exe.py
@@ -118,6 +118,10 @@
env['HG_PY2EXE_EXTRA_PACKAGES'] = ' '.join(sorted(extra_packages))
+ hgext3rd_extras = sorted(
+ e for e in extra_packages if e.startswith('hgext3rd.'))
+ if hgext3rd_extras:
+ env['HG_PY2EXE_EXTRA_INSTALL_PACKAGES'] = ' '.join(hgext3rd_extras)
env['HG_PY2EXE_EXTRA_EXCLUDES'] = ' '.join(sorted(extra_excludes))
To: durin42, indygreg, #hg-reviewers
More information about the Mercurial-devel