]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

don't require typed-ast
authorKotlinIsland <kotlinisland@users.noreply.github.com>
Tue, 16 Mar 2021 09:31:18 +0000 (19:31 +1000)
committerŁukasz Langa <lukasz@langa.pl>
Thu, 1 Apr 2021 15:38:04 +0000 (17:38 +0200)
CHANGES.md
README.md
setup.py
src/black/__init__.py
tox.ini

index 7da7be7b842bc6cb74e6889e6b4c59ff2a4ff5e3..97a3be33c9303d1ef955e4a055fc7683ec5bf188 100644 (file)
 
 - 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_
 
 - Self-contained native _Black_ binaries are now provided for releases via GitHub
index 411a8c8609d0a51589686be497b2c69d4a5665f3..0be356e3b84ad9d5c0256092b21687e7d27a4930 100644 (file)
--- a/README.md
+++ b/README.md
@@ -50,7 +50,8 @@ _Contents:_ **[Installation and usage](#installation-and-usage)** |
 ### Installation
 
 _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
 
index efdf69330257a3b076f1430f6ae5343ce834e21c..856c7fadb0ca2e6ee3a4fe6b9ecd700d000533db 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -71,7 +71,7 @@ setup(
         "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 @@ setup(
     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=[
index a8f4f89a6bbe8536f9e254a57b2fc658879c841e..52a57695aefdb0dc2202eda8b745b866187eba0e 100644 (file)
@@ -48,7 +48,20 @@ from appdirs import user_cache_dir
 from dataclasses import dataclass, field, replace
 import click
 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
 
 # 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)
             except SyntaxError:
                 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)
 
 
diff --git a/tox.ini b/tox.ini
index 500a2cad5791119233227e8b21da26ef219147a6..9bb809abe4139bcd90ad71da8490a1f7f0bed4e8 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -7,7 +7,7 @@ skip_install = True
 deps =
     -r{toxinidir}/test_requirements.txt
 commands =
-    pip install -e .[d]
+    pip install -e .[d,python2]
     coverage erase
     coverage run -m pytest tests
     coverage report