当前位置: 首页>>代码示例>>Python>>正文


Python repository.Repository类代码示例

本文整理汇总了Python中pre_commit.repository.Repository的典型用法代码示例。如果您正苦于以下问题:Python Repository类的具体用法?Python Repository怎么用?Python Repository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Repository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_repository

def _update_repository(repo_config, runner):
    """Updates a repository to the tip of `master`.  If the repository cannot
    be updated because a hook that is configured does not exist in `master`,
    this raises a RepositoryCannotBeUpdatedError

    Args:
        repo_config - A config for a repository
    """
    repo = Repository.create(repo_config, runner.store)

    with cwd(repo.repo_path_getter.repo_path):
        cmd_output('git', 'fetch')
        head_sha = cmd_output('git', 'rev-parse', 'origin/master')[1].strip()

    # Don't bother trying to update if our sha is the same
    if head_sha == repo_config['sha']:
        return repo_config

    # Construct a new config with the head sha
    new_config = OrderedDict(repo_config)
    new_config['sha'] = head_sha
    new_repo = Repository.create(new_config, runner.store)

    # See if any of our hooks were deleted with the new commits
    hooks = set(hook_id for hook_id, _ in repo.hooks)
    hooks_missing = hooks - (hooks & set(new_repo.manifest.hooks.keys()))
    if hooks_missing:
        raise RepositoryCannotBeUpdatedError(
            'Cannot update because the tip of master is missing these hooks:\n'
            '{0}'.format(', '.join(sorted(hooks_missing)))
        )

    return new_config
开发者ID:MMontgomeryII,项目名称:pre-commit,代码行数:33,代码来源:autoupdate.py

示例2: test_config_overrides_repo_specifics

def test_config_overrides_repo_specifics(tempdir_factory, store):
    path = make_repo(tempdir_factory, "script_hooks_repo")
    config = make_config_from_repo(path)

    repo = Repository.create(config, store)
    assert repo.hooks[0][1]["files"] == ""
    # Set the file regex to something else
    config["hooks"][0]["files"] = "\\.sh$"
    repo = Repository.create(config, store)
    assert repo.hooks[0][1]["files"] == "\\.sh$"
开发者ID:hitul007,项目名称:pre-commit,代码行数:10,代码来源:repository_test.py

示例3: test_config_overrides_repo_specifics

def test_config_overrides_repo_specifics(tmpdir_factory, store):
    path = make_repo(tmpdir_factory, 'script_hooks_repo')
    config = make_config_from_repo(path)

    repo = Repository.create(config, store)
    assert repo.hooks[0][1]['files'] == ''
    # Set the file regex to something else
    config['hooks'][0]['files'] = '\\.sh$'
    repo = Repository.create(config, store)
    assert repo.hooks[0][1]['files'] == '\\.sh$'
开发者ID:caffodian,项目名称:pre-commit,代码行数:10,代码来源:repository_test.py

示例4: test_reinstall

def test_reinstall(tmpdir_factory, store):
    path = make_repo(tmpdir_factory, 'python_hooks_repo')
    config = make_config_from_repo(path)
    repo = Repository.create(config, store)
    repo.require_installed()
    # Reinstall with same repo should not trigger another install
    # TODO: how to assert this?
    repo.require_installed()
    # Reinstall on another run should not trigger another install
    # TODO: how to assert this?
    repo = Repository.create(config, store)
    repo.require_installed()
开发者ID:bukzor,项目名称:pre-commit,代码行数:12,代码来源:repository_test.py

示例5: test_tags_on_repositories

def test_tags_on_repositories(in_tmpdir, tempdir_factory, store):
    tag = "v1.1"
    git_dir_1 = _create_repo_with_tags(tempdir_factory, "prints_cwd_repo", tag)
    git_dir_2 = _create_repo_with_tags(tempdir_factory, "script_hooks_repo", tag)

    repo_1 = Repository.create(make_config_from_repo(git_dir_1, sha=tag), store)
    ret = repo_1.run_hook(repo_1.hooks[0][1], ["-L"])
    assert ret[0] == 0
    assert ret[1].strip() == _norm_pwd(in_tmpdir)

    repo_2 = Repository.create(make_config_from_repo(git_dir_2, sha=tag), store)
    ret = repo_2.run_hook(repo_2.hooks[0][1], ["bar"])
    assert ret[0] == 0
    assert ret[1] == b"bar\nHello World\n"
开发者ID:hitul007,项目名称:pre-commit,代码行数:14,代码来源:repository_test.py

示例6: test_reinstall

def test_reinstall(tmpdir_factory, store, log_info_mock):
    path = make_repo(tmpdir_factory, 'python_hooks_repo')
    config = make_config_from_repo(path)
    repo = Repository.create(config, store)
    repo.require_installed()
    # We print some logging during clone (1) + install (3)
    assert log_info_mock.call_count == 4
    log_info_mock.reset_mock()
    # Reinstall with same repo should not trigger another install
    repo.require_installed()
    assert log_info_mock.call_count == 0
    # Reinstall on another run should not trigger another install
    repo = Repository.create(config, store)
    repo.require_installed()
    assert log_info_mock.call_count == 0
开发者ID:caffodian,项目名称:pre-commit,代码行数:15,代码来源:repository_test.py

示例7: run_on_version

 def run_on_version(version, expected_output):
     config = make_config_from_repo(path, hooks=[{"id": "python3-hook", "language_version": version}])
     repo = Repository.create(config, store)
     hook_dict, = [hook for repo_hook_id, hook in repo.hooks if repo_hook_id == "python3-hook"]
     ret = repo.run_hook(hook_dict, [])
     assert ret[0] == 0
     assert ret[1].replace(b"\r\n", b"\n") == expected_output
开发者ID:hitul007,项目名称:pre-commit,代码行数:7,代码来源:repository_test.py

示例8: repositories

 def repositories(self):
     """Returns a tuple of the configured repositories."""
     config = load_config(self.config_file_path)
     repositories = tuple(Repository.create(x, self.store) for x in config)
     for repository in repositories:
         repository.require_installed()
     return repositories
开发者ID:akramhussein,项目名称:pre-commit,代码行数:7,代码来源:runner.py

示例9: repositories

 def repositories(self):
     """Returns a tuple of the configured repositories."""
     repos = self.config['repos']
     repos = tuple(Repository.create(x, self.store) for x in repos)
     for repo in repos:
         repo.require_installed()
     return repos
开发者ID:Lucas-C,项目名称:pre-commit,代码行数:7,代码来源:runner.py

示例10: test_control_c_control_c_on_install

def test_control_c_control_c_on_install(tmpdir_factory, store):
    """Regression test for #186."""
    path = make_repo(tmpdir_factory, 'python_hooks_repo')
    config = make_config_from_repo(path)
    repo = Repository.create(config, store)
    hook = repo.hooks[0][1]

    class MyKeyboardInterrupt(KeyboardInterrupt):
        pass

    # To simulate a killed install, we'll make PythonEnv.run raise ^C
    # and then to simulate a second ^C during cleanup, we'll make shutil.rmtree
    # raise as well.
    with pytest.raises(MyKeyboardInterrupt):
        with mock.patch.object(
            PythonEnv, 'run', side_effect=MyKeyboardInterrupt,
        ):
            with mock.patch.object(
                shutil, 'rmtree', side_effect=MyKeyboardInterrupt,
            ):
                repo.run_hook(hook, [])

    # Should have made an environment, however this environment is broken!
    assert os.path.exists(repo.cmd_runner.path('py_env'))

    # However, it should be perfectly runnable (reinstall after botched
    # install)
    retv, stdout, stderr = repo.run_hook(hook, [])
    assert retv == 0
开发者ID:caffodian,项目名称:pre-commit,代码行数:29,代码来源:repository_test.py

示例11: test_local_repository

def test_local_repository():
    config = config_with_local_hooks()
    local_repo = Repository.create(config, 'dummy')
    with pytest.raises(NotImplementedError):
        local_repo.sha
    with pytest.raises(NotImplementedError):
        local_repo.manifest
    assert len(local_repo.hooks) == 1
开发者ID:FeodorFitsner,项目名称:pre-commit,代码行数:8,代码来源:repository_test.py

示例12: test_additional_python_dependencies_installed

def test_additional_python_dependencies_installed(tempdir_factory, store):
    path = make_repo(tempdir_factory, 'python_hooks_repo')
    config = make_config_from_repo(path)
    config['hooks'][0]['additional_dependencies'] = ['mccabe']
    repo = Repository.create(config, store)
    repo.run_hook(repo.hooks[0][1], [])
    with python.in_env(repo.cmd_runner, 'default') as env:
        output = env.run('pip freeze -l')[1]
        assert 'mccabe' in output
开发者ID:jdb8,项目名称:pre-commit,代码行数:9,代码来源:repository_test.py

示例13: _test_hook_repo

def _test_hook_repo(
    tempdir_factory, store, repo_path, hook_id, args, expected, expected_return_code=0, config_kwargs=None
):
    path = make_repo(tempdir_factory, repo_path)
    config = make_config_from_repo(path, **(config_kwargs or {}))
    repo = Repository.create(config, store)
    hook_dict = [hook for repo_hook_id, hook in repo.hooks if repo_hook_id == hook_id][0]
    ret = repo.run_hook(hook_dict, args)
    assert ret[0] == expected_return_code
    assert ret[1].replace(b"\r\n", b"\n") == expected
开发者ID:hitul007,项目名称:pre-commit,代码行数:10,代码来源:repository_test.py

示例14: test_tags_on_repositories

def test_tags_on_repositories(in_tmpdir, tmpdir_factory, store):
    tag = 'v1.1'
    git_dir_1 = _create_repo_with_tags(tmpdir_factory, 'prints_cwd_repo', tag)
    git_dir_2 = _create_repo_with_tags(
        tmpdir_factory, 'script_hooks_repo', tag,
    )

    repo_1 = Repository.create(
        make_config_from_repo(git_dir_1, sha=tag), store,
    )
    ret = repo_1.run_hook(repo_1.hooks[0][1], ['-L'])
    assert ret[0] == 0
    assert ret[1].strip() == _norm_pwd(in_tmpdir)

    repo_2 = Repository.create(
        make_config_from_repo(git_dir_2, sha=tag), store,
    )
    ret = repo_2.run_hook(repo_2.hooks[0][1], ['bar'])
    assert ret[0] == 0
    assert ret[1] == 'bar\nHello World\n'
开发者ID:caffodian,项目名称:pre-commit,代码行数:20,代码来源:repository_test.py

示例15: test_really_long_file_paths

def test_really_long_file_paths(tmpdir_factory, store):
    base_path = tmpdir_factory.get()
    really_long_path = os.path.join(base_path, 'really_long' * 10)
    cmd_output('git', 'init', really_long_path)

    path = make_repo(tmpdir_factory, 'python_hooks_repo')
    config = make_config_from_repo(path)

    with cwd(really_long_path):
        repo = Repository.create(config, store)
        repo.require_installed()
开发者ID:caffodian,项目名称:pre-commit,代码行数:11,代码来源:repository_test.py


注:本文中的pre_commit.repository.Repository类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。