mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Temporarily restore python 3.6.0 support
This commit is contained in:
parent
1c641b1c28
commit
081f3028ee
5 changed files with 79 additions and 55 deletions
|
|
@ -43,11 +43,6 @@ repos:
|
||||||
rev: v1.6.0
|
rev: v1.6.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: setup-cfg-fmt
|
- id: setup-cfg-fmt
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
|
||||||
rev: v0.761
|
|
||||||
hooks:
|
|
||||||
- id: mypy
|
|
||||||
exclude: ^testing/resources/
|
|
||||||
- repo: meta
|
- repo: meta
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-hooks-apply
|
- id: check-hooks-apply
|
||||||
|
|
|
||||||
|
|
@ -31,32 +31,39 @@ class RevInfo(NamedTuple):
|
||||||
rev: str
|
rev: str
|
||||||
frozen: Optional[str]
|
frozen: Optional[str]
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
|
|
||||||
return cls(config['repo'], config['rev'], None)
|
|
||||||
|
|
||||||
def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
@classmethod
|
||||||
if tags_only:
|
def RevInfo_from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
|
||||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
return cls(config['repo'], config['rev'], None)
|
||||||
else:
|
|
||||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
|
|
||||||
|
|
||||||
with tmpdir() as tmp:
|
|
||||||
git.init_repo(tmp, self.repo)
|
|
||||||
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
|
|
||||||
|
|
||||||
try:
|
def RevInfo_update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
||||||
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
|
if tags_only:
|
||||||
except CalledProcessError:
|
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
||||||
cmd = ('git', 'rev-parse', 'FETCH_HEAD')
|
else:
|
||||||
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
|
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
|
||||||
|
|
||||||
frozen = None
|
with tmpdir() as tmp:
|
||||||
if freeze:
|
git.init_repo(tmp, self.repo)
|
||||||
exact = cmd_output('git', 'rev-parse', rev, cwd=tmp)[1].strip()
|
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
|
||||||
if exact != rev:
|
|
||||||
rev, frozen = exact, rev
|
try:
|
||||||
return self._replace(rev=rev, frozen=frozen)
|
rev = cmd_output(*tag_cmd, cwd=tmp)[1].strip()
|
||||||
|
except CalledProcessError:
|
||||||
|
cmd = ('git', 'rev-parse', 'FETCH_HEAD')
|
||||||
|
rev = cmd_output(*cmd, cwd=tmp)[1].strip()
|
||||||
|
|
||||||
|
frozen = None
|
||||||
|
if freeze:
|
||||||
|
exact = cmd_output('git', 'rev-parse', rev, cwd=tmp)[1].strip()
|
||||||
|
if exact != rev:
|
||||||
|
rev, frozen = exact, rev
|
||||||
|
return self._replace(rev=rev, frozen=frozen)
|
||||||
|
|
||||||
|
|
||||||
|
# python 3.6.0 does not support methods on `typing.NamedTuple`
|
||||||
|
RevInfo.from_config = RevInfo_from_config
|
||||||
|
RevInfo.update = RevInfo_update
|
||||||
|
|
||||||
|
|
||||||
class RepositoryCannotBeUpdatedError(RuntimeError):
|
class RepositoryCannotBeUpdatedError(RuntimeError):
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,11 @@ UNSET = _Unset.UNSET
|
||||||
|
|
||||||
class Var(NamedTuple):
|
class Var(NamedTuple):
|
||||||
name: str
|
name: str
|
||||||
default: str = ''
|
default: str
|
||||||
|
|
||||||
|
|
||||||
|
# python3.6.0: `typing.NamedTuple` did not support defaults
|
||||||
|
Var.__new__.__defaults__ = ('',)
|
||||||
|
|
||||||
|
|
||||||
SubstitutionT = Tuple[Union[str, Var], ...]
|
SubstitutionT = Tuple[Union[str, Var], ...]
|
||||||
|
|
|
||||||
|
|
@ -35,29 +35,38 @@ class Hook(NamedTuple):
|
||||||
stages: Sequence[str]
|
stages: Sequence[str]
|
||||||
verbose: bool
|
verbose: bool
|
||||||
|
|
||||||
@property
|
|
||||||
def cmd(self) -> Tuple[str, ...]:
|
|
||||||
return (*shlex.split(self.entry), *self.args)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def install_key(self) -> Tuple[Prefix, str, str, Tuple[str, ...]]:
|
def Hook_cmd(self: Hook) -> Tuple[str, ...]:
|
||||||
return (
|
return (*shlex.split(self.entry), *self.args)
|
||||||
self.prefix,
|
|
||||||
self.language,
|
|
||||||
self.language_version,
|
@property
|
||||||
tuple(self.additional_dependencies),
|
def Hook_install_key(self) -> Tuple[Prefix, str, str, Tuple[str, ...]]:
|
||||||
|
return (
|
||||||
|
self.prefix,
|
||||||
|
self.language,
|
||||||
|
self.language_version,
|
||||||
|
tuple(self.additional_dependencies),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def Hook_create(cls, src: str, prefix: Prefix, dct: Dict[str, Any]) -> 'Hook':
|
||||||
|
# TODO: have cfgv do this (?)
|
||||||
|
extra_keys = set(dct) - _KEYS
|
||||||
|
if extra_keys:
|
||||||
|
logger.warning(
|
||||||
|
f'Unexpected key(s) present on {src} => {dct["id"]}: '
|
||||||
|
f'{", ".join(sorted(extra_keys))}',
|
||||||
)
|
)
|
||||||
|
return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create(cls, src: str, prefix: Prefix, dct: Dict[str, Any]) -> 'Hook':
|
# python 3.6.0 does not support methods on `typing.NamedTuple`
|
||||||
# TODO: have cfgv do this (?)
|
Hook.cmd = Hook_cmd
|
||||||
extra_keys = set(dct) - _KEYS
|
Hook.install_key = Hook_install_key
|
||||||
if extra_keys:
|
Hook.create = Hook_create
|
||||||
logger.warning(
|
|
||||||
f'Unexpected key(s) present on {src} => {dct["id"]}: '
|
|
||||||
f'{", ".join(sorted(extra_keys))}',
|
|
||||||
)
|
|
||||||
return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
|
|
||||||
|
|
||||||
|
|
||||||
_KEYS = frozenset(set(Hook._fields) - {'src', 'prefix'})
|
_KEYS = frozenset(set(Hook._fields) - {'src', 'prefix'})
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,21 @@ from typing import Tuple
|
||||||
class Prefix(NamedTuple):
|
class Prefix(NamedTuple):
|
||||||
prefix_dir: str
|
prefix_dir: str
|
||||||
|
|
||||||
def path(self, *parts: str) -> str:
|
|
||||||
return os.path.normpath(os.path.join(self.prefix_dir, *parts))
|
|
||||||
|
|
||||||
def exists(self, *parts: str) -> bool:
|
def Prefix_path(self, *parts: str) -> str:
|
||||||
return os.path.exists(self.path(*parts))
|
return os.path.normpath(os.path.join(self.prefix_dir, *parts))
|
||||||
|
|
||||||
def star(self, end: str) -> Tuple[str, ...]:
|
|
||||||
paths = os.listdir(self.prefix_dir)
|
def Prefix_exists(self, *parts: str) -> bool:
|
||||||
return tuple(path for path in paths if path.endswith(end))
|
return os.path.exists(self.path(*parts))
|
||||||
|
|
||||||
|
|
||||||
|
def Prefix_star(self, end: str) -> Tuple[str, ...]:
|
||||||
|
paths = os.listdir(self.prefix_dir)
|
||||||
|
return tuple(path for path in paths if path.endswith(end))
|
||||||
|
|
||||||
|
|
||||||
|
# python 3.6.0 does not support methods on `typing.NamedTuple`
|
||||||
|
Prefix.path = Prefix_path
|
||||||
|
Prefix.exists = Prefix_exists
|
||||||
|
Prefix.star = Prefix_star
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue