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