don't require typed-ast
This commit is contained in:
parent
c702588daa
commit
ed9d58b741
@ -40,6 +40,11 @@
|
|||||||
|
|
||||||
- Lines ending with `fmt: skip` will now be not formatted (#1800)
|
- Lines ending with `fmt: skip` will now be not formatted (#1800)
|
||||||
|
|
||||||
|
- PR #2053: Black no longer relies on typed-ast for Python 3.8 and higher
|
||||||
|
|
||||||
|
- PR #2053: Python 2 support is now optional, install with
|
||||||
|
`python3 -m pip install black[python2]` to maintain support.
|
||||||
|
|
||||||
#### _Packaging_
|
#### _Packaging_
|
||||||
|
|
||||||
- Self-contained native _Black_ binaries are now provided for releases via GitHub
|
- Self-contained native _Black_ binaries are now provided for releases via GitHub
|
||||||
|
@ -50,7 +50,8 @@ _Contents:_ **[Installation and usage](#installation-and-usage)** |
|
|||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
_Black_ can be installed by running `pip install black`. It requires Python 3.6.2+ to
|
_Black_ can be installed by running `pip install black`. It requires Python 3.6.2+ to
|
||||||
run but you can reformat Python 2 code with it, too.
|
run. If you want to format Python 2 code as well, install with
|
||||||
|
`pip install black[python2]`.
|
||||||
|
|
||||||
#### Install from GitHub
|
#### Install from GitHub
|
||||||
|
|
||||||
|
3
setup.py
3
setup.py
@ -71,7 +71,7 @@ def get_long_description() -> str:
|
|||||||
"click>=7.1.2",
|
"click>=7.1.2",
|
||||||
"appdirs",
|
"appdirs",
|
||||||
"toml>=0.10.1",
|
"toml>=0.10.1",
|
||||||
"typed-ast>=1.4.2",
|
"typed-ast>=1.4.2; python_version < '3.8'",
|
||||||
"regex>=2020.1.8",
|
"regex>=2020.1.8",
|
||||||
"pathspec>=0.6, <1",
|
"pathspec>=0.6, <1",
|
||||||
"dataclasses>=0.6; python_version < '3.7'",
|
"dataclasses>=0.6; python_version < '3.7'",
|
||||||
@ -81,6 +81,7 @@ def get_long_description() -> str:
|
|||||||
extras_require={
|
extras_require={
|
||||||
"d": ["aiohttp>=3.3.2", "aiohttp-cors"],
|
"d": ["aiohttp>=3.3.2", "aiohttp-cors"],
|
||||||
"colorama": ["colorama>=0.4.3"],
|
"colorama": ["colorama>=0.4.3"],
|
||||||
|
"python2": ["typed-ast>=1.4.2"],
|
||||||
},
|
},
|
||||||
test_suite="tests.test_black",
|
test_suite="tests.test_black",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
|
@ -48,7 +48,20 @@
|
|||||||
from dataclasses import dataclass, field, replace
|
from dataclasses import dataclass, field, replace
|
||||||
import click
|
import click
|
||||||
import toml
|
import toml
|
||||||
from typed_ast import ast3, ast27
|
|
||||||
|
try:
|
||||||
|
from typed_ast import ast3, ast27
|
||||||
|
except ImportError:
|
||||||
|
if sys.version_info < (3, 8):
|
||||||
|
print(
|
||||||
|
"The typed_ast package is not installed.\n"
|
||||||
|
"You can install it with `python3 -m pip install typed-ast`.",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
ast3 = ast27 = ast
|
||||||
|
|
||||||
from pathspec import PathSpec
|
from pathspec import PathSpec
|
||||||
|
|
||||||
# lib2to3 fork
|
# lib2to3 fork
|
||||||
@ -6336,7 +6349,12 @@ def parse_ast(src: str) -> Union[ast.AST, ast3.AST, ast27.AST]:
|
|||||||
return ast3.parse(src, filename, feature_version=feature_version)
|
return ast3.parse(src, filename, feature_version=feature_version)
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
continue
|
continue
|
||||||
|
if ast27.__name__ == "ast":
|
||||||
|
raise SyntaxError(
|
||||||
|
"The requested source code has invalid Python 3 syntax.\n"
|
||||||
|
"If you are trying to format Python 2 files please reinstall Black"
|
||||||
|
" with the 'python2' extra: `python3 -m pip install black[python2]`."
|
||||||
|
)
|
||||||
return ast27.parse(src)
|
return ast27.parse(src)
|
||||||
|
|
||||||
|
|
||||||
|
2
tox.ini
2
tox.ini
@ -7,7 +7,7 @@ skip_install = True
|
|||||||
deps =
|
deps =
|
||||||
-r{toxinidir}/test_requirements.txt
|
-r{toxinidir}/test_requirements.txt
|
||||||
commands =
|
commands =
|
||||||
pip install -e .[d]
|
pip install -e .[d,python2]
|
||||||
coverage erase
|
coverage erase
|
||||||
coverage run -m pytest tests
|
coverage run -m pytest tests
|
||||||
coverage report
|
coverage report
|
||||||
|
Loading…
Reference in New Issue
Block a user