From 0572d499883ba1f320a01f0125b00c5962fdc2cd Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 17 Jun 2022 09:08:50 +0200 Subject: [PATCH] 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. --- setup.py | 12 ++++++++++-- src/scripts/__init__.py | 0 scripts/supybot => src/scripts/limnoria.py | 17 ++++++++--------- .../scripts/limnoria_adduser.py | 0 .../scripts/limnoria_botchk.py | 5 ++++- .../scripts/limnoria_plugin_create.py | 9 ++++++--- .../scripts/limnoria_plugin_doc.py | 6 +++++- .../scripts/limnoria_reset_password.py | 7 +++++-- .../scripts/limnoria_test.py | 6 +++++- .../scripts/limnoria_wizard.py | 10 +++++++--- 10 files changed, 50 insertions(+), 22 deletions(-) create mode 100644 src/scripts/__init__.py rename scripts/supybot => src/scripts/limnoria.py (98%) rename scripts/supybot-adduser => src/scripts/limnoria_adduser.py (100%) rename scripts/supybot-botchk => src/scripts/limnoria_botchk.py (99%) rename scripts/supybot-plugin-create => src/scripts/limnoria_plugin_create.py (99%) rename scripts/supybot-plugin-doc => src/scripts/limnoria_plugin_doc.py (99%) rename scripts/supybot-reset-password => src/scripts/limnoria_reset_password.py (99%) rename scripts/supybot-test => src/scripts/limnoria_test.py (99%) rename scripts/supybot-wizard => src/scripts/limnoria_wizard.py (99%) diff --git a/setup.py b/setup.py index 1d6def55d..b31d9f208 100644 --- a/setup.py +++ b/setup.py @@ -117,7 +117,9 @@ packages = ['supybot', 'supybot.locales', 'supybot.utils', 'supybot.drivers', - 'supybot.plugins',] + \ + 'supybot.plugins', + 'supybot.scripts', + ] + \ ['supybot.plugins.'+s for s in plugins] + \ [ 'supybot.plugins.Dict.local', @@ -213,7 +215,13 @@ setup( 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=( [('share/man/man1', ['man/supybot%s.1' % name]) for name in scripts] diff --git a/src/scripts/__init__.py b/src/scripts/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/scripts/supybot b/src/scripts/limnoria.py similarity index 98% rename from scripts/supybot rename to src/scripts/limnoria.py index e955433be..7178ee46e 100644 --- a/scripts/supybot +++ b/src/scripts/limnoria.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - ### # Copyright (c) 2003-2004, Jeremiah Fincher # Copyright (c) 2009, James McCoy @@ -35,8 +33,6 @@ This is the main program to run Supybot. """ -import supybot - import re import os import sys @@ -78,11 +74,14 @@ except ImportError: from supybot.version import version -def main(): +def run(): + import supybot.log as log import supybot.conf as conf import supybot.world as world import supybot.drivers as drivers + import supybot.ircmsgs as ircmsgs import supybot.schedule as schedule + import supybot.httpserver as httpserver # 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 # 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('No more Irc objects, exiting.') -if __name__ == '__main__': +def main(): parser = optparse.OptionParser(usage='Usage: %prog [options] configFile', version='Limnoria %s running on Python %s' % (version, sys.version)) @@ -355,7 +354,7 @@ if __name__ == '__main__': import supybot.callbacks as callbacks 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). import supybot.httpserver as httpserver @@ -364,9 +363,9 @@ if __name__ == '__main__': if options.profile: import profile world.profiling = True - profile.run('main()', '%s-%i.prof' % (nick, time.time())) + profile.run('run()', '%s-%i.prof' % (nick, time.time())) else: - main() + run() # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/scripts/supybot-adduser b/src/scripts/limnoria_adduser.py similarity index 100% rename from scripts/supybot-adduser rename to src/scripts/limnoria_adduser.py diff --git a/scripts/supybot-botchk b/src/scripts/limnoria_botchk.py similarity index 99% rename from scripts/supybot-botchk rename to src/scripts/limnoria_botchk.py index 1ed0dd644..596a98d34 100644 --- a/scripts/supybot-botchk +++ b/src/scripts/limnoria_botchk.py @@ -53,7 +53,7 @@ def debug(s): s += os.linesep sys.stdout.write(s) -if __name__ == '__main__': +def main() # 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 # so that static information (like the version) can be imported from @@ -135,4 +135,7 @@ if __name__ == '__main__': else: sys.exit(0) +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/scripts/supybot-plugin-create b/src/scripts/limnoria_plugin_create.py similarity index 99% rename from scripts/supybot-plugin-create rename to src/scripts/limnoria_plugin_create.py index c4b687454..c4b34e009 100644 --- a/scripts/supybot-plugin-create +++ b/src/scripts/limnoria_plugin_create.py @@ -211,7 +211,7 @@ readmeTemplate = ''' %s '''.lstrip() -def main(): +def _main(): global copyright global license parser = optparse.OptionParser(usage='Usage: %prog [options]', @@ -307,13 +307,16 @@ def main(): print('Your new plugin template is in the %s directory.' % name) -if __name__ == '__main__': +def main(): try: - main() + _main() except KeyboardInterrupt: print() output("""It looks like you cancelled out of this script before it was finished. Obviously, nothing was written, but just run this script again whenever you want to generate a template for a plugin.""") +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/scripts/supybot-plugin-doc b/src/scripts/limnoria_plugin_doc.py similarity index 99% rename from scripts/supybot-plugin-doc rename to src/scripts/limnoria_plugin_doc.py index 224b11dbd..588291352 100644 --- a/scripts/supybot-plugin-doc +++ b/src/scripts/limnoria_plugin_doc.py @@ -276,7 +276,7 @@ def genDoc(m, options): finally: fd.close() -if __name__ == '__main__': +def main(): import glob import os.path import optparse @@ -349,4 +349,8 @@ if __name__ == '__main__': shutil.rmtree(conf.supybot.directories.conf()) shutil.rmtree(conf.supybot.directories.data()) + +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=78: diff --git a/scripts/supybot-reset-password b/src/scripts/limnoria_reset_password.py similarity index 99% rename from scripts/supybot-reset-password rename to src/scripts/limnoria_reset_password.py index cd92a0f2d..08f0a037e 100644 --- a/scripts/supybot-reset-password +++ b/src/scripts/limnoria_reset_password.py @@ -40,7 +40,7 @@ import os import sys import optparse -def main(): +def _main(): import supybot.log as log import supybot.conf as conf conf.supybot.log.stdout.setValue(False) @@ -102,10 +102,13 @@ def main(): ircdb.users.close() print('User %s\'s password reset!' % name) -if __name__ == '__main__': +def main(): try: main() except KeyboardInterrupt: pass +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/scripts/supybot-test b/src/scripts/limnoria_test.py similarity index 99% rename from scripts/supybot-test rename to src/scripts/limnoria_test.py index f21a1f1ff..7db6b9107 100644 --- a/scripts/supybot-test +++ b/src/scripts/limnoria_test.py @@ -119,7 +119,7 @@ class path(str): def __eq__(self, other): return self._r.split(self) == self._r.split(other) -if __name__ == '__main__': +def main(): import glob import os.path import optparse @@ -243,4 +243,8 @@ if __name__ == '__main__': else: sys.exit(1) + +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/scripts/supybot-wizard b/src/scripts/limnoria_wizard.py similarity index 99% rename from scripts/supybot-wizard rename to src/scripts/limnoria_wizard.py index 39b5b8184..71f545248 100644 --- a/scripts/supybot-wizard +++ b/src/scripts/limnoria_wizard.py @@ -166,7 +166,7 @@ def getDirectoryName(default, basedir=os.curdir, prompt=True): return (dir, os.path.dirname(orig_dir)) -def main(): +def _main(): import supybot.version as version parser = optparse.OptionParser(usage='Usage: %prog [options]', version='Supybot %s' % version.version) @@ -815,9 +815,9 @@ def main(): just have to start it like you start all your other Python scripts.""" % \ (filename, filename)) -if __name__ == '__main__': +def main(): try: - main() + _main() except KeyboardInterrupt: # We may still be using bold text when exiting during a prompt if questions.useBold: @@ -829,4 +829,8 @@ if __name__ == '__main__': it was done. Unfortunately, I didn't get to write anything to file. Please run the wizard again to completion.""") + +if __name__ == '__main__': + main() + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: