When invoking setup.py directly, the default behavior for 'install' is
to run the bdist_egg installation hook, which is ... actually deprecated
by setuptools. It doesn't seem to work quite right anymore.
By contrast, 'pip install' will invoke the bdist_wheel hook
instead. This leads to differences in behavior for the two approaches. I
advocate using pip in the documentation in this directory, but the
'setup.py' which has been used for quite a long time in the Python world
may deceptively appear to work at first glance.
Add an error message that will save a bit of time and frustration
that points the user towards using the supported installation
invocation.
Reported-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/setup.py | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/python/setup.py b/python/setup.py
index 2014f81b75..c5bc45919a 100755
--- a/python/setup.py
+++ b/python/setup.py
@@ -5,9 +5,26 @@
"""
import setuptools
+from setuptools.command import bdist_egg
+import sys
import pkg_resources
+class bdist_egg_guard(bdist_egg.bdist_egg):
+ """
+ Protect against bdist_egg from being executed
+
+ This prevents calling 'setup.py install' directly, as the 'install'
+ CLI option will invoke the deprecated bdist_egg hook. "pip install"
+ calls the more modern bdist_wheel hook, which is what we want.
+ """
+ def run(self):
+ sys.exit(
+ 'Installation directly via setup.py is not supported.\n'
+ 'Please use `pip install .` instead.'
+ )
+
+
def main():
"""
QEMU tooling installer
@@ -16,7 +33,7 @@ def main():
# https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
pkg_resources.require('setuptools>=39.2')
- setuptools.setup()
+ setuptools.setup(cmdclass={'bdist_egg': bdist_egg_guard})
if __name__ == '__main__':
--
2.34.1
On Mon, Feb 07, 2022 at 04:30:39PM -0500, John Snow wrote: > When invoking setup.py directly, the default behavior for 'install' is > to run the bdist_egg installation hook, which is ... actually deprecated > by setuptools. It doesn't seem to work quite right anymore. > > By contrast, 'pip install' will invoke the bdist_wheel hook > instead. This leads to differences in behavior for the two approaches. I > advocate using pip in the documentation in this directory, but the > 'setup.py' which has been used for quite a long time in the Python world > may deceptively appear to work at first glance. +1 for that. Using setup.py directly is no longer a good practice. All direct invocations of setup.py are deprecated. > --- > python/setup.py | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/python/setup.py b/python/setup.py > index 2014f81b75..c5bc45919a 100755 > --- a/python/setup.py > +++ b/python/setup.py > @@ -5,9 +5,26 @@ > """ > > import setuptools > +from setuptools.command import bdist_egg > +import sys > import pkg_resources > > > +class bdist_egg_guard(bdist_egg.bdist_egg): > + """ > + Protect against bdist_egg from being executed > + > + This prevents calling 'setup.py install' directly, as the 'install' > + CLI option will invoke the deprecated bdist_egg hook. "pip install" > + calls the more modern bdist_wheel hook, which is what we want. > + """ > + def run(self): > + sys.exit( > + 'Installation directly via setup.py is not supported.\n' > + 'Please use `pip install .` instead.' > + ) > + > + > def main(): > """ > QEMU tooling installer > @@ -16,7 +33,7 @@ def main(): > # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108 > pkg_resources.require('setuptools>=39.2') > > - setuptools.setup() > + setuptools.setup(cmdclass={'bdist_egg': bdist_egg_guard}) > > Reviewed-by: Beraldo Leal <bleal@redhat.com> -- Beraldo
On Wed, Feb 9, 2022 at 7:51 AM Beraldo Leal <bleal@redhat.com> wrote: > > On Mon, Feb 07, 2022 at 04:30:39PM -0500, John Snow wrote: > > When invoking setup.py directly, the default behavior for 'install' is > > to run the bdist_egg installation hook, which is ... actually deprecated > > by setuptools. It doesn't seem to work quite right anymore. > > > > By contrast, 'pip install' will invoke the bdist_wheel hook > > instead. This leads to differences in behavior for the two approaches. I > > advocate using pip in the documentation in this directory, but the > > 'setup.py' which has been used for quite a long time in the Python world > > may deceptively appear to work at first glance. > > +1 for that. Using setup.py directly is no longer a good practice. All > direct invocations of setup.py are deprecated. > > > --- > > python/setup.py | 19 ++++++++++++++++++- > > 1 file changed, 18 insertions(+), 1 deletion(-) > > > > diff --git a/python/setup.py b/python/setup.py > > index 2014f81b75..c5bc45919a 100755 > > --- a/python/setup.py > > +++ b/python/setup.py > > @@ -5,9 +5,26 @@ > > """ > > > > import setuptools > > +from setuptools.command import bdist_egg > > +import sys > > import pkg_resources > > > > > > +class bdist_egg_guard(bdist_egg.bdist_egg): > > + """ > > + Protect against bdist_egg from being executed > > + > > + This prevents calling 'setup.py install' directly, as the 'install' > > + CLI option will invoke the deprecated bdist_egg hook. "pip install" > > + calls the more modern bdist_wheel hook, which is what we want. > > + """ > > + def run(self): > > + sys.exit( > > + 'Installation directly via setup.py is not supported.\n' > > + 'Please use `pip install .` instead.' > > + ) > > + > > + > > def main(): > > """ > > QEMU tooling installer > > @@ -16,7 +33,7 @@ def main(): > > # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108 > > pkg_resources.require('setuptools>=39.2') > > > > - setuptools.setup() > > + setuptools.setup(cmdclass={'bdist_egg': bdist_egg_guard}) > > > > > > Reviewed-by: Beraldo Leal <bleal@redhat.com> > > -- > Beraldo > Thanks, staging this one to my python branch. --js
On Mon, 7 Feb 2022 at 21:34, John Snow <jsnow@redhat.com> wrote: > > When invoking setup.py directly, the default behavior for 'install' is > to run the bdist_egg installation hook, which is ... actually deprecated > by setuptools. It doesn't seem to work quite right anymore. > > By contrast, 'pip install' will invoke the bdist_wheel hook > instead. This leads to differences in behavior for the two approaches. I > advocate using pip in the documentation in this directory, but the > 'setup.py' which has been used for quite a long time in the Python world > may deceptively appear to work at first glance. > > Add an error message that will save a bit of time and frustration > that points the user towards using the supported installation > invocation. While we're on the topic of python installation, is there any way to suppress or otherwise deal with the warning Meson prints out? WARNING: Broken python installation detected. Python files installed by Meson might not be found by python interpreter. (I vaguely recall tracking down a meson bug, and this seems to be some issue the meson developers have with the way Ubuntu/Debian have done their python packaging. But I forget the details.) thanks -- PMM
On Wed, Feb 9, 2022, 8:35 AM Peter Maydell <peter.maydell@linaro.org> wrote: > On Mon, 7 Feb 2022 at 21:34, John Snow <jsnow@redhat.com> wrote: > > > > When invoking setup.py directly, the default behavior for 'install' is > > to run the bdist_egg installation hook, which is ... actually deprecated > > by setuptools. It doesn't seem to work quite right anymore. > > > > By contrast, 'pip install' will invoke the bdist_wheel hook > > instead. This leads to differences in behavior for the two approaches. I > > advocate using pip in the documentation in this directory, but the > > 'setup.py' which has been used for quite a long time in the Python world > > may deceptively appear to work at first glance. > > > > Add an error message that will save a bit of time and frustration > > that points the user towards using the supported installation > > invocation. > > While we're on the topic of python installation, is there any way > to suppress or otherwise deal with the warning Meson prints out? > > WARNING: Broken python installation detected. Python files installed > by Meson might not be found by python interpreter. > > (I vaguely recall tracking down a meson bug, and this seems to be > some issue the meson developers have with the way Ubuntu/Debian > have done their python packaging. But I forget the details.) > > thanks > -- PMM > Unknown, I don't think I see this message on Fedora. Are you seeing it from Debian? I'll see if it shows up in any of the VM build tests. >
On Wed, 9 Feb 2022 at 16:54, John Snow <jsnow@redhat.com> wrote: > On Wed, Feb 9, 2022, 8:35 AM Peter Maydell <peter.maydell@linaro.org> wrote: >> While we're on the topic of python installation, is there any way >> to suppress or otherwise deal with the warning Meson prints out? >> >> WARNING: Broken python installation detected. Python files installed >> by Meson might not be found by python interpreter. >> >> (I vaguely recall tracking down a meson bug, and this seems to be >> some issue the meson developers have with the way Ubuntu/Debian >> have done their python packaging. But I forget the details.) > Unknown, I don't think I see this message on Fedora. Are you seeing > it from Debian? I'll see if it shows up in any of the VM build tests. Yeah, it's an Ubuntu/Debian thing. -- PMM
© 2016 - 2025 Red Hat, Inc.