def test_basic_functionality_second_api(runner):
    group1 = OptionGroup('Group 1', help='Group 1 description')
    group2 = OptionGroup('Group 2', help='Group 2 description')

    @click.command()
    @click.option('--hello')
    @group1.option('--foo1')
    @group1.option('--bar1')
    @click.option('--lol')
    @group2.option('--foo2')
    @group2.option('--bar2')
    @click.option('--goodbye')
    def cli(hello, foo1, bar1, lol, foo2, bar2, goodbye):
        click.echo(f'{foo1},{bar1},{foo2},{bar2}')

    result = runner.invoke(cli, ['--help'])

    assert not result.exception
    assert 'Group 1:' in result.output
    assert 'Group 1 description' in result.output
    assert 'Group 2:' in result.output
    assert 'Group 2 description' in result.output

    result = runner.invoke(cli, [
        '--foo1', 'foo1', '--bar1', 'bar1',
        '--foo2', 'foo2', '--bar2', 'bar2'])

    assert not result.exception
    assert 'foo1,bar1,foo2,bar2' in result.output
 def options(cls):
     group = OptionGroup("Sync options")
     return compose_decorators(
         group.option('--full / --no-full',
                      default=cls.full,
                      show_default=True,
                      help="Perform full sync instead of incremental"),
         super().options())
def test_option_group_name_help():
    group = OptionGroup()
    assert group.name == ''
    assert group.help == ''

    group = OptionGroup('Group Name', help='Group description')
    assert group.name == 'Group Name'
    assert group.help == 'Group description'
 def options(cls):
     group = OptionGroup("Database")
     return compose_decorators(
         group.option('--database',
                      'strava_sqlite_database',
                      type=PathType(dir_okay=False),
                      default=cls.strava_sqlite_database,
                      show_default=True,
                      help="Sqlite database file"),
         super().options())
 def options(cls):
     group = OptionGroup("Strava web")
     return compose_decorators(
         group.option('--strava4-session',
                      'strava_cookie_strava4_session',
                      type=str,
                      envvar='STRAVA_COOKIE_STRAVA4_SESSION',
                      show_envvar=True,
                      required=True,
                      help="'_strava4_session' cookie value"),
         super().options())
 def options(cls):
     group = OptionGroup("GPX storage")
     return compose_decorators(
         group.option(
             '--dir-activities',
             type=PathType(file_okay=False),
             default=cls.dir_activities,
             show_default=True,
             help="Directory to store gpx files indexed by activity id"),
         group.option(
             '--dir-activities-backup',
             type=PathType(file_okay=False),
             help=
             "Optional path to activities in Strava backup (no need to redownload these)"
         ),
         super().options())
def test_subcommand_mix_decl_second_api():
    group = OptionGroup()

    with pytest.raises(TypeError, match=r"Check decorator position for \['--hello'\] option in 'cli1'"):
        @click.group()
        @group.option('--foo')
        @click.option('--hello')
        @group.option('--bar')
        def cli1(**params):
            pass

        @cli1.command()
        @group.option('--foo')
        @group.option('--bar')
        def command1(**params):
            pass

    with pytest.raises(TypeError, match=r"Check decorator position for \['--hello'\] option in 'command2'"):
        @click.group()
        @group.option('--foo')
        @group.option('--bar')
        def cli2(**params):
            pass

        @cli2.command()
        @group.option('--foo')
        @click.option('--hello')
        @group.option('--bar')
        def command2(**params):
            pass
def test_group_context_second_api(runner):
    group = OptionGroup()

    @click.command()
    @group.option('--foo1')
    @group.option('--bar1')
    def cli1(foo1, bar1):
        click.echo(f'{foo1},{bar1}')

    @click.command()
    @group.option('--foo2')
    @group.option('--bar2')
    def cli2(foo2, bar2):
        click.echo(f'{foo2},{bar2}')

    result = runner.invoke(cli1, ['--help'])
    assert not result.exception
    assert '(foo1|bar1):' in result.output
    assert '--foo1' in result.output
    assert '--bar1' in result.output

    result = runner.invoke(cli2, ['--help'])
    assert not result.exception
    assert '(foo2|bar2):' in result.output
    assert '--foo2' in result.output
    assert '--bar2' in result.output

    result = runner.invoke(cli1, ['--foo1', 'foo1', '--bar1', 'bar1'])
    assert not result.exception
    assert 'foo1,bar1' in result.output

    result = runner.invoke(cli2, ['--foo2', 'foo2', '--bar2', 'bar2'])
    assert not result.exception
    assert 'foo2,bar2' in result.output
 def options(cls):
     group = OptionGroup("Strava API")
     return compose_decorators(
         group.option('--client-id',
                      'strava_client_id',
                      type=str,
                      envvar='STRAVA_CLIENT_ID',
                      show_envvar=True,
                      default=cls.strava_client_id,
                      help="Strava OAuth 2 client id"),
         group.option('--client-secret',
                      'strava_client_secret',
                      type=str,
                      envvar='STRAVA_CLIENT_SECRET',
                      show_envvar=True,
                      default=cls.strava_client_secret,
                      help="Strava OAuth 2 client secret"),
         group.option('--token-file',
                      'strava_token_filename',
                      type=PathType(dir_okay=False),
                      default=cls.strava_token_filename,
                      show_default=True,
                      help="Strava OAuth 2 token store"),
         group.option('--http-host',
                      type=str,
                      default=cls.http_host,
                      show_default=True,
                      help="OAuth 2 HTTP server host"),
         group.option('--http-port',
                      type=int,
                      default=cls.http_port,
                      show_default=True,
                      help="OAuth 2 HTTP server port"),
         super().options())
def test_mix_decl_second_api():
    group1 = OptionGroup('Group 1', help='Group 1 description')

    with pytest.raises(TypeError, match=r"Check decorator position for \['--hello2'\]"):
        @click.command()
        @click.option('--hello1')
        @group1.option('--foo')
        @click.option('--hello2')
        @group1.option('--bar')
        @click.option('--hello3')
        def cli(**params):
            pass
def test_subcommand_second_api(runner):
    group = OptionGroup('Group', help='Group description')

    @click.group()
    @group.option('--foo1')
    @group.option('--bar1')
    def cli(foo1, bar1):
        click.echo(f'{foo1},{bar1}')

    @cli.command()
    @group.option('--foo2')
    @group.option('--bar2')
    def command(foo2, bar2):
        click.echo(f'{foo2},{bar2}')

    result = runner.invoke(cli, ['--help'])

    assert not result.exception
    assert 'Group:' in result.output
    assert 'Group description' in result.output
    assert '--foo1' in result.output
    assert '--bar1' in result.output

    result = runner.invoke(cli, ['command', '--help'])

    assert not result.exception

    assert 'Group:' in result.output
    assert 'Group description' in result.output
    assert '--foo2' in result.output
    assert '--bar2' in result.output

    result = runner.invoke(cli, [
        '--foo1', 'foo1', '--bar1', 'bar1', 'command', '--foo2', 'foo2',
        '--bar2', 'bar2'
    ])

    assert not result.exception
    assert 'foo1,bar1\nfoo2,bar2' in result.output
Example #12
0
            f.download(output_dir, replace=overwrite)

    else:

        def download(f: wandb.apis.public.File) -> None:
            return None

    for file_ in run_.files():

        if ff(file_):
            download(file_)
            delete(file_)


files_input = OptionGroup(
    "Input", help="The file globs to include and/or exclude."
)


@click.command(name="files")
@click.argument("run", type=str)
@files_input.option(
    "-f",
    "--files",
    default=None,
    type=str,
    help=dedent(
        """
        File globs to include (+) and exclude (-) files split using '|'.
        For example, to include all files with extension .json and important.txt, but ignoring all other .txt files and extra.json,
        in the 'serialization_dir' folder,
Example #13
0
import click
import os
import yaml
from omegaconf import OmegaConf
from click_option_group import OptionGroup

from im2gps.conf.config import load_config, configure_logging
from im2gps.conf.net.configschema import TrainConfig, ExtendedTestConfig
from im2gps.services.network import TrainServiceBuilder, ParameterSelectionService, NetworkTestService

train_properties = OptionGroup(
    "Train properties",
    help="Providing parameters from this group will override default "
    "parameters from config.")


@click.command()
@click.option("-v",
              "--verbosity",
              type=click.Choice(
                  ['disable', 'debug', 'info', 'warn', 'error', 'critical'],
                  case_sensitive=False),
              default='info',
              help="Provide verbosity level")
@click.option("-p",
              "--config-path",
              type=str,
              required=True,
              help="Provide path to train config file")
@click.option("-c",
              "--checkpoint-path",
Example #14
0
import click
import os
from click_option_group import OptionGroup

from im2gps.core.index import IndexType, IndexConfig
from im2gps.services.index import create_and_save_index

index_config = OptionGroup("Index parameters",
                           help="Parameters used for building faiss index")


@click.group()
def index():
    pass


@index.command()
@index_config.option(
    "--index-type",
    '-i',
    type=click.Choice([enum.value for enum in IndexType]),
    default=IndexType.L2_INDEX.value,
    help=
    "Chose which index type to use. This will affect how distance between two descriptors i"
    f"s measured. Default value is {IndexType.L2_INDEX.value}")
@index_config.option("--gpu-id",
                     default=-1,
                     help="ID of GPU to use. Default value is -1")
@index_config.option(
    "--gpu-enabled",
    '-g',
Example #15
0
import logging
from click_option_group import OptionGroup

from im2gps.services.localisation import (ModelParameters, BenchmarkParameters,
                                          perform_localisation_benchmark,
                                          TuningParameters,
                                          localisation_tuning)
from im2gps.conf.config import ConfigRepo, Config, load_config
from im2gps.core.index import IndexType, IndexConfig
from im2gps.core.localisation import LocalisationType
from im2gps.data.descriptors import DatasetEnum
import im2gps.conf.im2gps.configschema as schemas

log = logging.getLogger(__name__)

model_config = OptionGroup("Model parameters",
                           help="Parameters for localisation model")
index_config = OptionGroup("Index parameters",
                           help="Parameters used for building faiss index")
test_config = OptionGroup("Test options", help="Parameters for running test")


@click.group()
def localisation():
    pass


@localisation.command()
@model_config.option(
    "--loc-type",
    '-l',
    type=click.Choice([enum.value for enum in LocalisationType]),
Example #16
0
from click_option_group import OptionGroup

computational_group = OptionGroup(
    "Computational options", help="Context for runtime execution."
)
reproducibility_group = OptionGroup(
    "Reproducibility options", help="Allow to setup a deterministic setting."
)
model_group = OptionGroup(
    "Model options", help="Options allowing to choose the network trained."
)
data_group = OptionGroup("Data management", help="Options related to data management.")
cross_validation = OptionGroup(
    "Validation setup", help="Allow to choose the validation framework to use."
)
optimization_group = OptionGroup(
    "Optimization options", help="Options related to the optimizer."
)
transfer_learning_group = OptionGroup(
    "Transfer learning", help="Allow to choose a source MAPS."
)
task_group = OptionGroup(
    "Task specific options", help="Options specific to the task learnt by the network."
)