Python click.INT Examples

The following are 10 code examples of click.INT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module click , or try the search function .
Example #1
Source File: utils.py    From git-pw with MIT License 6 votes vote down vote up
def pagination_options(sort_fields, default_sort):
    """Shared pagination options."""

    def _pagination_options(f):
        f = click.option('--limit', metavar='LIMIT', type=click.INT,
                         help='Maximum number of items to show.')(f)
        f = click.option('--page', metavar='PAGE', type=click.INT,
                         help='Page to retrieve items from. This is '
                         'influenced by the size of LIMIT.')(f)
        f = click.option('--sort', metavar='FIELD', default=default_sort,
                         type=click.Choice(sort_fields),
                         help='Sort output on given field.')(f)

        return f

    return _pagination_options 
Example #2
Source File: token_ops.py    From raiden-contracts with MIT License 6 votes vote down vote up
def common_options(func: Callable) -> Callable:
    """A decorator that combines commonly appearing @click.option decorators."""

    @click.option(
        "--private-key", required=True, help="Path to a private key store.", type=click.STRING
    )
    @click.option("--password", help="password file for the keystore json file", type=click.STRING)
    @click.option(
        "--rpc-url",
        default="http://127.0.0.1:8545",
        help="Address of the Ethereum RPC provider",
        type=click.STRING,
    )
    @click.option(
        "--token-address", required=True, help="Address of the token contract", type=click.STRING
    )
    @click.option(
        "--amount", required=True, help="Amount to mint/deposit/transfer", type=click.INT
    )
    @click.option("--wait", default=300, help="Max tx wait time in s.", type=click.INT)
    @functools.wraps(func)
    def wrapper(*args: List, **kwargs: Dict) -> Any:
        return func(*args, **kwargs)

    return wrapper 
Example #3
Source File: tokens_to_counts.py    From textkit with MIT License 5 votes vote down vote up
def tokens2counts(sep, limit, tokens):
    '''Count unique tokens in a list of tokens.
    Tokens are sorted by top counts.'''
    content = read_tokens(tokens)
    counts = sort_counts(get_counts(content))

    # we want the argument type to be an INT - but python only
    # has support for a float infinity. So if it the limit is negative,
    # it becomes infinite
    if limit < 0:
        limit = float('inf')

    # using csv writer to ensure proper encoding of the seperator.
    rows = [list(map(str, vals)) for ind, vals in enumerate(counts) if ind < limit]
    write_csv(rows, str(sep)) 
Example #4
Source File: cli.py    From fossor with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def fossor_cli_flags(f):
    '''Add default Fossor CLI flags'''
    # Flags will appear in reverse order of how they  are listed here:
    f = add_dynamic_args(f)  # Must be applied after all other click options since this requires click's context object to be passed

    # Add normal flags
    csv_list = CsvList()
    f = click.option('--black-list', 'blacklist', type=csv_list, help='Do not run these plugins.')(f)
    f = click.option('--white-list', 'whitelist', type=csv_list, help='Only run these plugins.')(f)
    f = click.option('--truncate/--no-truncate', 'truncate', show_default=True, default=True, is_flag=True)(f)
    f = click.option('-v', '--verbose', is_flag=True)(f)
    f = click.option('-d', '--debug', is_flag=True, callback=setup_logging)(f)
    f = click.option('-t', '--time-out', 'timeout', show_default=True, default=600, help='Default timeout for plugins.')(f)
    f = click.option('--end-time', callback=set_end_time, help='Plugins may optionally implement and use this. Defaults to now.')(f)
    f = click.option('--start-time', callback=set_start_time, help='Plugins may optionally implement and use this.')(f)
    f = click.option('-r', '--report', type=click.STRING, show_default=True, default='StdOut', help='Report Plugin to run.')(f)
    f = click.option('--hours', type=click.INT, default=24, show_default=True, callback=set_relative_start_time,
                     help='Sets start-time to X hours ago. Plugins may optionally implement and use this.')(f)
    f = click.option('--plugin-dir', default=default_plugin_dir, show_default=True, help=f'Import all plugins from this directory.')(f)
    f = click.option('-p', '--pid', type=click.INT, help='Pid to investigate.')(f)

    # Required for parsing dynamics arguments
    f = click.pass_context(f)
    f = click.command(context_settings=dict(ignore_unknown_options=True, allow_extra_args=True, help_option_names=['-h', '--help']))(f)
    return f 
Example #5
Source File: _options.py    From dcos-e2e with Apache License 2.0 5 votes vote down vote up
def vm_memory_mb_option(command: Callable[..., None]) -> Callable[..., None]:
    """
    An option decorator for the amount of memory given to each VM.
    """
    backend = Vagrant()
    function = click.option(
        '--vm-memory-mb',
        type=click.INT,
        default=backend.vm_memory_mb,
        show_default=True,
        help='The amount of memory to give each VM.',
    )(command)  # type: Callable[..., None]
    return function 
Example #6
Source File: cluster_size.py    From dcos-e2e with Apache License 2.0 5 votes vote down vote up
def masters_option(command: Callable[..., None]) -> Callable[..., None]:
    """
    An option decorator for the number of masters.
    """
    function = click.option(
        '--masters',
        type=click.INT,
        default=1,
        show_default=True,
        help='The number of master nodes.',
    )(command)  # type: Callable[..., None]
    return function 
Example #7
Source File: cluster_size.py    From dcos-e2e with Apache License 2.0 5 votes vote down vote up
def agents_option(command: Callable[..., None]) -> Callable[..., None]:
    """
    An option decorator for the number of agents.
    """
    function = click.option(
        '--agents',
        type=click.INT,
        default=1,
        show_default=True,
        help='The number of agent nodes.',
    )(command)  # type: Callable[..., None]
    return function 
Example #8
Source File: cluster_size.py    From dcos-e2e with Apache License 2.0 5 votes vote down vote up
def public_agents_option(command: Callable[..., None]) -> Callable[..., None]:
    """
    An option decorator for the number of agents.
    """
    function = click.option(
        '--public-agents',
        type=click.INT,
        default=1,
        show_default=True,
        help='The number of public agent nodes.',
    )(command)  # type: Callable[..., None]
    return function 
Example #9
Source File: parameters.py    From metaflow with Apache License 2.0 5 votes vote down vote up
def _check_type(self, val):
        # it is easy to introduce a deploy-time function that that accidentally
        # returns a value whose type is not compatible with what is defined
        # in Parameter. Let's catch those mistakes early here, instead of
        # showing a cryptic stack trace later.

        # note: this doesn't work with long in Python2 or types defined as
        # click types, e.g. click.INT
        TYPES = {bool: 'bool',
                 int: 'int',
                 float: 'float',
                 list: 'list'}

        msg = "The value returned by the deploy-time function for "\
              "the parameter *%s* field *%s* has a wrong type. " %\
              (self.parameter_name, self.field)

        if self.parameter_type in TYPES:
            if type(val) != self.parameter_type:
                msg += 'Expected a %s.' % TYPES[self.parameter_type]
                raise ParameterFieldTypeMismatch(msg)
            return str(val) if self.return_str else val
        else:
            if not is_stringish(val):
                msg += 'Expected a string.'
                raise ParameterFieldTypeMismatch(msg)
            return val 
Example #10
Source File: yatai_service.py    From BentoML with Apache License 2.0 4 votes vote down vote up
def add_yatai_service_sub_command(cli):
    # pylint: disable=unused-variable

    @cli.command(help='Start BentoML YataiService for model management and deployment')
    @click.option(
        '--db-url',
        type=click.STRING,
        help='Database URL following RFC-1738, and usually can include username, '
        'password, hostname, database name as well as optional keyword arguments '
        'for additional configuration',
        envvar='BENTOML_DB_URL',
    )
    @click.option(
        '--repo-base-url',
        type=click.STRING,
        help='Base URL for storing BentoML saved bundle files, this can be a filesystem'
        'path(POSIX/Windows), or a S3 URL, usually starting with "s3://"',
        envvar='BENTOML_REPO_BASE_URL',
    )
    @click.option(
        '--grpc-port',
        type=click.INT,
        default=50051,
        help='Port to run YataiService gRPC server',
        envvar='BENTOML_GRPC_PORT',
    )
    @click.option(
        '--ui-port',
        type=click.INT,
        default=3000,
        help='Port to run YataiService Web UI server',
        envvar='BENTOML_WEB_UI_PORT',
    )
    @click.option(
        '--ui/--no-ui',
        default=True,
        help='Run YataiService with or without Web UI, when running with --no-ui, it '
        'will only run the gRPC server',
        envvar='BENTOML_ENABLE_WEB_UI',
    )
    @click.option(
        '--s3-endpoint-url',
        type=click.STRING,
        help='S3 Endpoint URL is used for deploying with storage services that are '
        'compatible with Amazon S3, such as MinIO',
        envvar='BENTOML_S3_ENDPOINT_URL',
    )
    def yatai_service_start(
        db_url, repo_base_url, grpc_port, ui_port, ui, s3_endpoint_url
    ):
        start_yatai_service_grpc_server(
            db_url, repo_base_url, grpc_port, ui_port, ui, s3_endpoint_url
        )