Merge pull request #1033 from pre-commit/fix-encoding-pragma

Add deprecation messaging for `fix-encoding-pragma`
This commit is contained in:
Anthony Sottile 2024-04-06 14:12:02 -04:00 committed by GitHub
commit d87a28b79d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -145,7 +145,7 @@
language: python language: python
types: [text] types: [text]
- id: fix-encoding-pragma - id: fix-encoding-pragma
name: fix python encoding pragma name: fix python encoding pragma (deprecated)
description: 'adds # -*- coding: utf-8 -*- to the top of python files.' description: 'adds # -*- coding: utf-8 -*- to the top of python files.'
language: python language: python
entry: fix-encoding-pragma entry: fix-encoding-pragma

View File

@ -127,6 +127,9 @@ The following arguments are available:
removes UTF-8 byte order marker removes UTF-8 byte order marker
#### `fix-encoding-pragma` #### `fix-encoding-pragma`
_Deprecated since py2 is EOL - use [pyupgrade](https://github.com/asottile/pyupgrade) instead._
Add `# -*- coding: utf-8 -*-` to the top of python files. Add `# -*- coding: utf-8 -*-` to the top of python files.
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase) - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)

View File

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import argparse import argparse
import sys
from typing import IO from typing import IO
from typing import NamedTuple from typing import NamedTuple
from typing import Sequence from typing import Sequence
@ -107,6 +108,13 @@ def _normalize_pragma(pragma: str) -> bytes:
def main(argv: Sequence[str] | None = None) -> int: def main(argv: Sequence[str] | None = None) -> int:
print(
'warning: this hook is deprecated and will be removed in a future '
'release because py2 is EOL. instead, use '
'https://github.com/asottile/pyupgrade',
file=sys.stderr,
)
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
'Fixes the encoding pragma of python files', 'Fixes the encoding pragma of python files',
) )