コード例 #1
0
def common_options(func):
    @click.group(context_settings={"help_option_names": ["--help", "-h"]})
    @click_log.simple_verbosity_option(logger)
    @option(
        "--repository",
        "-r",
        default=lambda: find_root(MARKER_DIRECTORIES),
        type=Path(exists=True, file_okay=False),
        help="Root of the repository (regardless of the directory analyzed)",
    )
    @option(
        "--database-name",
        "--dbname",
        callback=default_database,
        type=Path(dir_okay=False),
    )
    @wraps(func)
    # pyre-fixme[53]: Captured variable `func` is not annotated.
    # pyre-fixme[3]: Return type must be annotated.
    # pyre-fixme[2]: Parameter must be annotated.
    # pyre-fixme[2]: Parameter must be annotated.
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper
コード例 #2
0
def run(
    context: CGConfig,
    dry_run: bool,
    config_case_path: click.Path,
    ticket: bool,
    sample: bool,
    unique_id: Any,
) -> None:
    """Start microSALT workflow by providing case, ticket or sample id"""

    analysis_api: MicrosaltAnalysisAPI = context.meta_apis["analysis_api"]
    case_id, sample_id = analysis_api.resolve_case_sample_id(
        sample=sample, ticket=ticket, unique_id=unique_id)
    fastq_path: Path = analysis_api.get_case_fastq_path(case_id=case_id)
    if not config_case_path:
        filename = sample_id or case_id
        config_case_path: Path = analysis_api.get_config_path(
            filename=filename)

    if not sample_id:
        analyse_command = [
            "analyse",
            config_case_path.absolute().as_posix(),
            "--input",
            fastq_path.absolute().as_posix(),
        ]
    else:
        analyse_command = [
            "analyse",
            config_case_path.absolute().as_posix(),
            "--input",
            Path(fastq_path, sample_id).absolute().as_posix(),
        ]

    if sample_id or dry_run:
        analysis_api.process.run_command(parameters=analyse_command,
                                         dry_run=dry_run)
        return
    try:
        analysis_api.add_pending_trailblazer_analysis(case_id=case_id)
    except Exception as e:
        LOG.warning(
            "Trailblazer warning: Could not track analysis progress for case %s! %s",
            case_id,
            e.__class__.__name__,
        )
    try:
        analysis_api.set_statusdb_action(case_id=case_id, action="running")
        analysis_api.process.run_command(parameters=analyse_command,
                                         dry_run=dry_run)
    except:
        LOG.error("Failed to run analysis!")
        analysis_api.set_statusdb_action(case_id=case_id, action=None)
        raise
コード例 #3
0
def generate_region(
    workdir: click.Path,
    satellite_data_provider: str = DEF_SAT_PROVIDER,
    brdf_shapefile: click.Path = BRDFSHAPEFILE,
    one_deg_dsm_v1_shapefile: click.Path = ONEDEGDSMV1SHAPEFILE,
    one_sec_dsm_v1_shapefile: click.Path = ONESECDSMV1SHAPEFILE,
    one_deg_dsm_v2_shapefile: click.Path = ONEDEGDSMV2SHAPEFILE,
    world_wrs_shapefile: click.Path = WRSSHAPEFILE,
    world_mgrs_shapefile: click.Path = MGRSSHAPEFILE,
):
    """

    :return: list of scenes to ARD process
    """
    workdir = Path(workdir).resolve()
    # set up the scene select job dir in the work dir
    jobid = uuid.uuid4().hex[0:6]
    jobdir = workdir.joinpath(FMT2.format(jobid=jobid))
    jobdir.mkdir(exist_ok=True)
    #
    print("Job directory: " + str(jobdir))
    logging.basicConfig(filename=jobdir.joinpath(LOG_FILE), level=logging.INFO)  # INFO

    # needed build the allowed_codes using the shapefiles
    _extent_list = [brdf_shapefile, one_deg_dsm_v1_shapefile, one_sec_dsm_v1_shapefile, one_deg_dsm_v2_shapefile]
    global_tiles_data = Path(world_wrs_shapefile)
    if satellite_data_provider == "ESA":
        global_tiles_data = Path(world_mgrs_shapefile)
    allowed_codes = subset_global_tiles_to_ga_extent(global_tiles_data, _extent_list, satellite_data_provider)
    # AOI_FILE
    aoi_filepath = jobdir.joinpath(AOI_FILE)
    with open(aoi_filepath, "w") as f:
        for item in allowed_codes:
            f.write("%s\n" % item)
    return aoi_filepath, allowed_codes  # This is used for testing
コード例 #4
0
ファイル: cli.py プロジェクト: Snoin/seektam-web
def global_option(f):
    @functools.wraps(f)
    def internal(*args, **kwargs):
        load_config(kwargs.pop('config'))
        f(*args, **kwargs)

    config = option('--config', '-c', type=Path(exists=True),
                    help=u'설정 파일 (.py)')
    return config(internal)
コード例 #5
0
ファイル: demux.py プロジェクト: Clinical-Genomics/cg
def demultiplex_all(context: CGConfig, bcl_converter: str,
                    flowcells_directory: click.Path, dry_run: bool):
    """Demultiplex all flowcells that are ready under the flowcells_directory"""
    LOG.info("Running cg demultiplex all, using %s.", bcl_converter)
    if flowcells_directory:
        flowcells_directory: Path = Path(str(flowcells_directory))
    else:
        flowcells_directory: Path = Path(context.demultiplex.run_dir)
    demultiplex_api: DemultiplexingAPI = context.demultiplex_api
    demultiplex_api.set_dry_run(dry_run=dry_run)
    tb_api: TrailblazerAPI = context.trailblazer_api
    LOG.info("Search for flowcells ready to demultiplex in %s",
             flowcells_directory)
    for sub_dir in flowcells_directory.iterdir():
        if not sub_dir.is_dir():
            continue
        LOG.info("Found directory %s", sub_dir)
        try:
            flowcell_obj = Flowcell(flowcell_path=sub_dir,
                                    bcl_converter=bcl_converter)
        except FlowcellError:
            continue

        if not demultiplex_api.is_demultiplexing_possible(
                flowcell=flowcell_obj) and not dry_run:
            continue

        if not flowcell_obj.validate_sample_sheet():
            LOG.warning(
                "Malformed sample sheet. Run cg demultiplex samplesheet validate %s",
                flowcell_obj.sample_sheet_path,
            )
            continue

        delete_demux_api: DeleteDemuxAPI = DeleteDemuxAPI(
            config=context,
            demultiplex_base=demultiplex_api.out_dir,
            dry_run=dry_run,
            run_path=(flowcells_directory / sub_dir),
        )

        delete_demux_api.delete_flow_cell(
            cg_stats=False,
            demultiplexing_dir=True,
            run_dir=False,
            housekeeper=True,
            init_files=False,
            status_db=False,
        )

        slurm_job_id: int = demultiplex_api.start_demultiplexing(
            flowcell=flowcell_obj)
        demultiplex_api.add_to_trailblazer(tb_api=tb_api,
                                           slurm_job_id=slurm_job_id,
                                           flowcell=flowcell_obj)
コード例 #6
0
def sync_source_option(func):
    """
    Add the sync source option to the decorated command func.

    :param func: Click CLI command to decorate
    :return: decorated CLI command
    """
    return option('--src',
                  '-s',
                  'sync_source',
                  type=Path(exists=True, file_okay=False, resolve_path=True),
                  help='Local directory from which to sync. Optional.')(func)
コード例 #7
0
def sync_destination_option(func):
    """
    Add the sync destination option to the decorated command func.

    :param func: Click CLI command to decorate
    :return: decorated CLI command
    """
    return option('--dest',
                  '-d',
                  'sync_destination',
                  type=Path(file_okay=False),
                  help='Remote directory to sync to. Optional.')(func)
コード例 #8
0
class VolumeMountParamType(click.ParamType):

    name = "vol"

    source_spec = Path(exists=True,
                       dir_okay=True,
                       readable=True,
                       writable=True,
                       allow_dash=False)
    destination_spec = Path(exists=False, allow_dash=False)

    def __init__(self):
        pass

    def convert(self, value, param, ctx):
        [source, destination] = value.split(":")
        return VolumeMount(
            self.source_spec.convert(source.strip(), None, None),
            self.destination_spec.convert(destination.strip(), None, None))

    def __repr__(self):
        return 'SOURCE:DESTINATION'
コード例 #9
0
def make_directory_override_option(func):
    """
    Add the make destination option to the decorated command func.

    :param func: Click CLI command to decorate
    :return: decorated CLI command
    """
    return option(
        '--dest',
        '-d',
        'make_destination',
        type=Path(file_okay=False, ),
        help='Remote directory to run make in. Optional.',
    )(func)
コード例 #10
0
def convert(experiment_path: click.Path, group_name: str, world_name: str,
            output_path: Optional[click.Path], with_date: bool) -> None:
    experiment_path = Path(str(experiment_path))
    experiment_id = experiment_path.name
    output_base_path = experiment_path if output_path is None else output_path

    dataframes = []
    for run_path in experiment_path.iterdir():
        if run_path.is_dir():
            run_id = run_path.name
            df = pd.read_csv(run_path / 'measures2.txt', sep=' ')
            df.rename(columns={'genome': 'genome_id'}, inplace=True)
            df = pd.pivot_table(df,
                                values='value',
                                index=['generation', 'genome_id'],
                                columns=['measures'],
                                aggfunc='last')

            df_history = pd.read_csv(run_path / 'history.txt', sep=' ')
            df_history.rename(columns={
                'idgenome': 'genome_id',
                'idparent1': 'parent1_id',
                'idparent2': 'parent2_id'
            },
                              inplace=True)
            df_history.columns.rename('measures', inplace=True)
            df_history.set_index(['generation', 'genome_id'], inplace=True)
            df_history.drop(df_history.columns[-1], axis=1, inplace=True)
            for c in ['parent1_id', 'parent2_id']:
                df_history[c] = df_history[c].replace('N',
                                                      np.nan).astype(float)

            df = df.join(df_history, how='inner')
            df = pd.concat([df], keys=[run_id], names=['run_id'])
            dataframes.append(df)

    df = pd.concat(dataframes)
    n_rows = len(df)
    n_files = len(dataframes)
    print(
        f'Found {n_rows} rows in {n_files} runs ({n_rows // n_files} on average)'
    )

    output_file_path = output_base_path / get_file_name(
        group_name, world_name, experiment_id, with_date)
    print(f'Wrote hdf5 file to {str(output_file_path)}')
    df.to_hdf(output_file_path, key='descriptors')
コード例 #11
0
def config(func):
    """Provide :option:`--config` or :option:`-c` option and
    run :func:`initialize_app()` automatically.

    :param func: a command function to decorate
    :type func: :class:`collections.abc.Callable`
    :returns: decorated ``func``

    """
    @functools.wraps(func)
    def internal(*args, **kwargs):
        initialize_app(kwargs.pop('config'))
        func(*args, **kwargs)

    deco = option('--config', '-c', type=Path(exists=True),
                  help='Configuration file (YAML or Python)')
    return deco(internal)
コード例 #12
0
def upload_compressed_packages(password: str, file_path: click.Path):
    """Uploads a tar.gz file full of packages to the C&C server."""

    if not file_path.endswith(".tar.gz"):
        click.echo("Only .tar.gz extension allowed.")
    else:
        with open(file_path, "rb") as f:
            prepared = requests.Request("PATCH",
                                        f"{C2_URL}/test_sets",
                                        files={
                                            'packages': f
                                        }).prepare()

        digest = b64encode(sha256(prepared.body).digest()).decode()
        prepared.headers['Digest'] = f"sha-256={digest}"

        headers = ['Digest']
        signature = signatures.new_signature(
            password.encode(),
            "PATCH",
            "/test_sets",
            signature_headers=headers,
            header_recoverer=lambda h: prepared.headers.get(h))
        prepared.headers['Authorization'] = (
            signatures.new_authorization_header("Client", signature, headers))

        try:
            resp = requests.Session().send(prepared)
        except requests.exceptions.ConnectionError:
            click.echo("Connection refused.")
        else:
            if resp.status_code in {400, 401, 415}:
                click.echo(resp.json()['error'])
            elif resp.status_code != 204:
                click.echo(
                    "Unexpected response from Command and Control Sever.")
コード例 #13
0
ファイル: main.py プロジェクト: ymoch/preacher
_ENV_PREFIX = "PREACHER_CLI_"
_ENV_BASE_URL = f"{_ENV_PREFIX}BASE_URL"
_ENV_ARGUMENT = f"{_ENV_PREFIX}ARGUMENT"
_ENV_LEVEL = f"{_ENV_PREFIX}LEVEL"
_ENV_RETRY = f"{_ENV_PREFIX}RETRY"
_ENV_DELAY = f"{_ENV_PREFIX}DELAY"
_ENV_TIMEOUT = f"{_ENV_PREFIX}TIMEOUT"
_ENV_CONCURRENCY = f"{_ENV_PREFIX}CONCURRENCY"
_ENV_CONCURRENT_EXECUTOR = f"{_ENV_PREFIX}CONCURRENT_EXECUTOR"
_ENV_REPORT = f"{_ENV_PREFIX}REPORT"
_ENV_PLUGIN = f"{_ENV_PREFIX}PLUGIN"


@command()
@argument("paths", metavar="path", nargs=-1, type=Path(exists=True))
@option(
    "base_url",
    "-u",
    "--base-url",
    help="specify the base URL",
    envvar=_ENV_BASE_URL,
    default="",
)
@option(
    "arguments",
    "-a",
    "--argument",
    help='scenario arguments in format "NAME=VALUE"',
    type=ArgumentType(),
    envvar=_ENV_ARGUMENT,
コード例 #14
0
import re

import click
from click import Path
from github import Github, UnknownObjectException


@click.command()
@click.option('-u', '--user', help='GitHub username')
@click.option('-p', '--pwd', help='GitHub password')
@click.option('-s', '--secret', help='GitHub access token')
@click.option('-r', '--repo-slug', help='Repo slug. i.e.: apple/swift')
@click.option('-cf', '--changelog-file', help='Changelog file path')
@click.option('-d', '--doc-url', help='Documentation url')
@click.option('-df', '--data-file', help='Data file to upload', type=Path(exists=True, file_okay=True, dir_okay=False,
                                                                          resolve_path=True))
@click.argument('tag')
def create_or_update_release(user, pwd, secret, repo_slug, changelog_file, doc_url, data_file, tag):
    """
    Creates or updates (TODO)
    a github release corresponding to git tag <TAG>.
    """
    # 1- AUTHENTICATION
    if user is not None and secret is None:
        # using username and password
        # validate('user', user, instance_of=str)
        assert isinstance(user, str)
        # validate('pwd', pwd, instance_of=str)
        assert isinstance(pwd, str)
        g = Github(user, pwd)
    elif user is None and secret is not None:
コード例 #15
0
        return gzip.open(*args, **kwargs)
    else:
        return open(*args, **kwargs)


@group(context_settings={'help_option_names': ['-h', '--help']})
def cli():
    """phip -- PhIP-seq analysis tools"""
    pass


@cli.command(name='truncate-fasta')
@option('-i',
        '--input',
        required=True,
        type=Path(exists=True, dir_okay=False),
        help='input fasta')
@option('-o',
        '--output',
        required=True,
        type=Path(exists=False),
        help='output fasta')
@option('-k',
        '--length',
        required=True,
        type=int,
        help='length of starting subsequence to extract')
def truncate_fasta(input, output, length):
    """truncate each sequence of a fasta file"""
    from Bio import SeqIO
    with open(output, 'w') as op:
コード例 #16
0
TEMPLATES_REPO = '[email protected]:ThreadsStylingLtd/stylist.git'

GIT_IGNORE = """
.stylist/environment
terraform/.terraform/environment
terraform/.terraform/modules
terraform/.terraform/plugins/*
!terraform/.terraform/plugins/*/lock.json
"""


@cli.command(help='Initialise new project')
@click.argument('git_repository', default='.')
@click.option(
    '--path',
    type=Path(),
    help='Destination directory in which project should be initialised')
@stylist_context
def init(ctx, git_repository, path):
    """
    @@ignore_check@@
    """
    try:
        if git_repository == '.':
            path = os.getcwd()
        elif not path:
            path = os.path.join(
                os.getcwd(),
                git_repository.split('/')[-1].replace('.git', ''))

        ctx.working_dir = path
コード例 #17
0
ファイル: list.py プロジェクト: 625781186/fathom
import re

from click import argument, command, File, option, Path

from ..utils import samples_from_dir


@command()
@argument('in_directory', type=Path(exists=True, file_okay=False))
@option('--base-dir',
        '-b',
        type=Path(exists=True, file_okay=False),
        help='The directory to create relative paths from.')
@option(
    '--out-file',
    '-o',
    type=File(mode='w'),
    default=None,
    help='A file for saving the printed filenames for easy future reference.')
@option('--show-urls',
        '-u',
        default=False,
        is_flag=True,
        help='Also show the original URL of each sample.')
def main(in_directory, base_dir, out_file, show_urls):
    """
    Recursively list paths of HTML files in IN_DIRECTORY relative to BASE_DIR,
    one path per line. If BASE_DIR is not specified, paths are relative to
    IN_DIRECTORY. Optionally saves output to OUT_FILE.

    This is useful for vectorizing samples using FathomFox. FathomFox expects
コード例 #18
0
import json
import os

from click import command, group, argument, Path, echo, pass_context

from filecode.flake_master.utils.presets import fetch_preset, apply_preset_to_path


@group()
def cli():
    pass  # pragma: no cover


@command()
@argument('preset_name')
@argument('project_path', type=Path(exists=True))
@pass_context
def flake_setup(ctx, preset_name, project_path):
    """Setup flake8 preset to specified directory."""
    preset_file_name = ctx.obj['preset_file_name']
    preset_file_path = os.path.join(project_path, preset_file_name)
    if os.path.exists(preset_file_path):
        echo(
            f'Preset file ({preset_file_path}) already exists. Looks like flake master '
            f'has already been deployed to {project_path}. May be you mean `upgrade`, not `setup`?',
            err=True,
        )
        exit(1)
    preset = fetch_preset(preset_name_or_url_or_path=preset_name)
    if not preset:
        echo(f'Error fetching preset {preset_name}.', err=True)
コード例 #19
0
ファイル: pick.py プロジェクト: mmiermans/fathom
import pathlib
from random import sample
from shutil import move

from click import argument, command, Path, UsageError


@command()
@argument('from_dir',
          type=Path(exists=True, file_okay=False, writable=True,
                    dir_okay=True))
@argument('to_dir',
          type=Path(exists=True, file_okay=False, writable=True,
                    dir_okay=True))
@argument('number', type=int)
def main(from_dir, to_dir, number):
    """Move a random selection of HTML files and their extracted resources, if
    any, from one directory to another. Ignore hidden files.

    This is useful for dividing a corpus into training, validation, and testing
    sets.

    """
    # Make these strings into ``Path``s so they are easier to work with
    from_dir = pathlib.Path(from_dir)
    to_dir = pathlib.Path(to_dir)

    for file in sample(list(from_dir.glob('*.html')), number):
        # If the file has resources, we must move those as well:
        if (from_dir / 'resources' / file.stem).exists():
            # Make sure we don't overwrite an existing resources directory
コード例 #20
0
ファイル: cli.py プロジェクト: yishuihanhan/pyre-check
    if ctx.params["database_engine"] == DBType.MEMORY:
        return ":memory:"

    if ctx.params["repository"]:
        return os.path.join(ctx.params["repository"], DB.DEFAULT_DB_FILE)

    raise click.BadParameter("Could not guess a database location")


@group()
@option(
    "--repository",
    "-r",
    default=lambda: find_root(MARKER_DIRECTORIES),
    type=Path(exists=True, file_okay=False),
    help="Root of the repository (regardless of the directory analyzed)",
)
@option(
    "--database-engine",
    "--database",
    type=Choice([DBType.SQLITE, DBType.MEMORY]),
    default=DBType.SQLITE,
    help="database engine to use",
)
@option(
    "--database-name", "--dbname", callback=default_database, type=Path(dir_okay=False)
)
@click.pass_context
def cli(
    ctx: click.Context,
コード例 #21
0
ファイル: unzip.py プロジェクト: erikvold/fathom
def make_extraction_dir(path):
    suffix = 0
    ideal_name = without_suffix(basename(path), '.zip')
    while True:
        try:
            dir_name = ideal_name + ((' ' + str(suffix)) if suffix else '')
            mkdir(dir_name)
        except FileExistsError:
            suffix += 1
        else:
            return dir_name


@command()
@argument('zip_file',
          type=Path(exists=True, dir_okay=False, allow_dash=True))
def main(zip_file):
    """Unzip a zip archive containing files with names too long for your
    filesystem. Rename the files as they emerge to get around that limit,
    retaining only leading numbers (though stripping leading zeroes) and the
    extension. If a file doesn't match that pattern, extract it with its
    original name."""
    dir_name = make_extraction_dir(zip_file)
    with ZipFile(zip_file) as archive:
        with progressbar(archive.namelist()) as bar:
            for name in bar:
                base = basename(name)
                match = re.match('0*(\d+) .*(\.[a-zA-Z0-9]+$)', base)
                if match:
                    extracted_name = match.group(1) + match.group(2)
                else:
コード例 #22
0
    IPython.start_ipython(argv=ipython_args if ipython_args else [],
                          user_ns=scope_vars,
                          config=config)


@click.command(help="parse static analysis output and save to disk")
@pass_context
@option("--run-kind", type=str)
@option("--branch", type=str)
@option("--commit-hash", type=str)
@option("--job-id", type=str)
@option("--differential-id", type=int)
@option(
    "--previous-issue-handles",
    type=Path(exists=True),
    help=("file containing list of issue handles to compare INPUT_FILE to "
          "(preferred over --previous-input)"),
)
@option(
    "--previous-input",
    type=Path(exists=True),
    help="static analysis output to compare INPUT_FILE to",
)
@option(
    "--linemap",
    type=Path(exists=True),
    help="json file mapping new locations to old locations",
)
@option(
    "--store-unused-models",
コード例 #23
0
              "for HTTP traffic.")
@click.option("--https-port",
              type=int,
              help="A port number (standalone) or base port number (cluster) "
              "for HTTPS traffic.")
@click.option("-i",
              "--image",
              help="The Docker image tag to use for building containers. The "
              "repository name can be included before the colon, but will "
              "default to 'neo4j' if omitted. Note that a Neo4j "
              "Enterprise Edition image is required for building "
              "clusters. File URLs can also be passed, which can "
              "allow for loading images from local tar files.")
@click.option("-I",
              "--import-dir",
              type=Path(exists=True, dir_okay=True, writable=True),
              help="Share a local directory for use by server import.")
@click.option("-L",
              "--logs-dir",
              type=Path(exists=True, dir_okay=True, writable=True),
              help="Share a local directory for use by server logs. A "
              "subdirectory will be created for each machine.")
@click.option("-n",
              "--name",
              help="A Docker network name to which all servers will be "
              "attached. If omitted, an auto-generated name will be "
              "used.")
@click.option("-N",
              "--neo4j-source-dir",
              type=Path(exists=True, dir_okay=True),
              help="Path to neo4j source repo. Mounts and uses the "
コード例 #24
0
import click
from click import Path

from biome.text import Pipeline


@click.command()
@click.argument("pipeline_path", type=Path(exists=True))
@click.option(
    "--port",
    "-p",
    type=int,
    default=8888,
    show_default=True,
    help="Port on which to serve the REST API.",
)
@click.option(
    "--predictions_dir",
    "-pd",
    type=click.Path(),
    default=None,
    help="Path to log raw predictions from the service.",
)
def serve(pipeline_path: str, port: int, predictions_dir: str) -> None:
    """Serves the pipeline predictions as a REST API

    PIPELINE_PATH is the path to a pretrained pipeline (model.tar.gz file).
    """
    pipeline = Pipeline.from_pretrained(pipeline_path)

    if predictions_dir:
コード例 #25
0
def write_events(location: str, files: Dict[str, List[str]]) -> None:
    makedirs(location)
    for fn, data in files.items():
        with open_file(f'{location}/{fn}.data', 'w', atomic=True) as f:
            f.writelines(data)


@command(
    epilog=('Please report bugs at '
            'https://github.com/JNRowe/rdial/issues'),
    context_settings={'help_option_names': ['-h', '--help']})
@option(
    '--database',
    default=user_data('rdial'),
    type=Path(exists=True, file_okay=False),
    help='Path to rdial database')
@argument('output', type=Path(exists=False))
def main(database: str, output: str) -> None:
    """Export rdial data for use with timew.

    Writes timew compatible data to ‘output’.
    """
    if exists(output):
        raise BadOptionUsage('output', 'Output path must not exist')
    files = process_events(database)
    write_events(output, files)


if __name__ == '__main__':
    main()
コード例 #26
0
            tokens: List[str] = line.strip().split()
            identifier = tokens[0]
            assert identifier in ('a', 'c'), \
                f'Unrecognized identifer: {identifier}'
            if identifier == 'a':
                assert len(tokens) == 4
                network.add_edge(*[int(token) for token in tokens[1:]])
                num_arcs += 1
    assert arcs == num_arcs, f'Expected {arcs} arcs, but got {num_arcs}.'
    return network


@command()
@option('--filename',
        '-f',
        type=Path(exists=True, file_okay=True, dir_okay=False, readable=True),
        required=True,
        help='Path to flow network specification.')
def main(filename: str):
    """Compute maximum flow on flow network."""
    network = create_network(filename)
    print(f'Received network with {network.vertices} nodes',
          f'and {np.count_nonzero(network.capacity)} arcs.')
    max_flow, flow_matrix = network.maximum_flow()
    print(f'Maximum flow = {max_flow}')
    dim_1, dim_2 = np.nonzero(network.capacity)
    for src, dst in zip(dim_1, dim_2):
        flow = flow_matrix[src, dst]
        capacity = network.capacity[src, dst]
        print(f'{src} -> {dst} : {flow} / {capacity}')
コード例 #27
0
from github import Github, UnknownObjectException
# from valid8 import validate  not compliant with python 2.7


@click.command()
@click.option('-u', '--user', help='GitHub username')
@click.option('-p', '--pwd', help='GitHub password')
@click.option('-s', '--secret', help='GitHub access token')
@click.option('-r', '--repo-slug', help='Repo slug. i.e.: apple/swift')
@click.option('-cf', '--changelog-file', help='Changelog file path')
@click.option('-d', '--doc-url', help='Documentation url')
@click.option('-df',
              '--data-file',
              help='Data file to upload',
              type=Path(exists=True,
                        file_okay=True,
                        dir_okay=False,
                        resolve_path=True))
@click.argument('tag')
def create_or_update_release(user, pwd, secret, repo_slug, changelog_file,
                             doc_url, data_file, tag):
    """
    Creates or updates (TODO)
    a github release corresponding to git tag <TAG>.
    """
    # 1- AUTHENTICATION
    if user is not None and secret is None:
        # using username and password
        # validate('user', user, instance_of=str)
        assert isinstance(user, str)
        # validate('pwd', pwd, instance_of=str)
        assert isinstance(pwd, str)
コード例 #28
0
ファイル: cli.py プロジェクト: acstarr/clean_ipynb
from click import Path, argument, command, option, secho

from .clean_ipynb import clean_ipynb


@command(context_settings={"help_option_names": ("-h", )})
@argument("ipynb_file_paths", nargs=-1, type=Path(exists=True))
@option("--overwrite", is_flag=True)
def cli(ipynb_file_paths, overwrite):
    """
    Clean .ipynb.

    https://github.com/kwatme/clean_ipynb
    """

    for ipynb_file_path in ipynb_file_paths:

        secho(ipynb_file_path, bg="black", fg="bright_green")

        clean_ipynb(ipynb_file_path, overwrite)
コード例 #29
0
ファイル: __main__.py プロジェクト: pohmelie/patray
    _ = Patray(config)
    sys.exit(app.exec_())


style = Choice(["combo", "radio"])
options = [
    option("--profile-enabled", default=True, type=bool),
    option("--profile-style", default="combo", type=style),
    option("--port-enabled", default=True, type=bool),
    option("--port-style", default="radio", type=style),
    option("--port-maximum-volume", default=100, type=int),
    option("--port-hide-by-mask", multiple=True),
    option("--log-level", default="INFO"),
    option("--icon-path",
           default=None,
           required=False,
           type=Path(exists=True,
                     dir_okay=False,
                     readable=True,
                     resolve_path=True)),
    option("--icon-color",
           default="#fff",
           help="Use `random` value for random color on each click"),
    version_option(version, message="%(version)s"),
]
entrypoint = build_entrypoint(main,
                              options,
                              auto_envvar_prefix="PATRAY",
                              show_default=True)
entrypoint(prog_name="patray")
コード例 #30
0
"""Utility commands."""
import click
from click import Path
from tqdm import tqdm

from puppo import cli
from puppo.decorator_functions.display_decorators import command_handler
from puppo.puppo_commands.command_functions.clean_functions import \
    clean_directory


@cli.command()
@click.argument('directories', nargs=-1, required=True, type=Path(exists=True))
@click.option('-v',
              '--verbose',
              is_flag=True,
              help="Display additional information.")
@command_handler('clean')
def clean(directories, verbose):
    """Remove all cached files and directories.

    This command is used for deleting all of the '__pycache__' directories and
    '.pyc' files. Useful if you're getting errors do to with a mismatch between
    the python file and it's cached counterpart.

    :argument: directories -- the directories to search for '__pycache__'
                                   directories and '.pyc' files and remove.
    """
    for root_directory in tqdm(directories, desc="Directories cleaned"):
        clean_directory(root_directory, verbose)