Python: discourage direct setup.py install
PATCH 1/1 Python: discourage direct setup.py install
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.
--- python/setup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
python/setup.py +18 -1
@@ -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__':
Signature · 1 line
2.34.1
Quoted 9 lines · John Snow
When invoking
setup.pydirectly, the default behavior for 'install' is to run thebdist_egginstallation hook, which is ... actually deprecated by setuptools. It doesn't seem to work quite right anymore.By contrast, 'pip install' will invoke the
bdist_wheelhook 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.
Quoted 36 lines
--- python/setup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)python/setup.py +17
-0@@ -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
python/setup.py def main(): · line 38
Quoted 7 lines
python/setup.py +1
-1@@ -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})
--
Beraldo
Quoted 61 lines · Beraldo Leal
Quoted 9 lines · John Snow
When invoking
setup.pydirectly, the default behavior for 'install' is to run thebdist_egginstallation hook, which is ... actually deprecated by setuptools. It doesn't seem to work quite right anymore.By contrast, 'pip install' will invoke the
bdist_wheelhook 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.pydirectly is no longer a good practice. All direct invocations ofsetup.pyare deprecated.Quoted 36 lines
--- python/setup.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)python/setup.py +17
-0@@ -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 installerpython/setup.py def main(): · line 38
Quoted 7 lines
python/setup.py +1
-1@@ -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 <[email protected]>
Quoted 3 lines
--
Beraldo
Thanks, staging this one to my python branch.
--js
Quoted 11 lines · John Snow
When invoking
setup.pydirectly, the default behavior for 'install' is to run thebdist_egginstallation hook, which is ... actually deprecated by setuptools. It doesn't seem to work quite right anymore.By contrast, 'pip install' will invoke the
bdist_wheelhook 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.
Quoted 3 lines
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
Quoted 22 lines · Peter Maydell
Quoted 11 lines · John Snow
When invoking
setup.pydirectly, the default behavior for 'install' is to run thebdist_egginstallation hook, which is ... actually deprecated by setuptools. It doesn't seem to work quite right anymore.By contrast, 'pip install' will invoke the
bdist_wheelhook 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.Quoted 3 lines
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.
Quoted 7 lines
(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.
Quoted 1 line
Quoted 7 lines · John Snow
Quoted 6 lines · Peter Maydell
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.
Quoted 6 lines
Quoted 3 lines
(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