deprecate python_venv language

This commit is contained in:
Anthony Sottile 2023-02-04 14:26:09 -05:00
parent 0359fae2da
commit 0c1267b214
8 changed files with 73 additions and 29 deletions

View file

@ -42,6 +42,14 @@ def _migrate_sha_to_rev(contents: str) -> str:
return re.sub(r'(\n\s+)sha:', r'\1rev:', contents)
def _migrate_python_venv(contents: str) -> str:
return re.sub(
r'(\n\s+)language: python_venv\b',
r'\1language: python',
contents,
)
def migrate_config(config_file: str, quiet: bool = False) -> int:
with open(config_file) as f:
orig_contents = contents = f.read()
@ -55,6 +63,7 @@ def migrate_config(config_file: str, quiet: bool = False) -> int:
contents = _migrate_map(contents)
contents = _migrate_sha_to_rev(contents)
contents = _migrate_python_venv(contents)
if contents != orig_contents:
with open(config_file, 'w') as f:

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import json
import logging
import os
import shlex
from typing import Any
from typing import Sequence
@ -68,6 +69,14 @@ def _hook_install(hook: Hook) -> None:
logger.info('Once installed this environment will be reused.')
logger.info('This may take a few minutes...')
if hook.language == 'python_venv':
logger.warning(
f'`repo: {hook.src}` uses deprecated `language: python_venv`. '
f'This is an alias for `language: python`. '
f'Often `pre-commit autoupdate --repo {shlex.quote(hook.src)}` '
f'will fix this.',
)
lang = languages[hook.language]
assert lang.ENVIRONMENT_DIR is not None