From 9e81b0b8ee66bde7fe831219b2ccba1867eed29f Mon Sep 17 00:00:00 2001 From: KotlinIsland Date: Tue, 16 Mar 2021 19:31:18 +1000 Subject: [PATCH] don't require typed-ast --- setup.py | 3 ++- src/black/__init__.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index efdf6933025..0b5820ff305 100644 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ def get_long_description() -> str: "click>=7.1.2", "appdirs", "toml>=0.10.1", - "typed-ast>=1.4.2", + "typed-ast>=1.4.2; python_version < '3.8'", "regex>=2020.1.8", "pathspec>=0.6, <1", "dataclasses>=0.6; python_version < '3.7'", @@ -81,6 +81,7 @@ def get_long_description() -> str: extras_require={ "d": ["aiohttp>=3.3.2", "aiohttp-cors"], "colorama": ["colorama>=0.4.3"], + 'python2': ['typed-ast>=1.4.2'], }, test_suite="tests.test_black", classifiers=[ diff --git a/src/black/__init__.py b/src/black/__init__.py index a8f4f89a6bb..60d948ccd9c 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -48,7 +48,20 @@ from dataclasses import dataclass, field, replace import click import toml -from typed_ast import ast3, ast27 + +if sys.version_info < (3, 8): + try: + from typed_ast import ast3, ast27 + except ImportError: + print( + "The typed_ast package is not installed.\n" + "You must install typed_ast with `python3 -m pip install typed-ast`.", + file=sys.stderr, + ) + sys.exit(1) +else: + ast3 = ast27 = ast + from pathspec import PathSpec # lib2to3 fork