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,11 +31,13 @@ class RevInfo(NamedTuple):
|
||||||
rev: str
|
rev: str
|
||||||
frozen: Optional[str]
|
frozen: Optional[str]
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
|
@classmethod
|
||||||
|
def RevInfo_from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
|
||||||
return cls(config['repo'], config['rev'], None)
|
return cls(config['repo'], config['rev'], None)
|
||||||
|
|
||||||
def update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
|
||||||
|
def RevInfo_update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
||||||
if tags_only:
|
if tags_only:
|
||||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
||||||
else:
|
else:
|
||||||
|
|
@ -59,6 +61,11 @@ class RevInfo(NamedTuple):
|
||||||
return self._replace(rev=rev, frozen=frozen)
|
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):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,12 +35,14 @@ class Hook(NamedTuple):
|
||||||
stages: Sequence[str]
|
stages: Sequence[str]
|
||||||
verbose: bool
|
verbose: bool
|
||||||
|
|
||||||
@property
|
|
||||||
def cmd(self) -> Tuple[str, ...]:
|
@property
|
||||||
|
def Hook_cmd(self: Hook) -> Tuple[str, ...]:
|
||||||
return (*shlex.split(self.entry), *self.args)
|
return (*shlex.split(self.entry), *self.args)
|
||||||
|
|
||||||
@property
|
|
||||||
def install_key(self) -> Tuple[Prefix, str, str, Tuple[str, ...]]:
|
@property
|
||||||
|
def Hook_install_key(self) -> Tuple[Prefix, str, str, Tuple[str, ...]]:
|
||||||
return (
|
return (
|
||||||
self.prefix,
|
self.prefix,
|
||||||
self.language,
|
self.language,
|
||||||
|
|
@ -48,8 +50,9 @@ class Hook(NamedTuple):
|
||||||
tuple(self.additional_dependencies),
|
tuple(self.additional_dependencies),
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def create(cls, src: str, prefix: Prefix, dct: Dict[str, Any]) -> 'Hook':
|
@classmethod
|
||||||
|
def Hook_create(cls, src: str, prefix: Prefix, dct: Dict[str, Any]) -> 'Hook':
|
||||||
# TODO: have cfgv do this (?)
|
# TODO: have cfgv do this (?)
|
||||||
extra_keys = set(dct) - _KEYS
|
extra_keys = set(dct) - _KEYS
|
||||||
if extra_keys:
|
if extra_keys:
|
||||||
|
|
@ -60,4 +63,10 @@ class Hook(NamedTuple):
|
||||||
return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
|
return cls(src=src, prefix=prefix, **{k: dct[k] for k in _KEYS})
|
||||||
|
|
||||||
|
|
||||||
|
# python 3.6.0 does not support methods on `typing.NamedTuple`
|
||||||
|
Hook.cmd = Hook_cmd
|
||||||
|
Hook.install_key = Hook_install_key
|
||||||
|
Hook.create = Hook_create
|
||||||
|
|
||||||
|
|
||||||
_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:
|
|
||||||
|
def Prefix_path(self, *parts: str) -> str:
|
||||||
return os.path.normpath(os.path.join(self.prefix_dir, *parts))
|
return os.path.normpath(os.path.join(self.prefix_dir, *parts))
|
||||||
|
|
||||||
def exists(self, *parts: str) -> bool:
|
|
||||||
|
def Prefix_exists(self, *parts: str) -> bool:
|
||||||
return os.path.exists(self.path(*parts))
|
return os.path.exists(self.path(*parts))
|
||||||
|
|
||||||
def star(self, end: str) -> Tuple[str, ...]:
|
|
||||||
|
def Prefix_star(self, end: str) -> Tuple[str, ...]:
|
||||||
paths = os.listdir(self.prefix_dir)
|
paths = os.listdir(self.prefix_dir)
|
||||||
return tuple(path for path in paths if path.endswith(end))
|
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