Commit Graph

274 Commits

Author SHA1 Message Date
Richard Si
6ebdc5a644
Fix toml parsing and bump toml from 0.10.0 to 0.10.1 (#1501)
* Bump toml from 0.10.0 to 0.10.1 to fix a bug

* Add tests for TOML parsing and reading

* Fix configuration bug affecting vim plugin

The vim plugin directly calls parse_pyproject and skips the Click processing
, but parse_pyproject assumed that it would only be used before Click processing
and therefore made the config values click friendly. This moves the "make the values
click friendly processing" into read_pyproject_toml which is only called by a Click
callback.

* Please mypy and flake8
2020-06-16 11:58:33 -07:00
Cooper Lees
8acc22f114
Add black-primer unittests (#1426)
* Add black-primer unittests

- Get this tool covered with some decent unittests for all unittests wins
- Have a CLI and lib test class
- Import it from `test_black.py` so we always run tests
- Revert typing asyncio.Queue as Queue[str] so we can work in 3.6
- **mypy**: Until black > 3.6 disallow_any_generics=False for primer code

Test:
- Run tests: `coverage run tests/test_primer.py` or `coverage run -m unittest`
```
(b) cooper-mbp1:black cooper$ coverage report
Name                      Stmts   Miss  Cover
---------------------------------------------
src/black_primer/cli.py      49      8    84%
src/black_primer/lib.py     148     28    81%
tests/test_primer.py        114      1    99%
---------------------------------------------
TOTAL                       311     37    88%
```

* Use ProactorEventLoop for Windows + fix false path for Linux

* Set Windows to use ProactorEventLoop in  to benefit all callers

* sys.platform seems to not having the loop applied - So type ignore and use platform.system() gate

* Have each test loop correctly set to ProactorEventLoop on Windows for < 3.8 too
2020-05-17 12:18:49 -07:00
Hugo van Kemenade
03b8304abd
Update and fix Flake8 (#1424)
* Update pre-commit

* Fix F541 f-string is missing placeholders

* Fix E741 ambiguous variable name 'l'

* Update actions to v2
2020-05-17 07:18:45 -07:00
Cooper Lees
2082a325fd
Refactor black into packages in src/ dir (#1376)
- Move black.py to src/black/__init__.py
- Have setuptools_scm make src/_black_version.py and exclude from git
- Move blackd.py to src/blackd/__init__.py
- Move blib2to3/ to src/
- Update `setup.py`
- Update unittests to pass
  - Mostly path fixing + resolving
- Update CI
  - pre-commit config
  - appveyor + travis

Tested on my mac with python 3.7.5 via:
```
python3 -m venv /tmp/tb3
/tmp/tb3/bin/pip install --upgrade setuptools pip coverage pre-commit
/tmp/tb2/bin/pip install ~/repos/black/
cd ~/repos/black/
/tmp/tb2/bin/coverage run tests/test_black.py
/tmp/tb3/bin/pre-commit run -a
/tmp/tb3/bin/black --help
/tmp/tb3/bin/black ~/repos/ptr/ptr.py
```
2020-05-08 08:50:50 -07:00
Zsolt Dollenstein
7f4b275413
close event loop for all tests (#1394) 2020-05-08 16:27:50 +01:00
Zsolt Dollenstein
703faa3233 Fix mono test 2020-05-08 16:15:31 +01:00
Zsolt Dollenstein
6ea76e9b4f Improve error messages from BlackRunner 2020-05-08 16:15:31 +01:00
Giacomo Tagliabue
89c87d22e7
add --force-exclude argument (#1032)
Co-authored-by: Peter Yu <2057325+yukw777@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2020-05-08 07:47:26 -07:00
Zsolt Dollenstein
67726a7cf3
skip mono test while im working on it 2020-05-08 15:37:08 +01:00
Zsolt Dollenstein
9104ebe5ae
better test for mono executor 2020-05-08 14:57:32 +01:00
Allan Simon
c0a7582e3d
permits black to run in AWS Lambda: (#1141)
AWS Lambda and some other virtualized environment may not permit access
to /dev/shm on Linux and as such, trying to use ProcessPoolExecutor will
fail.

As using parallelism is only a 'nice to have' feature of black, if it fails
we gracefully fallback to a monoprocess implementation, which permits black
to finish normally.

Co-authored-by: Allan Simon <asimon@yolaw.fr>
2020-05-08 15:46:07 +02:00
Douglas Thor
8d6d92aa5b
Add option for printing a colored diff (#1266) 2020-05-08 14:30:10 +01:00
Alex Vandiver
a4c11a75e1
Re-indent the contents of docstrings (#1053)
* Re-indent the contents of docstrings when indentation changes

Keeping the contents of docstrings completely unchanged when
re-indenting (from 2-space intents to 4, for example) can cause
incorrect docstring indentation:

```
class MyClass:
  """Multiline
  class docstring
  """

  def method(self):
    """Multiline
    method docstring
    """
    pass
```
...becomes:
```
class MyClass:
    """Multiline
  class docstring
  """

    def method(self):
        """Multiline
    method docstring
    """
        pass
```

This uses the PEP 257 algorithm for determining docstring indentation,
and adjusts the contents of docstrings to match their new indentation
after `black` is applied.

A small normalization is necessary to `assert_equivalent` because the
trees are technically no longer precisely equivalent -- some constant
strings have changed.  When comparing two ASTs, whitespace after
newlines within constant strings is thus folded into a single space.

Co-authored-by: Luka Zakrajšek <luka@bancek.net>

* Extract the inner `_v` method to decrease complexity

This reduces the cyclomatic complexity to a level that makes flake8 happy.

* Blacken blib2to3's docstring which had an over-indent

Co-authored-by: Luka Zakrajšek <luka@bancek.net>
Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
2020-05-08 14:08:15 +01:00
Bryan Bugyi
544ea9c217
Improve String Handling (#1132)
This pull request's main intention is to wraps long strings (as requested by #182); however, it also provides better string handling in general and, in doing so, closes the following issues:

Closes #26
Closes #182
Closes #933
Closes #1183
Closes #1243
2020-05-08 14:56:21 +02:00
otstrel
892eddacd2
Fix for "# fmt: on" with decorators (#1325) 2020-05-08 14:37:17 +02:00
Toby Fleming
7a14a37981
Change exit code to 2 when config file doesn't exist (#1361)
Fixes #1360, where an invalid config file causes a return/exit code of 1. This
change means this case is caught earlier, treated like any other bad
parameters, and results in an exit code of 2.

Co-authored-by: Toby Fleming <tobywf@users.noreply.github.com>
2020-04-30 08:47:52 +01:00
Vlad Emelianov
be49ac72a0 Support py38-style starred expressions in return statement (#1121) 2020-01-18 07:21:46 -08:00
kyle hausmann
a02829bea1 Use conditional case for diff reports (#1226)
When --diff flag is used, black will now use the
conditional case in the Report output: eg "would
be reformatted"
2020-01-18 07:13:15 -08:00
Michael J. Sullivan
3e60f6d454 Support compilation with mypyc (#1009)
* Make most of blib2to3 directly typed and mypyc-compatible

This used a combination of retype and pytype's merge-pyi to do the
initial merges of the stubs, which then required manual tweaking to
make actually typecheck and work with mypyc.

Co-authored-by: Sanjit Kalapatapu <sanjitkal@gmail.com>
Co-authored-by: Michael J. Sullivan <sully@msully.net>

* Make black able to compile and run with mypyc

The changes made fall into a couple categories:
 * Fixing actual type mistakes that slip through the cracks
 * Working around a couple mypy bugs (the most annoying of which being
   that we need to add type annotations in a number of places where
   variables are initialized to None)

Co-authored-by: Sanjit Kalapatapu <sanjitkal@gmail.com>
Co-authored-by: Michael J. Sullivan <sully@msully.net>
2019-10-30 07:29:29 -07:00
Lawrence Chan
23fec8b0f7 Fix fmt on/off when multiple exist in leaf prefix (#1086)
The old behavior would detect the existence of a `# fmt: on` in a leaf
node's comment prefix and immediately mark the node as formatting-on,
even if a subsequent `# fmt: off` in the same comment prefix would turn
it back off. This change modifies that logic to track the state through
the entire prefix and take the final state.

Note that this does not fully solve on/off behavior, since any _comment_
lines between the off/on are still formatted. We may need to add
virtual leaf nodes to truly solve that. I will leave that for a separate
commit/PR.

Fixes #1005
2019-10-28 20:51:45 +01:00
Joe Antonakakis
df6e1a41f7 Add diff support to blackd (#969) 2019-10-28 14:25:26 +01:00
jgirardet
e9d4e7b67f add gitignore support using pathspec (#878) 2019-10-21 11:44:53 +02:00
Augie Fackler
9854d4b375 Tweak collection literals to explode with trailing comma (#826) 2019-10-20 16:08:34 +02:00
Michael J. Sullivan
0ff718e1e2 Blacken .py files in blib2to3 (#1011)
* Blacken .py files in blib2to3

This is in preparation for adding type annotations to blib2to3 in
order to compiling it with mypyc (#1009, which I can rebase on top of
this).

To enforce that it stays blackened, I just cargo-culted the existing
test code used for validating formatting. It feels pretty clunky now,
though, so I can abstract the common logic out into a helper if that
seems better. (But error messages might be less clear then?)

* Tidy up the tests
2019-10-20 15:55:31 +02:00
Linus Groh
73bd7038fb Add black version header to blackd responses (#1046) 2019-10-13 11:35:31 -07:00
Andrey
6aef6c9d45 #455 Fix bug with tricky unicode symbols (#1047)
* add test for special unicode symbol which usual re can not process correctly
add regex lib which supports unicode 12.1.0 standard
replace re usage in project in favor to regex

* #455 fix dependency
2019-10-13 10:21:15 -07:00
vezeli
c4d2db4323 Change variable in README according to the PEP8 (#1002)
* Change variable in README according to the PEP8
* Change variable in tests according to the PEP8
2019-09-04 09:11:07 +01:00
Zsolt Dollenstein
40e8b3a231 [blackd] Support py36-style values in X-Python-Variant header (#979) 2019-08-13 08:26:01 -07:00
Zsolt Dollenstein
bd0ab3cba2
Reraise exception in skip_if_exception decorator 2019-08-05 10:07:43 +01:00
Joe Antonakakis
154b98579d Fix async blackd tests which won't fail currently (#966) 2019-08-05 10:06:12 +01:00
Joe Antonakakis
c7495b9aa0 Fix unstable format involving backslash + whitespace at beginning of file (#948) 2019-08-04 10:03:19 +01:00
Zsolt Dollenstein
e66451761f appease flake8... 2019-07-28 16:40:04 +01:00
Zsolt Dollenstein
6b5eb7d465 skip tests touching aiohttp when known exception occurs 2019-07-28 16:35:10 +01:00
Zsolt Dollenstein
2848e2e1d6
Support PEP-570 (positional only arguments) (#946)
Code using positional only arguments is considered >= 3.8
2019-07-28 16:17:33 +01:00
Zsolt Dollenstein
d8fa8df052
Add support for walrus operator (#935)
* Parse `:=` properly
* never unwrap parenthesis around `:=`
* When checking for AST-equivalence, use `ast` instead of `typed-ast` when running on python >=3.8
* Assume code that uses `:=` is at least 3.8
2019-07-28 16:03:23 +01:00
dylanjblack
9394de150e Fix trailing comma for function with one arg (#880) (#891)
Modified maybe_remove_trailing_comma to remove trailing commas for
typedarglists (in addition to arglists), and updated line split logic
to ensure that all lines in a function definition that contain only one
arg have a trailing comma.
2019-06-14 21:49:49 -07:00
Jelle Zijlstra
957ba24bb6
remove obviously unnecessary parentheses (#850)
Fixes #548
2019-05-15 21:11:04 -07:00
Benjamin Woodruff
f8617f975d
Add support for always tokenizing async/await as keywords
Fixes #593

I looked into this bug with @ambv and @carljm, and we reached the
conclusion was that it's not possible for the tokenizer to determine if
async/await is a keyword inside all possible generators without breaking
the grammar for older versions of Python.

Instead, we introduce a new tokenizer mode for Python 3.7+ that will
cause all async/await instances to get parsed as a reserved keyword,
which should fix async/await inside generators.
2019-05-09 17:59:29 +02:00
Jason Fried
866be06646 Make --safe work for Python2.7 syntax, by using typed_ast for safe validation (#840) 2019-05-08 07:45:59 -07:00
Carl Meyer
6fdbdb4ee3
Avoid unstable formatting when comment follows escaped newline. (#839). Fixes #767. 2019-05-08 09:53:20 -04:00
Jelle Zijlstra
de806405d2 Add parentheses around tuple unpack assignment (#832)
Fixes #656
2019-05-07 09:51:28 -04:00
Jelle Zijlstra
6b994fdb8a
fix handling of comments in from imports (#829)
Fixes #671
2019-05-06 09:13:25 -04:00
Jelle Zijlstra
cea13f4984
Split the TRAILING_COMMA feature (#763) 2019-03-25 08:22:02 -07:00
Jelle Zijlstra
ba64fc757c
redo grammar selection, add test (#765) 2019-03-16 11:35:18 -07:00
Andy Freeland
d6db1c12a8 Fix print() function on Python 2 (#754)
Fixes #752
2019-03-14 16:42:54 -07:00
Łukasz Langa
6af55d8851
Mention tab comment fixes, extend tests 2019-03-14 17:17:50 +01:00
Anders-Petter Ljungquist
227c2d77b4 Changes default logger used by blib2to3 Driver (#732)
... to stop it from spamming the log when black is used as a library in another
    python application.

When used indirectly by black the logger initiated in `driver.py` will emit
thousands of debug messages making the debug level of the root logger virtually
useless. By getting a named logger instead the verbosity of logging from this
module can easily be controlled by setting its log level.

Fixes #715
2019-03-14 13:39:42 +01:00
Jelle Zijlstra
ea55ff2878
remove Python implementation-specific versions (#736) 2019-03-07 16:34:34 -08:00
Jelle Zijlstra
21ab37a5d9
remove --py36 (#724)
Fixes #703.
2019-02-24 09:15:03 -08:00
Zsolt Dollenstein
250ba7f04b Remove numeric underscore normalization (#696) 2019-02-06 19:16:49 -08:00
Jelle Zijlstra
36d3c516d3
Add --target-version option to allow users to choose targeted Python versions (#618) 2019-02-06 18:43:50 -08:00
Samuel Cormier-Iijima
66aa676278 Fix indent calculation with tabs when computing prefixes (#595)
Closes #262
2019-02-04 18:55:01 -08:00
Jan Hnátek
f6643c4f0c Fix location of expression.diff in the change notification message (#670) 2019-02-04 18:42:42 -08:00
Utsav Shah
024c9cab55 Add support for special comments in multiline functions (#642) 2019-01-05 11:20:12 -08:00
Jim Brännlund
4809e365d4 Silence expected stderr (#621)
* Silence expected stderr output during test

* Change based on PR comment
2018-11-29 21:43:22 +00:00
Jelle Zijlstra
8d58827376
Refactor Travis (#614)
Fixes #305 

- Run separate jobs for mypy, self-formatting, flake8, and test runs.
- Don't run flake8 in 3.8 because it is broken (and we can't really expect flake8 to always keep up with 3.8 development).
- Fix unused variable in test
2018-11-20 08:42:43 -08:00
Zsolt Dollenstein
5f9eb9e4f7 Add underscores to numeric literals with more than six digits (#529) 2018-09-26 12:32:11 +01:00
Zsolt Dollenstein
a82f186787 blackd: a HTTP server for blackening (#460) 2018-09-17 10:02:25 -07:00
Zsolt Dollenstein
66a6be642c fix lint errors 2018-08-26 21:27:33 +01:00
Zsolt Dollenstein
401836d02e add test case for preserving newlines from stdin 2018-08-26 21:19:22 +01:00
Jelle Zijlstra
b53cb94743 fix bracket match bug (#470)
* fix bracket match bug

* add missing test file
2018-08-23 12:52:07 +01:00
Zsolt Dollenstein
883689366c Support parsing of async generators in non-async functions (#165)
This is a new syntax added in python3.7, so black can't verify that reformatting will not change the ast unless black itself is run with 3.7. We'll need to change the error message black gives in this case. @ambv any ideas?

Fixes #125.
2018-08-20 14:47:58 +01:00
Jelle Zijlstra
b719d85ccc
autodetect Python 3.6 on the basis of underscores (#461) 2018-08-19 21:02:06 -07:00
Jelle Zijlstra
cc48bc56ca normalize numeric literals (#454)
Fixes #452

I ended up making a couple of other normalizations to numeric literals
too (lowercase everything, don't allow leading or trailing . in floats,
remove redundant + sign in exponent). I don't care too much about those,
so I'm happy to change the behavior there.

For reference, here is Python's grammar for numeric literals:
https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
2018-08-17 15:03:58 +01:00
Zsolt Dollenstein
df965b0558 update to mypy 0.620 and make tests pass again
Fixes #408
2018-07-18 22:10:52 +01:00
Zsolt Dollenstein
dd8bde6d2f Improve get_future_imports implementation.
Closes #389.
2018-07-02 17:49:47 +01:00
Łukasz Langa
048efa7476 Trivial nits 2018-06-19 23:08:10 -07:00
Łukasz Langa
2dfa69bb7f Stop Click from crashing Black on invalid environments
Fixes #277
2018-06-19 22:55:57 -07:00
Łukasz Langa
df2ae3bbe6 Use the separate pass for # fmt: off on all code
This removes the hacky exception-based handling that didn't work across
statement boundaries.

Fixes #335
2018-06-19 17:32:41 -07:00
Neraste
42a3fe5331 Ignore symbolic links pointing outside of the root directory (#339)
Fixes #338
2018-06-13 00:07:04 -07:00
Łukasz Langa
ec31ee967d Make test_black.py work in profilers 2018-06-09 18:49:39 -07:00
Łukasz Langa
489d00ed8f Support pyproject.toml
Fixes #65
2018-06-06 17:02:10 -07:00
Łukasz Langa
f71db23824 Move test data to data 2018-06-06 15:48:38 -07:00
Zsolt Dollenstein
33baccd88e Change tests with stdin/out to exercise black.main (#307) 2018-06-06 15:42:50 -07:00
Łukasz Langa
7fc6ce9906 Fix handling of empty files 2018-06-04 19:04:29 -07:00
Łukasz Langa
728e5a2f1e Properly format unified diff
Previously we weren't using timestamps.
2018-06-04 18:07:03 -07:00
Łukasz Langa
ed91dd4de6 Make source handling use sets instead of lists
Also, sort cached file output to be (more) deterministic.
2018-06-04 15:53:37 -07:00
Zsolt Dollenstein
00a302560b Preserve line endings when formatting a file in place (#288) 2018-06-04 15:52:06 -07:00
Łukasz Langa
4c352ad4be Add --verbose and report excluded paths in it, too
Fixes #283
2018-06-04 12:09:18 -07:00
Łukasz Langa
36bed855e1 Introduce "project root" as a concept
This is required for regular expressions in `--include=` and `--exclude=` not
to catch false positives from directories outside of the project.
2018-06-04 11:03:18 -07:00
Zsolt Dollenstein
ef903ecd46 Skip symlink test if can't create one (#287) 2018-06-01 14:47:07 -07:00
Łukasz Langa
8a82e0bf9a Make empty --include mean "anything goes", simplify gen_python_files_in_dir 2018-05-31 19:40:07 -07:00
Mika⠙
51756a405c Added --include and --exclude cli options (#281)
These 2 options allow you to pass in regular expressions that determine
whether files/directories are included or excluded in the recursive file
search.

Fixes #270
2018-05-31 17:51:15 -07:00
Łukasz Langa
8ebbd26888 Add --skip-string-normalization
Fixes #118
2018-05-30 12:56:16 -07:00
Łukasz Langa
023e61a254 Refactor --pyi and --py36 into FileMode 2018-05-29 01:53:54 -07:00
Luka Sterbic
e818260f1a Class new line between docstrings / vars / methods (#219)
Partially addresses #144
2018-05-28 23:48:59 -07:00
Carl Meyer
07b1b2f3dd Add --pyi and --py36 flags (#249)
Fixes #244.
2018-05-23 11:01:26 -07:00
Jelle Zijlstra
14ba1bf8b6 Add support for pyi files (#210)
Fixes #207
2018-05-15 15:09:35 -04:00
Miguel Gaiowski
c667b85a7f Check for broken symlinks before checking file data (#202) 2018-05-15 01:13:48 -04:00
Jelle Zijlstra
21c8dc85f5 Remove u prefix if unicode_literals is present (#199) 2018-05-09 18:26:41 -04:00
Łukasz Langa
1747c388bb Discover whether a file is Python 3.6+ also by stars in calls
Fixes a pathological situation where if a function signature used a trailing
comma but was later reformatted to a single line (with the trailing comma
removed), Black would change its mind whether a file is Python
3.6-compatible between runs.
2018-05-08 21:57:09 -07:00
snlkapil
6dbb657681 Removing empty parentheses after class name (#180) 2018-05-07 10:15:24 -07:00
Christian Heimes
2d9eaafa97 Output something when no files are reformatted (#190)
Just executing ``black`` without any argument does not print any message
to stdout or stderr. It's rather confusing, because the user doesn't
know what happened.

In ``len(sources) == 0`` case, black now prints ``No paths given. Nothing to
do``.

Signed-off-by: Christian Heimes <christian@python.org>
2018-05-07 10:12:47 -07:00
Zsolt Dollenstein
9f096d5536 Format subscriptions in a PEP-8 compliant way (#178)
Fixes #157
2018-04-30 22:49:30 -07:00
Jonas Obrist
92957a41e3 Make cache work with non-default line lenghts (#163) 2018-04-24 11:56:50 -07:00
Łukasz Langa
52fda8b0e9 Support sticky standalone comments (comments preceding defs, classes, and decorators)
Fixes #56
Fixes #154
2018-04-24 11:50:31 -07:00
Vishwas B Sharma
29e97d1d4a [#154] Handle comments between decorators properly (#166) 2018-04-24 09:38:12 -07:00
Łukasz Langa
54d707e10a Allow standalone comments to close code blocks
Fixes #16
Fixes #32
2018-04-23 16:17:12 -07:00
Łukasz Langa
06e95b1e9b Show full path on diffs
Fixes #130
2018-04-23 12:00:03 -07:00
Zsolt Dollenstein
c012c70176 Fix tests on windows (#159) 2018-04-23 11:23:36 -07:00
Vishwas B Sharma
5e1e1a1820 [#149] Make check and diff not mutually exclusive (#161)
Fixes #149.
2018-04-23 11:23:11 -07:00
Łukasz Langa
8429f3a63b Revert format_file_in_place() and format_stdin_to_stdout() to return bools
`Changed.CACHED` is meaningless for those two functions.
2018-04-18 17:46:03 -07:00
Jonas Obrist
639b62dcd3 Added caching (#136)
Black will cache already formatted files using their file size and
modification timestamp. The cache is per-user and will always be used
unless Black is used with --diff or with code provided via standard
input.
2018-04-18 17:27:07 -07:00
Łukasz Langa
a764f1bb3b Generalize star expression handling
Fixes #132
2018-04-16 01:34:15 -07:00
Zsolt Dollenstein
8e7848c63e Open temporary files with utf-8 encoding (#126)
This is not the default on Windows.
2018-04-12 11:19:21 -07:00
Łukasz Langa
cb5aadad74 Automatic parentheses management
Fixes #4
2018-04-11 01:36:18 -07:00
Łukasz Langa
1d45f6e6a1 Improve test coverage a bit 2018-03-31 15:46:09 -07:00
Łukasz Langa
a20a3eeb0f Support --diff for both files and stdin
Fixes #87
2018-03-31 15:46:09 -07:00
Zsolt Dollenstein
80bd2b3134 Normalize string quotes (#75)
* Normalize string quotes

Convert single-quoted strings to double-quoted. Convert triple single-quoted strings to triple double-quoted. Do not touch any strings where conversion would increase the number of backslashes.

Fixes #51.

* reformat Black itself
2018-03-31 11:21:25 -07:00
Łukasz Langa
17b22642f5 More comments tests 2018-03-29 21:19:20 -07:00
Łukasz Langa
c55d08d0b9 Remove standalone comment hacks
Now Black properly splits standalone comments within bracketed expressions.
They are treated as another type of split instead of being bolted on with
whitespace prefixes.

A related fix: now multiple comments might appear after a given leaf.

Fixes #22
2018-03-29 21:10:00 -07:00
Łukasz Langa
fc869039eb Don't crash and burn on empty lines with trailing whitespace
Fixes #80
2018-03-26 18:41:25 -07:00
Łukasz Langa
0677a53937 Implement # fmt: off and # fmt: on
Fixes #5
2018-03-23 17:16:08 -07:00
Łukasz Langa
7e1c5b2ba6 Introduce DebugVisitor.show() + tests 2018-03-23 16:08:05 -07:00
Łukasz Langa
6316e293ac Automatic detection of deprecated Python 2 forms of print and exec
Note: if those are handled, you can't use --safe because this check is using
Python 3.6+ builtin AST.

Fixes #49
2018-03-22 23:19:23 -07:00
Łukasz Langa
8de552eb4f Only return exit code 1 when --check is used
Also, output less confusing messages in --check.

Fixes #50
2018-03-22 17:33:44 -07:00
Łukasz Langa
591bedc2be Support skipping AST printing on test failure 2018-03-20 18:55:04 -07:00
Łukasz Langa
d1e0d79e38 Don't write back stdin to stdout when --check is passed 2018-03-20 18:54:55 -07:00
Łukasz Langa
e911c79809 Don't remove single empty lines outside of bracketed expressions
Fixes #19
2018-03-20 18:54:19 -07:00
treuherz
10d8976a79 Add piping from stdin to stdout with a - (#25)
Being able to format code by piping it through the formatter makes it much easier to integrate with tools like google/vim-codefmt or Chiel92/vim-autoformat.
2018-03-19 11:07:10 -07:00
Łukasz Langa
9fea478022 Also run mypy on test_black.py 2018-03-15 23:55:22 -07:00
Łukasz Langa
5fb5cc8c2b Only use trailing commas in function signatures when it's safe
Trailing commas after * or ** in a function signature are only safe for Python 3.6
code.  So now Black checks whether the file was already Python 3.6 to begin
with.  If so, trailing commas are used in such cases.  Otherwise, they're not.

When * and ** don't appear in a function signature, the trailing comma is
always safe.

Fixes #8
2018-03-15 19:44:09 -07:00
Łukasz Langa
c85cb48ec2 Fix tests after introducing --check 2018-03-15 17:05:59 -07:00
Łukasz Langa
e74117f172 Initial commit 2018-03-14 12:55:32 -07:00