Skip to content

Commit 2ddaeb7

Browse files
committed
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. Reported-by: Daniel P. Berrangé <[email protected]> Signed-off-by: John Snow <[email protected]> Reviewed-by: Beraldo Leal <[email protected]> Message-id: [email protected] Signed-off-by: John Snow <[email protected]>
1 parent 5c66d7d commit 2ddaeb7

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

python/setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@
55
"""
66

77
import setuptools
8+
from setuptools.command import bdist_egg
9+
import sys
810
import pkg_resources
911

1012

13+
class bdist_egg_guard(bdist_egg.bdist_egg):
14+
"""
15+
Protect against bdist_egg from being executed
16+
17+
This prevents calling 'setup.py install' directly, as the 'install'
18+
CLI option will invoke the deprecated bdist_egg hook. "pip install"
19+
calls the more modern bdist_wheel hook, which is what we want.
20+
"""
21+
def run(self):
22+
sys.exit(
23+
'Installation directly via setup.py is not supported.\n'
24+
'Please use `pip install .` instead.'
25+
)
26+
27+
1128
def main():
1229
"""
1330
QEMU tooling installer
@@ -16,7 +33,7 @@ def main():
1633
# https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108
1734
pkg_resources.require('setuptools>=39.2')
1835

19-
setuptools.setup()
36+
setuptools.setup(cmdclass={'bdist_egg': bdist_egg_guard})
2037

2138

2239
if __name__ == '__main__':

0 commit comments

Comments
 (0)