Esempio n. 1
0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser(
        description=(
            'Add git-clone tab completion for all-repos repositories.\n\n'
            'Add to .bash_profile:\n'
            '  `eval "$(all-repos-complete -C ~/.../all-repos.json --bash)"`'),
        formatter_class=argparse.RawDescriptionHelpFormatter,
        usage='%(prog)s [options] {--bash}',
    )
    cli.add_common_args(parser)
    mutex = parser.add_mutually_exclusive_group(required=True)
    mutex.add_argument('--bash', action='store_true')
    mutex.add_argument('--zsh', action='store_true')
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)

    print(f'__all_repos__repos_json={config.repos_filtered_path}')
    if args.bash:
        print(BASH)
    elif args.zsh:
        print(ZSH)
    else:
        raise NotImplementedError()
    return 0
Esempio n. 2
0
def main(argv: Sequence[str] | None = None) -> int:
    parser = argparse.ArgumentParser(
        description='Similar to a distributed `git grep ...`.',
        usage='%(prog)s [options] [GIT_GREP_OPTIONS]',
        add_help=False,
    )
    # Handle --help like normal, pass -h through to git grep
    parser.add_argument(
        '--help',
        action='help',
        help='show this help message and exit',
    )
    cli.add_common_args(parser)
    cli.add_repos_with_matches_arg(parser)
    cli.add_output_paths_arg(parser)
    args, rest = parser.parse_known_args(argv)

    config = load_config(args.config_filename)
    if args.repos_with_matches:
        return repos_matching_cli(config, rest)
    else:
        return grep_cli(
            config,
            rest,
            output_paths=args.output_paths,
            use_color=args.color,
        )
Esempio n. 3
0
def add_fixer_args(parser: argparse.ArgumentParser) -> None:
    cli.add_common_args(parser)

    mutex = parser.add_mutually_exclusive_group()
    mutex.add_argument(
        '--dry-run', action='store_true',
        help='show what would happen but do not push.',
    )
    mutex.add_argument(
        '-i', '--interactive', action='store_true',
        help='interactively approve / deny fixes.',
    )
    cli.add_jobs_arg(mutex, default=1)

    parser.add_argument(
        '--limit', type=int, default=None,
        help='maximum number of repos to process (default: unlimited).',
    )
    parser.add_argument(
        '--author',
        help=(
            'override commit author.  '
            'This is passed directly to `git commit`.  '
            "An example: `--author='Herp Derp <*****@*****.**>'`."
        ),
    )
    parser.add_argument(
        '--repos', nargs='*',
        help=(
            'run against specific repositories instead.  This is especially '
            'useful with `xargs autofixer ... --repos`.  This can be used to '
            'specify repositories which are not managed by `all-repos`.'
        ),
    )
Esempio n. 4
0
def main(argv=None):
    parser = argparse.ArgumentParser(
        description='List all cloned repository names.',
        usage='all-repos-list-repos [options]',
    )
    cli.add_common_args(parser)
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)
    for repo in config.get_cloned_repos():
        print(repo)
Esempio n. 5
0
def main(argv=None):
    parser = argparse.ArgumentParser(
        description='Similar to a distributed `git grep ...`.',
        usage='%(prog)s [options] [GIT_GREP_OPTIONS]',
    )
    cli.add_common_args(parser)
    cli.add_repos_with_matches_arg(parser)
    args, rest = parser.parse_known_args(argv)

    config = load_config(args.config_filename)
    if args.repos_with_matches:
        return repos_matching_cli(config, rest)
    else:
        return grep_cli(config, rest, use_color=args.color)
Esempio n. 6
0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser(
        description=(
            'Clone all the repositories into the `output_dir`.  If '
            'run again, this command will update existing repositories.'),
        usage='%(prog)s [options]',
    )
    cli.add_common_args(parser)
    cli.add_jobs_arg(parser)
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)

    repos = config.list_repos(config.source_settings)
    repos_filtered = {
        k: v
        for k, v in sorted(repos.items())
        if config.include.search(k) and not config.exclude.search(k)
    }

    # If the previous `repos.json` / `repos_filtered.json` files exist
    # remove them.
    for path in (config.repos_path, config.repos_filtered_path):
        if os.path.exists(path):
            os.remove(path)

    current_repos = set(_get_current_state(config.output_dir).items())
    filtered_repos = set(repos_filtered.items())

    # Remove old no longer cloned repositories
    for path, _ in current_repos - filtered_repos:
        _remove(config.output_dir, path)

    for path, remote in filtered_repos - current_repos:
        _init(config.output_dir, path, remote)

    fn = functools.partial(_fetch_reset, all_branches=config.all_branches)
    todo = [os.path.join(config.output_dir, p) for p in repos_filtered]
    with mapper.thread_mapper(args.jobs) as do_map:
        mapper.exhaust(do_map(fn, todo))

    # write these last
    os.makedirs(config.output_dir, exist_ok=True)
    with open(config.repos_path, 'w') as f:
        f.write(json.dumps(repos))
    with open(config.repos_filtered_path, 'w') as f:
        f.write(json.dumps(repos_filtered))
    return 0
Esempio n. 7
0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser(
        description='List all cloned repository names.',
        usage='all-repos-list-repos [options]',
    )
    cli.add_common_args(parser)
    cli.add_output_paths_arg(parser)
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)
    for repo in config.get_cloned_repos():
        if args.output_paths:
            print(os.path.join(config.output_dir, repo))
        else:
            print(repo)
    return 0
Esempio n. 8
0
def main(argv=None):
    parser = argparse.ArgumentParser(
        description=(
            'Similar to a distributed `git ls-files | grep -P PATTERN`.'),
        usage='%(prog)s [options] PATTERN',
    )
    cli.add_common_args(parser)
    cli.add_repos_with_matches_arg(parser)
    parser.add_argument('pattern', help='the python regex to match.')
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)
    if args.repos_with_matches:
        return find_files_repos_cli(config, args.pattern, use_color=args.color)
    else:
        return find_files_cli(config, args.pattern, use_color=args.color)
Esempio n. 9
0
def main(argv: Optional[Sequence[str]] = None) -> int:
    parser = argparse.ArgumentParser(
        description='Run tox4 on all cloned repositories.',
        usage='python tox.py -C configfile',
    )
    cli.add_common_args(parser)
    cli.add_output_paths_arg(parser)
    args = parser.parse_args(argv)

    config = load_config(args.config_filename)
    results = {
        "notox": [],
        "successful": [],
        "problems": [],
    }

    number_of_repos = len(config.get_cloned_repos())

    for i, repo in enumerate(list(config.get_cloned_repos())):
        if repo == "zopefoundation/zopetoolkit":  # causes buildout/setuptools endless loop
            continue
        if repo == "plone/plone.memoize":  # causes buildout/setuptools endless loop
            continue
        path_repo = os.path.join(config.output_dir, repo)
        path_tox = os.path.join(path_repo, "tox.ini")
        if os.path.exists(path_tox):
            print(f"about to run tox for {repo}, {i+1} of {number_of_repos}")
            run = subprocess.run(["tox4", "-e py38", "-c", path_tox],
                                 stdout=subprocess.DEVNULL)
            if run.returncode == 0:
                print(f"tox4 run successful for {repo}")
                results["successful"].append(repo)
            else:
                print(f"tox4 run failed for {repo}")
                results["problems"].append(repo)

        else:
            print(f"{repo} does not contain a tox configuration. Boo!")
            results["notox"].append(repo)

    print(f'notox: {len(results["notox"])}')
    print(f'{results["notox"]}')
    print(f'successful: {len(results["successful"])}')
    print(f'{results["successful"]}')
    print(f'problems: {len(results["problems"])}')
    print(f'{results["problems"]}')
    return 0