[PATCH V2] setup: prevent setuptools from laying an egg

Matt Harbison mharbison72 at gmail.com
Mon May 29 02:32:28 UTC 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 b81e017073fbb68a878610377484c5d4d32f683c
# Parent  7422587f7788842413ebb2e6617749ed64895071
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)

Augie relayed concerns[1] about the first attempt at this, which also excluded
'install_egg_info'.  All that needs to be excluded to avoid the egg and make the
test work is to filter out 'bdist_egg'.  (Actually, the body of this class could
simply be 'pass', and 'bdist_egg' still isn't run.  But that seems to magical.)

Also note that prior to this (and still now), `make clean` doesn't delete the
'mercurial.egg-info' that is generated by `make install`.

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-May/097668.html

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
@@ -464,6 +465,14 @@
         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.  But allow
+        # mercurial.egg-info generation, since that is part of modern
+        # packaging.
+        excl = {'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
@@ -575,6 +584,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