[PATCH 2 of 2] setup: prevent setuptools from laying an egg

Matt Harbison mharbison72 at gmail.com
Mon May 8 00:39:20 EDT 2017


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1494214143 14400
#      Sun May 07 23:29:03 2017 -0400
# Node ID 707683d56e5cbd3fe3453ddab9a57222b998f2af
# Parent  36d9a659b9d76837faaf73fde3f5c5455231c2f9
setup: prevent setuptools from laying an egg

Previously, test-hghave.t was failing on Windows (and on Linux if
$FORCE_SETUPTOOLS was set) with the following:

  --- c:/Users/Matt/Projects/hg/tests/test-hghave.t
  +++ c:/Users/Matt/Projects/hg/tests/test-hghave.t.err
  @@ -19,7 +19,11 @@
     >   foo
     > EOF
     $ run-tests.py $HGTEST_RUN_TESTS_PURE test-hghaveaddon.t
  +  warning: Testing with unexpected mercurial lib: c:\Users\Matt\Projects\hg\mercurial
  +           (expected ...\hgtests.mu9rou\install\lib\python\mercurial)
     .
  +  warning: Tested with unexpected mercurial lib: c:\Users\Matt\Projects\hg\mercurial
  +           (expected ...\hgtests.mu9rou\install\lib\python\mercurial)

Also, `make install` was creating an *.egg-info in the local Mercurial source
tree, which `make clean` wasn't deleting.

Someone familiar with setuptools should take a close look at this.  I originally
registered a subclass of 'install_egg_info' with an empty run(), which took care
of the egg-info generated by `make install`.  Looking at the output of setup.py
as run by run-tests._installhg(), I saw that 'bdist_egg' was being run.  I
registered a similar empty class for that command, but the egg was still
produced.  But when I registered this 'install' subclass with nothing but a
run() that called the super class run, 'bdist_egg' was no longer being called,
and the test worked.  Subsequently dropping everything except the 'install'
subclass with a minimal delegating run() allowed the test to run (though the
setup log had output from running 'install_egg_info').

To be on the safe side (and to avoid output about eggs when the empty subclasses
would have prevented any egg processing), I added a filter to get_sub_commands()
to filter out the egg related stuff.  Unlike the others, 'bdist_egg' is part of
setuptools, so registering a subclass and still working without setuptools
probably isn't very clean.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -77,6 +77,7 @@
 from distutils.command.build_ext import build_ext
 from distutils.command.build_py import build_py
 from distutils.command.build_scripts import build_scripts
+from distutils.command.install import install
 from distutils.command.install_lib import install_lib
 from distutils.command.install_scripts import install_scripts
 from distutils.spawn import spawn, find_executable
@@ -461,6 +462,12 @@
         dir = os.path.dirname(self.get_ext_fullpath('dummy'))
         return os.path.join(self.build_temp, dir, 'hg.exe')
 
+class hginstall(install):
+    def get_sub_commands(self):
+        # Screen out egg related commands to prevent egg generation
+        excl = set(['install_egg_info', 'bdist_egg'])
+        return filter(lambda x: x not in excl, install.get_sub_commands(self))
+
 class hginstalllib(install_lib):
     '''
     This is a specialization of install_lib that replaces the copy_file used
@@ -572,6 +579,7 @@
             'build_py': hgbuildpy,
             'build_scripts': hgbuildscripts,
             'build_hgextindex': buildhgextindex,
+            'install': hginstall,
             'install_lib': hginstalllib,
             'install_scripts': hginstallscripts,
             'build_hgexe': buildhgexe,


More information about the Mercurial-devel mailing list