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
This commit is contained in:
qubesuser 2017-11-09 17:46:06 +01:00
parent d08f1a58b7
commit b731ef3885

View File

@ -2,6 +2,7 @@
import os import os
import setuptools import setuptools
import setuptools.command.install
import sys import sys
exclude=[] exclude=[]
@ -19,9 +20,29 @@ def get_console_scripts():
basename, ext = os.path.splitext(os.path.basename(filename)) basename, ext = os.path.splitext(os.path.basename(filename))
if basename in ['__init__', 'dochelpers'] or ext != '.py': if basename in ['__init__', 'dochelpers'] or ext != '.py':
continue continue
yield '{} = qubesadmin.tools.{}:main'.format( yield basename.replace('_', '-'), 'qubesadmin.tools.{}'.format(basename)
basename.replace('_', '-'), 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__': if __name__ == '__main__':
setuptools.setup( setuptools.setup(
@ -36,8 +57,8 @@ if __name__ == '__main__':
package_data={ package_data={
'qubesadmin.tests.backup': ['*.xml'], 'qubesadmin.tests.backup': ['*.xml'],
}, },
entry_points={ cmdclass={
'console_scripts': list(get_console_scripts()), 'install': CustomInstall
}, },
) )