* [PATCH] Python: discourage direct setup.py install
@ 2022-02-07 21:30 John Snow
2022-02-09 12:51 ` Beraldo Leal
2022-02-09 13:35 ` Peter Maydell
0 siblings, 2 replies; 6+ messages in thread
From: John Snow @ 2022-02-07 21:30 UTC (permalink / raw)
To: qemu-devel
Cc: Eduardo Habkost, Daniel P . Berrangé,
John Snow, Beraldo Leal, Cleber Rosa
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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Python: discourage direct setup.py install
2022-02-07 21:30 [PATCH] Python: discourage direct setup.py install John Snow
@ 2022-02-09 12:51 ` Beraldo Leal
2022-02-09 18:24 ` John Snow
2022-02-09 13:35 ` Peter Maydell
1 sibling, 1 reply; 6+ messages in thread
From: Beraldo Leal @ 2022-02-09 12:51 UTC (permalink / raw)
To: John Snow
Cc: Eduardo Habkost, Daniel P . Berrangé, qemu-devel, Cleber Rosa
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Python: discourage direct setup.py install
2022-02-07 21:30 [PATCH] Python: discourage direct setup.py install John Snow
2022-02-09 12:51 ` Beraldo Leal
@ 2022-02-09 13:35 ` Peter Maydell
2022-02-09 16:53 ` John Snow
1 sibling, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2022-02-09 13:35 UTC (permalink / raw)
To: John Snow
Cc: Eduardo Habkost, Cleber Rosa, Daniel P . Berrangé,
qemu-devel, Beraldo Leal
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Python: discourage direct setup.py install
2022-02-09 13:35 ` Peter Maydell
@ 2022-02-09 16:53 ` John Snow
2022-02-09 17:14 ` Peter Maydell
0 siblings, 1 reply; 6+ messages in thread
From: John Snow @ 2022-02-09 16:53 UTC (permalink / raw)
To: Peter Maydell
Cc: Eduardo Habkost, Cleber Rosa, Daniel P . Berrangé,
qemu-devel, Beraldo Leal
[-- Attachment #1: Type: text/plain, Size: 1492 bytes --]
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.
>
[-- Attachment #2: Type: text/html, Size: 2229 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Python: discourage direct setup.py install
2022-02-09 16:53 ` John Snow
@ 2022-02-09 17:14 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2022-02-09 17:14 UTC (permalink / raw)
To: John Snow
Cc: Eduardo Habkost, Cleber Rosa, Daniel P . Berrangé,
qemu-devel, Beraldo Leal
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Python: discourage direct setup.py install
2022-02-09 12:51 ` Beraldo Leal
@ 2022-02-09 18:24 ` John Snow
0 siblings, 0 replies; 6+ messages in thread
From: John Snow @ 2022-02-09 18:24 UTC (permalink / raw)
To: Beraldo Leal
Cc: Eduardo Habkost, Daniel P . Berrangé, qemu-devel, Cleber Rosa
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-02-09 19:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-07 21:30 [PATCH] Python: discourage direct setup.py install John Snow
2022-02-09 12:51 ` Beraldo Leal
2022-02-09 18:24 ` John Snow
2022-02-09 13:35 ` Peter Maydell
2022-02-09 16:53 ` John Snow
2022-02-09 17:14 ` Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.