Add fast option to Black
Black takes arguments. How do we pipe these in? For example, I'd like to send Black the --fast command-line arguments.
https://github.com/diffplug/spotless/blob/224f8f96df3ad42cac81064a0461e6d4ee91dcaf/plugin-maven/src/main/java/com/diffplug/spotless/maven/python/Black.java#L25-L31
We can add a property to run it fast:
--fast / --safe By default, Black performs an AST safety
check after formatting your code. The --fast
flag turns off this check and the --safe
flag explicitly enables it. [default:
--safe]
I'm also seeing that args is a private field that is never assigned outside this class:
https://github.com/diffplug/spotless/blob/1ad019da39f8994d5b7ccd86a536678cb38fbdea/lib/src/main/java/com/diffplug/spotless/python/BlackStep.java#L89-L107
Here's an example of one that takes a command-line argument:
- https://github.com/diffplug/spotless/blob/1ad019da39f8994d5b7ccd86a536678cb38fbdea/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java#L44-L46
- https://github.com/diffplug/spotless/blob/1ad019da39f8994d5b7ccd86a536678cb38fbdea/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java#L126-L129
Actually, running black from the command-line was very fast even without the flag.
When I run mvn spotless:apply on the same code, it's extremely slow.
OK, I fixed the problem by altering my include/exclude tags. Now it's fast without any modifications to spotless:
diff --git a/pom.xml b/pom.xml
index 3eee11b8..df773850 100644
--- a/pom.xml
+++ b/pom.xml
@@ -201,13 +201,8 @@
</pom>
<python>
<includes>
- <include>**/*.py</include>
+ <include>.</include>
</includes>
- <excludes>
- <!-- Don't format generated files. -->
- <exclude>**/bin/</exclude>
- <exclude>**/target/</exclude>
- </excludes>
<black>
<version>${black.version}</version>
</black>
I just told black to process all files and walla. I think it would still be helpful, however, to have a property for --fast.