本文整理汇总了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
示例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$"
示例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$'
示例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()
示例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"
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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'
示例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()