mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-14 21:10:27 -06:00
Temporarily restore python 3.6.0 support
This commit is contained in:
@@ -43,11 +43,6 @@ repos:
|
||||
rev: v1.6.0
|
||||
hooks:
|
||||
- id: setup-cfg-fmt
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v0.761
|
||||
hooks:
|
||||
- id: mypy
|
||||
exclude: ^testing/resources/
|
||||
- repo: meta
|
||||
hooks:
|
||||
- id: check-hooks-apply
|
||||
|
||||
@@ -31,32 +31,39 @@ class RevInfo(NamedTuple):
|
||||
rev: 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':
|
||||
if tags_only:
|
||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
||||
else:
|
||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
|
||||
@classmethod
|
||||
def RevInfo_from_config(cls, config: Dict[str, Any]) -> 'RevInfo':
|
||||
return cls(config['repo'], config['rev'], None)
|
||||
|
||||
with tmpdir() as tmp:
|
||||
git.init_repo(tmp, self.repo)
|
||||
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
|
||||
|
||||
try:
|
||||
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()
|
||||
def RevInfo_update(self, tags_only: bool, freeze: bool) -> 'RevInfo':
|
||||
if tags_only:
|
||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--abbrev=0')
|
||||
else:
|
||||
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags', '--exact')
|
||||
|
||||
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)
|
||||
with tmpdir() as tmp:
|
||||
git.init_repo(tmp, self.repo)
|
||||
cmd_output_b('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=tmp)
|
||||
|
||||
try:
|
||||
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):
|
||||
|
||||
@@ -19,7 +19,11 @@ UNSET = _Unset.UNSET
|
||||
|
||||
class Var(NamedTuple):
|
||||
name: str
|
||||
default: str = ''
|
||||
default: str
|
||||
|
||||
|
||||
# python3.6.0: `typing.NamedTuple` did not support defaults
|
||||
Var.__new__.__defaults__ = ('',)
|
||||
|
||||
|
||||
SubstitutionT = Tuple[Union[str, Var], ...]
|
||||
|
||||
@@ -35,29 +35,38 @@ class Hook(NamedTuple):
|
||||
stages: Sequence[str]
|
||||
verbose: bool
|
||||
|
||||
@property
|
||||
def cmd(self) -> Tuple[str, ...]:
|
||||
return (*shlex.split(self.entry), *self.args)
|
||||
|
||||
@property
|
||||
def install_key(self) -> Tuple[Prefix, str, str, Tuple[str, ...]]:
|
||||
return (
|
||||
self.prefix,
|
||||
self.language,
|
||||
self.language_version,
|
||||
tuple(self.additional_dependencies),
|
||||
@property
|
||||
def Hook_cmd(self: Hook) -> Tuple[str, ...]:
|
||||
return (*shlex.split(self.entry), *self.args)
|
||||
|
||||
|
||||
@property
|
||||
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':
|
||||
# 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})
|
||||
|
||||
# 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'})
|
||||
|
||||
@@ -6,12 +6,21 @@ from typing import Tuple
|
||||
class Prefix(NamedTuple):
|
||||
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:
|
||||
return os.path.exists(self.path(*parts))
|
||||
def Prefix_path(self, *parts: str) -> str:
|
||||
return os.path.normpath(os.path.join(self.prefix_dir, *parts))
|
||||
|
||||
def star(self, end: str) -> Tuple[str, ...]:
|
||||
paths = os.listdir(self.prefix_dir)
|
||||
return tuple(path for path in paths if path.endswith(end))
|
||||
|
||||
def Prefix_exists(self, *parts: str) -> bool:
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user