Use setuptools 'entry_points' instead of distutils-style 'scripts'

A future commit will add aliases for these scripts, and using entry_points
will make them easier to set up.
This commit is contained in:
Valentin Lorentz 2022-06-17 09:08:50 +02:00
parent 52271d2e6e
commit 0572d49988
10 changed files with 50 additions and 22 deletions

View File

@ -117,7 +117,9 @@ packages = ['supybot',
'supybot.locales', 'supybot.locales',
'supybot.utils', 'supybot.utils',
'supybot.drivers', 'supybot.drivers',
'supybot.plugins',] + \ 'supybot.plugins',
'supybot.scripts',
] + \
['supybot.plugins.'+s for s in plugins] + \ ['supybot.plugins.'+s for s in plugins] + \
[ [
'supybot.plugins.Dict.local', 'supybot.plugins.Dict.local',
@ -213,7 +215,13 @@ setup(
package_data=package_data, package_data=package_data,
scripts=['scripts/supybot%s' % name for name in scripts], entry_points={
'console_scripts': [
'supybot%s = supybot.scripts.limnoria%s:main'
% (name, name.replace('-', '_'))
for name in scripts
]
},
data_files=( data_files=(
[('share/man/man1', ['man/supybot%s.1' % name]) for name in scripts] [('share/man/man1', ['man/supybot%s.1' % name]) for name in scripts]

0
src/scripts/__init__.py Normal file
View File

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python3
### ###
# Copyright (c) 2003-2004, Jeremiah Fincher # Copyright (c) 2003-2004, Jeremiah Fincher
# Copyright (c) 2009, James McCoy # Copyright (c) 2009, James McCoy
@ -35,8 +33,6 @@
This is the main program to run Supybot. This is the main program to run Supybot.
""" """
import supybot
import re import re
import os import os
import sys import sys
@ -78,11 +74,14 @@ except ImportError:
from supybot.version import version from supybot.version import version
def main(): def run():
import supybot.log as log
import supybot.conf as conf import supybot.conf as conf
import supybot.world as world import supybot.world as world
import supybot.drivers as drivers import supybot.drivers as drivers
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule import supybot.schedule as schedule
import supybot.httpserver as httpserver
# We schedule this event rather than have it actually run because if there # We schedule this event rather than have it actually run because if there
# is a failure between now and the time it takes the Owner plugin to load # is a failure between now and the time it takes the Owner plugin to load
# all the various plugins, our registry file might be wiped. That's bad. # all the various plugins, our registry file might be wiped. That's bad.
@ -147,7 +146,7 @@ def main():
log.info('Total CPU time taken: %.2f seconds.', user+system) log.info('Total CPU time taken: %.2f seconds.', user+system)
log.info('No more Irc objects, exiting.') log.info('No more Irc objects, exiting.')
if __name__ == '__main__': def main():
parser = optparse.OptionParser(usage='Usage: %prog [options] configFile', parser = optparse.OptionParser(usage='Usage: %prog [options] configFile',
version='Limnoria %s running on Python %s' % version='Limnoria %s running on Python %s' %
(version, sys.version)) (version, sys.version))
@ -355,7 +354,7 @@ if __name__ == '__main__':
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
import supybot.plugins.Owner as Owner import supybot.plugins.Owner as Owner
# These may take some resources, and it does not need to be run while boot, so # This may take some resources, and it does not need to run while booting, so
# we import it as late as possible (but before plugins are loaded). # we import it as late as possible (but before plugins are loaded).
import supybot.httpserver as httpserver import supybot.httpserver as httpserver
@ -364,9 +363,9 @@ if __name__ == '__main__':
if options.profile: if options.profile:
import profile import profile
world.profiling = True world.profiling = True
profile.run('main()', '%s-%i.prof' % (nick, time.time())) profile.run('run()', '%s-%i.prof' % (nick, time.time()))
else: else:
main() run()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -53,7 +53,7 @@ def debug(s):
s += os.linesep s += os.linesep
sys.stdout.write(s) sys.stdout.write(s)
if __name__ == '__main__': def main()
# XXX I wanted this for conf.version, but this will create directories. We # XXX I wanted this for conf.version, but this will create directories. We
# really need to refactor conf so it either doesn't create directories, or # really need to refactor conf so it either doesn't create directories, or
# so that static information (like the version) can be imported from # so that static information (like the version) can be imported from
@ -135,4 +135,7 @@ if __name__ == '__main__':
else: else:
sys.exit(0) sys.exit(0)
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -211,7 +211,7 @@ readmeTemplate = '''
%s %s
'''.lstrip() '''.lstrip()
def main(): def _main():
global copyright global copyright
global license global license
parser = optparse.OptionParser(usage='Usage: %prog [options]', parser = optparse.OptionParser(usage='Usage: %prog [options]',
@ -307,13 +307,16 @@ def main():
print('Your new plugin template is in the %s directory.' % name) print('Your new plugin template is in the %s directory.' % name)
if __name__ == '__main__': def main():
try: try:
main() _main()
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
output("""It looks like you cancelled out of this script before it was output("""It looks like you cancelled out of this script before it was
finished. Obviously, nothing was written, but just run this script finished. Obviously, nothing was written, but just run this script
again whenever you want to generate a template for a plugin.""") again whenever you want to generate a template for a plugin.""")
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -276,7 +276,7 @@ def genDoc(m, options):
finally: finally:
fd.close() fd.close()
if __name__ == '__main__': def main():
import glob import glob
import os.path import os.path
import optparse import optparse
@ -349,4 +349,8 @@ if __name__ == '__main__':
shutil.rmtree(conf.supybot.directories.conf()) shutil.rmtree(conf.supybot.directories.conf())
shutil.rmtree(conf.supybot.directories.data()) shutil.rmtree(conf.supybot.directories.data())
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=78: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=78:

View File

@ -40,7 +40,7 @@ import os
import sys import sys
import optparse import optparse
def main(): def _main():
import supybot.log as log import supybot.log as log
import supybot.conf as conf import supybot.conf as conf
conf.supybot.log.stdout.setValue(False) conf.supybot.log.stdout.setValue(False)
@ -102,10 +102,13 @@ def main():
ircdb.users.close() ircdb.users.close()
print('User %s\'s password reset!' % name) print('User %s\'s password reset!' % name)
if __name__ == '__main__': def main():
try: try:
main() main()
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -119,7 +119,7 @@ class path(str):
def __eq__(self, other): def __eq__(self, other):
return self._r.split(self) == self._r.split(other) return self._r.split(self) == self._r.split(other)
if __name__ == '__main__': def main():
import glob import glob
import os.path import os.path
import optparse import optparse
@ -243,4 +243,8 @@ if __name__ == '__main__':
else: else:
sys.exit(1) sys.exit(1)
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -166,7 +166,7 @@ def getDirectoryName(default, basedir=os.curdir, prompt=True):
return (dir, os.path.dirname(orig_dir)) return (dir, os.path.dirname(orig_dir))
def main(): def _main():
import supybot.version as version import supybot.version as version
parser = optparse.OptionParser(usage='Usage: %prog [options]', parser = optparse.OptionParser(usage='Usage: %prog [options]',
version='Supybot %s' % version.version) version='Supybot %s' % version.version)
@ -815,9 +815,9 @@ def main():
just have to start it like you start all your other Python scripts.""" % \ just have to start it like you start all your other Python scripts.""" % \
(filename, filename)) (filename, filename))
if __name__ == '__main__': def main():
try: try:
main() _main()
except KeyboardInterrupt: except KeyboardInterrupt:
# We may still be using bold text when exiting during a prompt # We may still be using bold text when exiting during a prompt
if questions.useBold: if questions.useBold:
@ -829,4 +829,8 @@ if __name__ == '__main__':
it was done. Unfortunately, I didn't get to write anything to file. it was done. Unfortunately, I didn't get to write anything to file.
Please run the wizard again to completion.""") Please run the wizard again to completion.""")
if __name__ == '__main__':
main()
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: