Example #1
0
def add_logging_options(cmd: click.Command) -> click.Command:

    levels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL')

    cmd = optgroup.option(
        '--log-level',
        type=click.Choice(levels, case_sensitive=False),
        help='Amount of detail in build-time logging output.')(cmd)
    cmd = optgroup('Logging')(cmd)

    return cmd
Example #2
0
def add_build_options(cmd: click.Command) -> click.Command:
    """
    Decorator which adds all build-arguments to a click command
    """
    cmd = optgroup.option(
        '--distpath',
        default=DEFAULT_DISTPATH,
        type=click.Path(),
        help='Where to put the bundled app (default: ./dist)')(cmd)
    cmd = optgroup.option(
        '--workpath',
        default=DEFAULT_WORKPATH,
        type=click.Path(),
        help=
        'Where to put all the temporary work files - .log, .pyz, etc. (default: ./build)'
    )(cmd)
    cmd = optgroup.option(
        '-y',
        '--noconfirm',
        is_flag=True,
        default=False,
        help='Replace output directory without asking for confirmation')(cmd)
    cmd = optgroup.option(
        '--upx-dir',
        default=None,
        type=click.Path(),
        help='Path to UPX utility (default: search PATH)')(cmd)
    cmd = optgroup.option(
        '-a',
        '--ascii',
        is_flag=True,
        default=False,
        help='Don\'t include unicode support (default: included if available)'
    )(cmd)
    cmd = optgroup.option(
        '--clean',
        is_flag=True,
        default=False,
        help='Clean PyInstaller cache and remove temporary files before building'
    )(cmd)
    cmd = optgroup('Output Options', help='Help')(cmd)

    return cmd
Example #3
0
import click
from click_option_group import optgroup  # type: ignore
from click_skeleton import add_options

from musicbot.cli.options import config_string
from musicbot.musicdb import MusicDb


def sane_musicdb(ctx: click.Context, param: click.Parameter, value: str) -> MusicDb:
    if param.name:
        ctx.params[param.name] = value
    dsn = ctx.params.pop('dsn')
    musicdb = MusicDb.from_dsn(dsn)
    ctx.params['musicdb'] = musicdb
    return musicdb


musicdb_options = add_options(
    optgroup('MusicDB options'),
    optgroup.option(
        '--dsn',
        help='DSN to MusicBot EdgeDB',
        callback=config_string,
    ),
    optgroup.option(
        '--musicdb',
        expose_value=False,
        callback=sane_musicdb,
    ),
)
Example #4
0
def add_makespec_options(cmd: click.Command) -> click.Command:

    # Group: Where to search
    cmd = optgroup.option(
        '--additional-hooks-dir',
        'hookspath',
        multiple=True,
        type=click.Path(),
        help=
        'Additional path to search for hooks. This option can be used multiple times.'
    )(cmd)
    cmd = optgroup.option(
        '-p',
        '--paths',
        multiple=True,
        type=click.Path(),
        help='A path to search for imports (like using PYTHONPATH). '
        f'Multiple paths are allowed, separated by ``{os.pathsep}``, or '
        'use this option multiple times. Equivalent to '
        'supplying the ``pathex`` argument in the spec file.')(cmd)
    cmd = optgroup('Where to search')(cmd)

    # Group: What to bundle
    cmd = optgroup.option(
        '--runtime-hook',
        'runtime_hooks',
        multiple=True,
        type=click.File(),
        help='Path to a custom runtime hook file. A runtime hook is code that '
        'is bundled with the executable and is executed before any '
        'other code or module to set up special features of the runtime '
        'environment. This option can be used multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-metadata-recursive',
        multiple=True,
        metavar='MODULENAME',
        help=
        'Recursively collect all metadata from the specified package and it\'s dependencies. '
        'This option can be use multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-metadata',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help='Collect all metadata from the specified package. '
        'This option can be use multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-all',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help=
        'Collect all submodules, data files, metadata, and binaries from the specified package or module. '
        'This option can be use multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-binaries',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help='Collect all binaries from the specified package or module. '
        'This option can be use multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-datas',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help='Collect all data files from the specified package or module. '
        'This option can be use multiple times.')(cmd)
    cmd = optgroup.option(
        '--collect-submodules',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help='Collect all submodules from the specified package or module. '
        'This option can be used multiple times.')(cmd)
    cmd = optgroup.option(
        '--excluded-import',
        'excludes',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help=
        'Optional module (Python name) that will be ignored and not included, '
        'as if it was not found. This option can be used multiple times.')(cmd)
    cmd = optgroup.option(
        '-H',
        '--hidden-import',
        '--hiddenimport',
        'hiddenimports',
        multiple=True,
        metavar='MODULENAME',
        type=click.UNPROCESSED,
        callback=lambda _, _p, value: [x for x in value if is_ident(x)],
        help=
        'An import not visible in the code of the script(s) or it\'s dependencies. '
        'This option can be used multiple times.')(cmd)
    cmd = optgroup.option(
        '--add-binary',
        'binaries',
        multiple=True,
        type=click.UNPROCESSED,
        callback=validate_datas_or_binaries,
        metavar=f'SRC{os.pathsep}DEST',
        help=
        'Additional binary files to be added to the executable. See the `--add-data` '
        'option for more details. This option can be used multiple times.')(
            cmd)
    cmd = optgroup.option(
        '--add-data',
        'datas',
        multiple=True,
        type=click.UNPROCESSED,
        callback=validate_datas_or_binaries,
        metavar=f'SRC{os.pathsep}DEST',
        help=
        'Additional non-binary files or folders to be added to the executable. '
        'The path separator is platform specific, `os.pathsep` (which is `;` on '
        'Windows and `:` on most unix systems) is used. This option can be used '
        'multiple times.')(cmd)
    cmd = optgroup('What to bundle')(cmd)

    # Group: What to generate

    cmd = optgroup.option(
        '--upx-exclude',
        'upx_exclude',
        multiple=True,
        metavar='FILE',
        help=
        'Prevent a binary from being compressed when using upx. This is typically'
        ' used if upx corrupts certain binaries during compression. FILE is the '
        'filename of the binary without path. This option can be used multiple times.'
    )(cmd)
    cmd = optgroup.option(
        '--noupx',
        is_flag=True,
        default=False,
        help='Don\'t apply UPX regardless of availability')(cmd)
    cmd = optgroup.option(
        '-s',
        '--strip',
        is_flag=True,
        default=False,
        help=
        'Apply a symbol-table strip to the executable and shared libraries. '
        '(not recommended on Windows)')(cmd)
    cmd = optgroup.option(
        '-d',
        '--debug',
        multiple=True,
        type=click.Choice(['all', 'imports', 'bootloader', 'noarchive']),
        help=('Whether or not to build a debug version of your code. '
              'This option can be used multiple times to select '
              'several of the following items.\n\n'
              '- bootloader: enable the bootloader\'s logging feature, '
              '              which prints launch progress messages.\n\n'
              '- imports: specify the -v option to the bundled Python '
              'interpreter. See ``python --help -v`` for more information '
              'on the effects of this option.\n\n'
              '- noarchive: instead of storing all frozen Python source '
              'files inside the executable file, store them as files '
              'alongside it.'))(cmd)
    cmd = optgroup.option(
        '--splash',
        type=click.File(),
        help=
        '(EXPERIMENTAL) Add an splash screen with the image IMAGE_FILE to the application. '
        'The splash screen can display progress updates while unpacking.')(cmd)
    cmd = optgroup.option('--key',
                          metavar='KEY',
                          help='The key used to encrypt python bytecode')(cmd)
    cmd = optgroup.option(
        '-F/-D',
        '--onefile/--onedir',
        'onefile',
        default=False,
        help='Single file or single directory bundle (default: onedir)')(cmd)
    cmd = optgroup.option(
        '--specpath',
        type=click.Path(),
        default='.',
        help=
        'Folder to store the generated spec file in (default : current directory)'
    )(cmd)
    cmd = optgroup.option(
        '-n',
        '--name',
        type=click.STRING,
        required=False,
        metavar='NAME',
        help=
        'Name to assign to the bundled app and spec file (default: first script\'s basename)'
    )(cmd)
    cmd = optgroup('What to generate')(cmd)

    return cmd
Example #5
0
    help='Set verbosity to info and show execution timings',
    envvar=defaults.MB_TIMINGS,
    default=defaults.DEFAULT_TIMINGS,
    is_flag=True,
    show_default=True,
)

quiet_option = optgroup.option(
    '--quiet',
    '-q',
    help='Disable progress bars',
    envvar=defaults.MB_QUIET,
    default=defaults.DEFAULT_QUIET,
    is_flag=True,
    show_default=True,
)

options = [
    optgroup.group('Global options'),
    config_option,
    log_option,
    quiet_option,
    timings_option,
    optgroup('Verbosity', cls=MutuallyExclusiveOptionGroup),
    debug_option,
    info_option,
    warning_option,
    error_option,
    critical_option,
]
Example #6
0
import click
from beartype import beartype
from click_option_group import optgroup  # type: ignore
from click_skeleton import add_options
from click_skeleton.helpers import split_arguments

from musicbot.cli.options import (config_string, dry_option, sane_rating,
                                  sane_set)
from musicbot.defaults import (DEFAULT_ACOUSTID_API_KEY, DEFAULT_CHECKS,
                               DEFAULT_FLAT, DEFAULT_MAX_RATING,
                               DEFAULT_MIN_RATING)
from musicbot.file import File

logger = logging.getLogger(__name__)

music_options_group = optgroup('Music options')
keywords_option = optgroup.option(
    '--keywords',
    help='Keywords',
    multiple=True,
    callback=split_arguments,
)
artist_option = optgroup.option('--artist', help='Artist')
album_option = optgroup.option('--album', help='Album')
title_option = optgroup.option('--title', help='Title')
genre_option = optgroup.option('--genre', help='Genre')
track_option = optgroup.option('--track', help='Track number')
rating_option = optgroup.option(
    '--rating',
    help='Rating',
    type=click.FloatRange(DEFAULT_MIN_RATING, DEFAULT_MAX_RATING, clamp=True),
Example #7
0
    kwargs: dict[str, Any] = {}
    for field in fields_dict(LinkOptions):
        if field not in ctx.params:
            logger.debug(f"{field} param not in options")
            continue
        kwargs[field] = ctx.params[field]
        ctx.params.pop(field)

    link_options = LinkOptions(**kwargs)
    ctx.params[param.name] = link_options
    return link_options


link_options_options = add_options(
    optgroup('Link options'),
    optgroup.option(
        '--http/--no-http',
        help="Generate HTTP link",
        is_flag=True,
        default=DEFAULT_HTTP,
        show_default=True,
    ),
    optgroup.option(
        '--sftp/--no-sftp',
        help="Generate sFTP link",
        is_flag=True,
        default=DEFAULT_SFTP,
        show_default=True,
    ),
    # optgroup.option(
Example #8
0
    callback=config_string,
)

spotify_client_secret_option = optgroup.option(
    '--spotify-client-secret',
    help='Spotify client secret',
    envvar='MB_SPOTIFY_CLIENT_SECRET',
    default=DEFAULT_SPOTIFY_CLIENT_SECRET,
    callback=config_string,
)

spotify_token_option = optgroup.option(
    '--spotify-token',
    help='Spotify token',
    envvar='MB_SPOTIFY_TOKEN',
    expose_value=False,
    default=DEFAULT_SPOTIFY_TOKEN,
    callback=sane_spotify,
)

spotify_options = add_options(
    optgroup('Spotify options'),
    spotify_username_option,
    spotify_client_id_option,
    spotify_client_secret_option,
    spotify_cache_path_option,
    spotify_scope_option,
    spotify_redirect_uri_option,
    spotify_token_option,
)
Example #9
0
critical_option = optgroup.option(
    '--critical',
    help='Critical verbosity',
    envvar='MB_CRITICAL',
    default=DEFAULT_CRITICAL,
    is_flag=True,
)

quiet_option = optgroup.option(
    '-q', '--quiet/--no-quiet',
    help='Disable progress bars',
    envvar='MB_QUIET',
    default=DEFAULT_QUIET,
    is_flag=True,
    show_default=True,
)

config_options = add_options(
    optgroup('Global options'),
    config_option,
    log_option,
    quiet_option,
    color_option,
    optgroup('Verbosity', cls=MutuallyExclusiveOptionGroup),
    debug_option,
    info_option,
    warning_option,
    error_option,
    critical_option,
)
Example #10
0
shuffle_option = optgroup.option(
    '--shuffle',
    help='Randomize selection',
    default=DEFAULT_SHUFFLE,
    is_flag=True,
)

interleave_option = optgroup.option(
    '--interleave',
    help='Interleave tracks by artist',
    is_flag=True,
)

ordering_options = add_options(
    optgroup('Ordering options'),
    shuffle_option,
    interleave_option,
)

music_filter_options = add_options(
    optgroup('Filter options'),
    optgroup.option(
        '--name',
        help='Filter name',
        default=DEFAULT_NAME,
    ),
    optgroup.option(
        '--limit',
        help='Fetch a maximum limit of music',
        default=DEFAULT_LIMIT,