Example #1
0
def make_config_from_repo(
    repo_path,
    sha=None,
    hooks=None,
    check=True,
    legacy=False,
):
    filename = C.MANIFEST_FILE_LEGACY if legacy else C.MANIFEST_FILE
    manifest = load_manifest(os.path.join(repo_path, filename))
    config = OrderedDict((
        ('repo', repo_path),
        ('sha', sha or get_head_sha(repo_path)),
        (
            'hooks',
            hooks
            or [OrderedDict((('id', hook['id']), )) for hook in manifest],
        ),
    ))

    if check:
        wrapped_config = apply_defaults([config], CONFIG_JSON_SCHEMA)
        validate_config_extra(wrapped_config)
        return wrapped_config[0]
    else:
        return config
Example #2
0
 def manifest_contents(self):
     default_path = os.path.join(self.repo_path, C.MANIFEST_FILE)
     legacy_path = os.path.join(self.repo_path, C.MANIFEST_FILE_LEGACY)
     if os.path.exists(legacy_path) and not os.path.exists(default_path):
         logger.warning(
             '{} uses legacy {} to provide hooks.\n'
             'In newer versions, this file is called {}\n'
             'This will work in this version of pre-commit but will be '
             'removed at a later time.\n'
             'If `pre-commit autoupdate` does not silence this warning '
             'consider making an issue / pull request.'.format(
                 self.repo_url, C.MANIFEST_FILE_LEGACY, C.MANIFEST_FILE,
             )
         )
         return load_manifest(legacy_path)
     else:
         return load_manifest(default_path)
Example #3
0
def test_local_python_repo(store):
    # Make a "local" hooks repo that just installs our other hooks repo
    repo_path = get_resource_path('python_hooks_repo')
    manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
    hooks = [
        dict(hook, additional_dependencies=[repo_path]) for hook in manifest
    ]
    config = {'repo': 'local', 'hooks': hooks}
    repo = Repository.create(config, store)
    (_, hook), = repo.hooks
    ret = repo.run_hook(hook, ('filename', ))
    assert ret[0] == 0
    assert ret[1].replace(b'\r\n', b'\n') == b"['filename']\nHello World\n"
Example #4
0
def make_config_from_repo(repo_path, sha=None, hooks=None, check=True):
    manifest = load_manifest(os.path.join(repo_path, C.MANIFEST_FILE))
    config = OrderedDict((
        ('repo', repo_path),
        ('sha', sha or get_head_sha(repo_path)),
        (
            'hooks',
            hooks or [OrderedDict((('id', hook['id']),)) for hook in manifest],
        ),
    ))

    if check:
        wrapped_config = apply_defaults([config], CONFIG_JSON_SCHEMA)
        validate_config_extra(wrapped_config)
        return wrapped_config[0]
    else:
        return config
Example #5
0
 def manifest_contents(self):
     manifest_path = os.path.join(
         self.repo_path_getter.repo_path, C.MANIFEST_FILE,
     )
     return load_manifest(manifest_path)
Example #6
0
 def manifest_contents(self):
     manifest_path = os.path.join(
         self.repo_path_getter.repo_path, C.MANIFEST_FILE,
     )
     return load_manifest(manifest_path)