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 is based on
QubesOS/qubes-core-admin-client@b731ef3885
by @qubesuser
This commit is contained in:
Marek Marczykowski-Górecki 2018-01-18 22:13:37 +01:00
parent e9cc6ee3db
commit 5ea8eda3ea
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -4,18 +4,42 @@
import os
import setuptools
import setuptools.command.install
# don't import: import * is unreliable and there is no need, since this is
# compile time and we have source files
def get_console_scripts():
yield 'qrexec-policy', 'qubespolicy.cli'
yield 'qrexec-policy-agent', 'qubespolicy.agent'
yield 'qrexec-policy-graph', 'qubespolicy.graph'
for filename in os.listdir('./qubes/tools'):
basename, ext = os.path.splitext(os.path.basename(filename))
if basename == '__init__' or ext != '.py':
continue
yield '{} = qubes.tools.{}:main'.format(
basename.replace('_', '-'), basename)
yield basename.replace('_', '-'), 'qubes.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(
@ -30,12 +54,10 @@ if __name__ == '__main__':
package_data = {
'qubespolicy': ['glade/*.glade'],
},
cmdclass={
'install': CustomInstall,
},
entry_points={
'console_scripts': list(get_console_scripts()) + [
'qrexec-policy = qubespolicy.cli:main',
'qrexec-policy-agent = qubespolicy.agent:main',
'qrexec-policy-graph = qubespolicy.graph:main',
],
'qubes.vm': [
'AppVM = qubes.vm.appvm:AppVM',
'TemplateVM = qubes.vm.templatevm:TemplateVM',