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

login
register
mail settings
Submitter Matt Harbison
Date May 29, 2017, 2:32 a.m.
Message ID <b81e017073fbb68a8786.1496025148@Envy>
Download mbox | patch
Permalink /patch/21029/
State Accepted
Headers show

Comments

Matt Harbison - May 29, 2017, 2:32 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@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
Yuya Nishihara - June 3, 2017, 3:25 a.m.
On Sun, 28 May 2017 22:32:28 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@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

Looks good per the previous discussion, queued, thanks.
Augie Fackler - June 3, 2017, 4:50 a.m.
On Sat, Jun 03, 2017 at 12:25:31PM +0900, Yuya Nishihara wrote:
> On Sun, 28 May 2017 22:32:28 -0400, Matt Harbison wrote:
> > # HG changeset patch
> > # User Matt Harbison <matt_harbison@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
>
> Looks good per the previous discussion, queued, thanks.

I also ran this by the pip maintainer and he said it looked like it'd
probably be okay. Just forgot to follow up here. :)

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Boris Feld - June 6, 2017, 1:29 p.m.
Following this patch, it seems that mercurial default is no longer pip-
installable.

I first saw the issue when playing with https://hg.logilab.org/review/h
gperf where I can see this crash when testing the default branch:

https://bpaste.net/show/e792a21fc6fb

I can also reproduce the crash when trying to pip install mercurial
directly:

https://bpaste.net/show/a11615d5429c

Commenting the following line in setup.py:

'install': hginstall,

is sufficient to make it working.

I'm not exactly sure why we have this crash, maybe the command we
blacklisted was used to detect the version of setuptools and pip think
setuptools is older and supports this version.

Here are my versions:

pip             9.0.1
setuptools      36.0.1 

I have tried to install mercurial both from inside a virtualenv and
outside, I have the same error.

On Sat, 2017-06-03 at 00:50 -0400, Augie Fackler wrote:
> On Sat, Jun 03, 2017 at 12:25:31PM +0900, Yuya Nishihara wrote:
> > On Sun, 28 May 2017 22:32:28 -0400, Matt Harbison wrote:
> > > # HG changeset patch
> > > # User Matt Harbison <matt_harbison@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
> > 
> > Looks good per the previous discussion, queued, thanks.
> 
> I also ran this by the pip maintainer and he said it looked like it'd
> probably be okay. Just forgot to follow up here. :)
> 
> > _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel@mercurial-scm.org
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

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,