diff --git a/requirements-swh-server.txt b/requirements-swh-server.txt --- a/requirements-swh-server.txt +++ b/requirements-swh-server.txt @@ -1,3 +1,4 @@ +swh.core[http] swh.loader.tar >= 0.0.39 swh.loader.core >= 0.0.32 swh.scheduler >= 0.0.39 diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1 +1 @@ -swh.core >= 0.0.36 +swh.core >= 0.0.59 diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -16,22 +16,23 @@ long_description = f.read() -def parse_requirements(name=None): - if name: - reqf = 'requirements-%s.txt' % name - else: - reqf = 'requirements.txt' - +def parse_requirements(*names): requirements = [] - if not path.exists(reqf): - return requirements + for name in names: + if name: + reqf = 'requirements-%s.txt' % name + else: + reqf = 'requirements.txt' + + if not path.exists(reqf): + return requirements - with open(reqf) as f: - for line in f.readlines(): - line = line.strip() - if not line or line.startswith('#'): - continue - requirements.append(line) + with open(reqf) as f: + for line in f.readlines(): + line = line.strip() + if not line or line.startswith('#'): + continue + requirements.append(line) return requirements @@ -44,17 +45,19 @@ author_email='swh-devel@inria.fr', url='https://forge.softwareheritage.org/source/swh-deposit/', packages=find_packages(), - install_requires=parse_requirements() + parse_requirements('swh'), + install_requires=parse_requirements(None, 'swh'), tests_require=parse_requirements('test'), setup_requires=['vcversioner'], - extras_require={'testing': parse_requirements('test'), - 'server': (parse_requirements('server') + - parse_requirements('swh-server'))}, + extras_require={ + 'testing': parse_requirements('test', 'server', 'swh-server'), + 'server': parse_requirements('server', 'swh-server')}, vcversioner={}, include_package_data=True, entry_points=''' [console_scripts] swh-deposit=swh.deposit.cli:main + [swh.cli] + swh-deposit=swh.deposit.cli ''', classifiers=[ "Programming Language :: Python :: 3", diff --git a/swh/deposit/cli/__init__.py b/swh/deposit/cli/__init__.py --- a/swh/deposit/cli/__init__.py +++ b/swh/deposit/cli/__init__.py @@ -6,31 +6,41 @@ import click import logging -logger = logging.getLogger(__name__) - - -CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) +from swh.core.cli import swh, CONTEXT_SETTINGS +logger = logging.getLogger(__name__) -@click.group(context_settings=CONTEXT_SETTINGS) -@click.option('--log-level', '-l', default='INFO', - type=click.Choice(logging._nameToLevel.keys()), - help="Log level (default to INFO)") -@click.pass_context -def cli(ctx, log_level): - logger.setLevel(log_level) - ctx.ensure_object(dict) +if __name__ == '__main__': + # for bw compat (i.e. have the 'swh-deposit' command), should now use the + # master 'swh' command group defined in swh.core + @click.group('swh-deposit', context_settings=CONTEXT_SETTINGS) + @click.option('--log-level', '-l', default='INFO', + type=click.Choice(logging._nameToLevel.keys()), + help="Log level (default to INFO)") + @click.pass_context + def deposit(ctx, log_level): + logger.setLevel(log_level) + ctx.ensure_object(dict) +else: + @swh.group('deposit') + @click.pass_context + def deposit(ctx): + """Deposit main command + """ + pass def main(): logging.basicConfig() - from . import deposit # noqa - try: - from . import admin # noqa - except ImportError: # server part is optional - pass - - return cli(auto_envvar_prefix='SWH_DEPOSIT') + return deposit(auto_envvar_prefix='SWH_DEPOSIT') + +# These import statements MUST be executed after defining the 'deposit' group +# since the subcommands in these are defined using this 'deposit' group. +from . import client # noqa +try: + from . import admin # noqa +except ImportError: # server part is optional + pass if __name__ == '__main__': diff --git a/swh/deposit/cli/admin.py b/swh/deposit/cli/admin.py --- a/swh/deposit/cli/admin.py +++ b/swh/deposit/cli/admin.py @@ -6,10 +6,10 @@ import click from swh.deposit.config import setup_django_for -from swh.deposit.cli import cli +from swh.deposit.cli import deposit -@cli.group('admin') +@deposit.group('admin') @click.option('--config-file', '-C', default=None, type=click.Path(exists=True, dir_okay=False,), help="Optional extra configuration file.") diff --git a/swh/deposit/cli/deposit.py b/swh/deposit/cli/client.py rename from swh/deposit/cli/deposit.py rename to swh/deposit/cli/client.py --- a/swh/deposit/cli/deposit.py +++ b/swh/deposit/cli/client.py @@ -12,7 +12,7 @@ import xmltodict from swh.deposit.client import PublicApiDepositClient -from swh.deposit.cli import cli +from swh.deposit.cli import deposit logger = logging.getLogger(__name__) @@ -266,7 +266,7 @@ **_subdict(config, keys)) -@cli.command() +@deposit.command() @click.option('--username', required=1, help="(Mandatory) User's name") @click.option('--password', required=1, @@ -301,13 +301,13 @@ help='Software author(s), this can be repeated as many times' ' as there are authors') @click.pass_context -def deposit(ctx, - username, password, archive=None, metadata=None, - archive_deposit=False, metadata_deposit=False, - collection=None, slug=None, partial=False, deposit_id=None, - replace=False, status=False, - url='https://deposit.softwareheritage.org/1', - verbose=False, name=None, author=None): +def upload(ctx, + username, password, archive=None, metadata=None, + archive_deposit=False, metadata_deposit=False, + collection=None, slug=None, partial=False, deposit_id=None, + replace=False, status=False, + url='https://deposit.softwareheritage.org/1', + verbose=False, name=None, author=None): """Software Heritage Public Deposit Client Create/Update deposit through the command line or access its