Skip to content

Commit

Permalink
feat: Correct the usage information for scrapyd command, closes #238
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Jul 16, 2024
1 parent 1362df7 commit 6dfbee0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changed

- Add a confirmation dialog to the Cancel button.
- Add "Last modified" column to the directory listings of log files and item feeds.
- The Scrapyd CLI corrects the usage message and long description, removes all ``twistd`` subcommands, and removes the ``--nodaemon`` and ``--python=`` options, which it overrides.
- The Scrapyd CLI runs from the ``scrapyd.__main__`` module instead of from the ``scrapyd.scripts.scrapyd_run`` module.
- Drop support for end-of-life Python version 3.7.

Expand Down
21 changes: 19 additions & 2 deletions scrapyd/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@
import sys
from os.path import dirname, join

from twisted.scripts.twistd import run
from twisted.scripts import twistd

import scrapyd


class ServerOptions(twistd.ServerOptions):
synopsis = 'Usage: scrapyd [options]'
longdesc = 'Scrapyd is an application for deploying and running Scrapy spiders.'

def __init__(self):
super().__init__()
# main() always sets -n (--nodaemon) and -y (--python=).
self.longOpt = [opt for opt in self.longOpt if opt not in ('nodaemon', 'python=')]

@property
def subCommands(self):
return [] # remove alternatives to running txapp.py

def getUsage(self, width=None):
return super().getUsage(width=width)[:-11] # remove "\nCommands:\n"


def main():
if len(sys.argv) > 1 and '-v' in sys.argv[1:] or '--version' in sys.argv[1:]:
__version__ = pkgutil.get_data(__package__, '../VERSION').decode('ascii').strip()
print(f'Scrapyd {__version__}')
else:
sys.argv[1:1] = ['-n', '-y', join(dirname(scrapyd.__file__), 'txapp.py')]
run()
twistd.app.run(twistd.runApp, ServerOptions)


if __name__ == '__main__':
Expand Down

0 comments on commit 6dfbee0

Please sign in to comment.