From b731ef388571c30e1d2383bdf6b287ed7c6dbe42 Mon Sep 17 00:00:00 2001 From: qubesuser Date: Thu, 9 Nov 2017 17:46:06 +0100 Subject: [PATCH] replace console entry points with just importing the module importing pkg_resources and looking up entry points wastes 100ms+ of time, which is totally unnecessary --- setup.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 7c27c3f..65e96e6 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import os import setuptools +import setuptools.command.install import sys exclude=[] @@ -19,9 +20,29 @@ def get_console_scripts(): basename, ext = os.path.splitext(os.path.basename(filename)) if basename in ['__init__', 'dochelpers'] or ext != '.py': continue - yield '{} = qubesadmin.tools.{}:main'.format( - basename.replace('_', '-'), basename) + yield basename.replace('_', '-'), 'qubesadmin.tools.{}'.format(basename) +# create simple scripts that run much faster than "console entry points" +class CustomInstall(setuptools.command.install.install): + def run(self): + bin = os.path.join(self.root, "usr/bin") + try: + os.makedirs(bin) + except: + pass + for file, pkg in get_console_scripts(): + path = os.path.join(bin, file) + with open(path, "w") as f: + f.write( +"""#!/usr/bin/python3 +from {} import main +import sys +if __name__ == '__main__': + sys.exit(main()) +""".format(pkg)) + + os.chmod(path, 0o755) + setuptools.command.install.install.run(self) if __name__ == '__main__': setuptools.setup( @@ -36,8 +57,8 @@ if __name__ == '__main__': package_data={ 'qubesadmin.tests.backup': ['*.xml'], }, - entry_points={ - 'console_scripts': list(get_console_scripts()), + cmdclass={ + 'install': CustomInstall }, )