From d9988a932c5365e2c5d04f5f8fff1c8350c67f6d Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Mon, 7 Oct 2019 22:42:28 +0200 Subject: [PATCH] Fix command listing to work on pip package installs --- bin/etherpump | 48 +++++++++++++++++++++++++++++------------------- setup.py | 1 + 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/bin/etherpump b/bin/etherpump index 3ad5858..545b073 100755 --- a/bin/etherpump +++ b/bin/etherpump @@ -1,36 +1,46 @@ #!/usr/bin/env python3 -import os import sys -from importlib import import_module -from pathlib import Path from etherpump import __VERSION__ def subcommands(): """List all sub-commands for the `--help` output.""" - not_sub_commands = ['common.py', 'appendmeta.py', 'html5tidy.py', 'join.py'] - subcommands = [] - - all_files = os.listdir(Path().absolute() / 'etherpump' / 'commands') - modules = filter( - lambda file: not file.startswith('__') - and not any(file == module for module in not_sub_commands), - all_files, - ) - - for module in modules: - name = module.split('.py')[0] + output = [] + + subcommands = [ + 'creatediffhtml', + 'deletepad', + 'dumpcsv', + 'gethtml', + 'gettext', + 'index', + 'init', + 'list', + 'listauthors', + 'publication', + 'pull', + 'revisionscount', + 'sethtml', + 'settext', + 'showmeta', + ] + + for subcommand in subcommands: try: - doc = import_module(f'etherpump.commands.{name}').__doc__ + # http://stackoverflow.com/questions/301134/dynamic-module-import-in-python + doc = __import__( + "etherpump.commands.%s" % subcommand, + fromlist=["etherdump.commands"], + ).__doc__ except ModuleNotFoundError: doc = "" - subcommands.append(f' {name}: {doc}') + output.append(f' {subcommand}: {doc}') - subcommands.sort() + output.sort() - return '\n'.join(subcommands) + return '\n'.join(output) usage = """ diff --git a/setup.py b/setup.py index 0686ce5..fec08ae 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,7 @@ setup( "python-dateutil", "pypandoc", "tqdm", + "requests", ], classifiers=[ 'Programming Language :: Python :: 3',