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:
parent
d08f1a58b7
commit
b731ef3885
29
setup.py
29
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
|
||||
},
|
||||
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user