Commit Graph

774 Commits

Author SHA1 Message Date
Richard Si
12e857f24c
Document git's ignore-revs-file feature (#1419)
* Document git's ignore-revs-file feature

A long-standing counterargument against moving to automated code formatters
like Black is that the migration will clutter up the output of git blame.
This used to be a valid argument, but not anymore. Since git version 2.23,
git natively supports ignoring revisions in blame with the --ignore-rev
and --ignore-revs-file options.

This isn't documented in the Black documentation. It should be as it would
put old projects wanting to migrate to Black at ease since blame won't
be ruined.

* Add links so people can +1 on --ignore-revs-file support

* Fix wording

'Counterargument' was the wrong word since it means an objection to an objection. 'Argument' is the proper word I was looking for.

Co-authored-by: Cooper Lees <me@cooperlees.com>
2020-05-16 13:22:46 -07:00
Richard Si
97060a4f18
Expand docs about slice formatting (#1418)
Black will apply no spaces around ':' operators for 'simple' expresssions
, but will apply extra space around ':' operators for 'complex' expressions.
Black treats anything more than variable names as 'complex', but this isn't
noted in the Black documentation. Which leads to a few issues on the GitHub
issue tracker that all report inconsistent spacing around ':' operators.
2020-05-16 10:21:31 +01:00
Jelle Zijlstra
c7da3482c7
fix crashes on docstring whitespace changes (#1417)
Fixes #1415
2020-05-15 20:47:21 -07:00
Paul Meinhardt
45c98cf150
Fix Boolean values in pyproject.toml config (#1410)
Boolean values use lowercase identifiers in TOML.
https://github.com/toml-lang/toml#user-content-boolean
2020-05-13 12:51:04 -07:00
Cooper Lees
24323091c8
Remove no longer used appveyor (#1401) 2020-05-09 12:16:00 -07:00
Terrance
865f536143
Handle ImportError from multiprocessing module (#1400)
Termux's Python environment doesn't provide sem_open, but fails with a
nested `ImportError` on import attempts:

    ImportError: cannot import name 'SemLock' from '_multiprocessing'

This updates the existing handling for AWS Lambda to catch both
`OSError` and `ImportError`.
2020-05-09 09:22:23 -07:00
Sanket Dasgupta
f6393a20fc
Add preference of parantheses over backslashes in docs (#1399)
Closes https://github.com/psf/black/issues/392

Revived from https://github.com/psf/black/pull/558

Relevant to https://github.com/psf/black/issues/664
2020-05-09 06:32:29 -07:00
Hugo van Kemenade
4501f22fcb
README/CHANGES: Fix links (#1397)
* Replace relative README links with absolutes, so they work on PyPI

* CHANGES: Fix Spyder web link
2020-05-08 12:14:27 -07:00
Nathan Hunt
3de8524de6
Add py.typed file. (#1395)
* Add py.typed file
2020-05-08 09:53:07 -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
shaoran
0721f11731
Adding documentation to the README for import errors in vim (#1317)
* Adding documentation to the README for import errors in vim

I had the same issue as psf/black#1148 and have been searching for a
solution to this. I realized that you cannot fix it by change anything
in the code, but by re-compiling the C extensions of regex and
typed-ast. Installing this packages from the tarballs solves the
problem.

* Fixing a bad copy&paste

Co-Authored-By: Hugo van Kemenade <hugovk@users.noreply.github.com>

* chore: changed made by pre-commit

* chore: better way of dealing with non-binary installs

* chore: adding vim cache files to the ignore list

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-05-08 08:42:19 -07:00
Dan Davison
2da2c15b21
Add purcell/reformatter.el as an Emacs integration option (#1330) 2020-05-08 16:31:06 +01:00
Zsolt Dollenstein
7f4b275413
close event loop for all tests (#1394) 2020-05-08 16:27:50 +01:00
Hugo van Kemenade
362b722004
Test on Python 3.9-dev (#1393)
* Test on Python 3.9-dev

* Python 3.9 still in alpha, allow to fail
2020-05-08 08:19:06 -07: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
Jelle Zijlstra
702e459176
Update changelog and README (#1392)
* add two CHANGELOG entries

* update README on command-line options
2020-05-08 07:55:57 -07:00
Hugo van Kemenade
8e38b6626b
Remove deprecated --py36 option (#1236) 2020-05-08 07:47:54 -07: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
Cooper Lees
a904771093
Update CHANGELOG with some PRs merged (#1391)
* Update CHANGELOG with some PRs merged
- Add section for vim plugin
- Add vim plugin now prefering virtualenv
- Add py3 tagged wheels

* packges

* Update CHANGES.md _Black_

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>

* Update CHANGES.md Vim

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-05-08 07:29:53 -07:00
Richard Si
8c3c190f99
Add Black compatible configurations in documentation (#1366 & #1205) (#1371)
* Add Black compatible configs in docs ( #1366 & #1205)

When users of Black are starting a new project or are adding Black to their
existing projects, they will usually have to config their existing tools like
flake8 to be compatible with Black. Usually, these configs are the same across
different projects. Yet, there isn't any consolidated infomation on what configs
are compatible. Leaving users of Black to dig out any infomation they can find
in README.md.

* Fix a bad max-line-length value

* Clean up pylint's configs

* Add explanations for each configurations

Copying and pasting code without understanding it is a bad idea. This goes the same
for users copying and pasting configurations.

* Capitalize Pylint

* Link from the README

* Fix the isort configuration

I referenced the wrong source. I used a pesonal configuration, not a pure Black-
compatible configuration.

* Improve the config explanations

The explanation for the isort configuration was pretty bad. After having fixed the
configuration (see commit 01c55d1), improving the its explanation was necessary to
make it more user-friendly and understandable. Also added fenced code blocks of the
raw configuration options so the explanations make sense.

* Improve README wording slightly

* Add @hugovk, @JelleZijlstra + my suggestions

Co-authored-by: Cooper Lees <cooper@fb.com>
2020-05-08 07:26:29 -07:00
Arnav Borborah
6695fd892f
Include an easier way to integrate black with Pycharm (#1268)
* Include an easier way to integrate black with Pycharm
2020-05-08 15:13:57 +01:00
Łukasz Langa
c5f87fb4ef
Make the use of a ThreadPoolExecutor explicit 2020-05-08 16:06:33 +02:00
Zsolt Dollenstein
9104ebe5ae
better test for mono executor 2020-05-08 14:57:32 +01:00
Autophagy
ede23ae7ff Add docstrings to fmt checking functions, add to docs
Follow up from #1325

Adds docstrings to the fmt checking functions.
Renames fmt_on to is_fmt_on.
Adds the functions to the autodocs.
2020-05-08 15:47:18 +02: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
Ville Skyttä
26c9465a22
Add Change Log project URL (#1382)
* Add Change Log project URL

Co-authored-by: Cooper Lees <me@cooperlees.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-05-08 06:40:56 -07:00
kaiix
61f04e658b
Prefer virtualenv packages over global packages (#1383) (#1384) 2020-05-08 06:31:37 -07:00
Douglas Thor
8d6d92aa5b
Add option for printing a colored diff (#1266) 2020-05-08 14:30:10 +01:00
Jon Dufresne
1382eabb3f
Remove deprecated use of 'setup.py test' (#1275)
Since setuptools v41.5.0 (27 Oct 2019), the 'test' command is formally
deprecated and should not be used. Now use unittest as the test entry
point.
2020-05-08 06:23:50 -07:00
utsav-dbx
4041c560ec
Add Dropbox as a user of Black (#1335) 2020-05-08 15:23:22 +02:00
williamfzc
92c611cfdf
add bracket check in split_line (#1315) 2020-05-08 06:16:57 -07:00
David Lukes
68a3c75eb2
Make sure sys._base_executable is sane in Vim plugin (#1380)
The `venv` module relies on `sys._base_executable` to determine the
Python executable to run, but with recent versions of Vim, this is set
to the `vim` executable. A possible workaround is to just override it,
since the `black` plugin already overrides `sys.executable` (possibly
for similar reasons?) anyway.
2020-05-08 06:13:54 -07:00
Zsolt Dollenstein
1d3fb871be add change log entry for #1053 2020-05-08 14:09:15 +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
Andrew Zhou
9938c92fd7
Add error on non-list target-version in config file (#1284) 2020-05-08 06:01:42 -07: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
Cooper Lees
07c046b7cd
Move to 'py3' tagged wheels (#1388)
- This makes black wheels to be tagged as py3 default
- `python_requires=">=3.6"` ensures we are >= 3.6

Test:
```
python3 -m venv /tmp/build_black
/tmp/build_black/bin/pip install --upgrade pip setuptools wheel
/tmp/build_black/bin/python setup.py bdist_wheel
...
black-19.10b1.dev53+g81bf9bb.d20200508-py3-none-any.whl
```

Addresses #1385
2020-05-08 05:49:51 -07:00
otstrel
892eddacd2
Fix for "# fmt: on" with decorators (#1325) 2020-05-08 14:37:17 +02:00
Vlad Emelianov
c8ca6b2b9f
Issue 1144: Fix type annotations for --config option (#1166) 2020-05-08 05:10:04 -07:00
dependabot[bot]
81bf9bb961
Bump bleach from 3.1.2 to 3.1.4 (#1326)
Bumps [bleach](https://github.com/mozilla/bleach) from 3.1.2 to 3.1.4.
- [Release notes](https://github.com/mozilla/bleach/releases)
- [Changelog](https://github.com/mozilla/bleach/blob/master/CHANGES)
- [Commits](https://github.com/mozilla/bleach/compare/v3.1.2...v3.1.4)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-05-08 04:31:46 -07: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
shaoran
8126b4f6a9
Fixing the documentation of how to install the vim plugin (#1318)
* fix: Fixing the documentation of how to install the vim plugin

Solves the installation problem that currently exist because
the current master branch is not stable. See psf/black#1304 for
more information.

* fix: fixing incorrect path
2020-04-23 19:32:40 -07:00
Charles
8654e8d7ae
Update heredoc marker case to conform with vim patch 8.1.1723 (#1348) 2020-04-16 19:26:09 -07:00
MomIsBestFriend
af7105f9ab
Small nitpicks (#1340)
Co-authored-by: MomIsBestFriend <>
2020-04-11 20:30:24 -07:00
Rémi Verschelde
959848c176
Fix --diff output when encountering EOF (#1328)
`split("\n")` includes a final empty element `""` if the final line
ends with `\n` (as it should for POSIX-compliant text files), which
then became an extra `"\n"`.

`splitlines()` solves that, but there's a caveat, as it will split
on other types of line breaks too (like `\r`), which may not be
desired.

Fixes #526.
2020-04-04 22:02:57 -07:00
Zsolt Dollenstein
9ed2542e93
Omit commit hash and date stamp from doc version (#1322)
This also removes the dependency on setuptools-scm while building the
docs.

Fixes #1104.
2020-03-28 19:06:00 -07:00
Quentin Pradet
7e4c6bf71f
Add missing separator in README (#1320) 2020-03-27 10:28:10 -07:00
Zsolt Dollenstein
a33823e859
Fix readthedocs build (#1321)
* migrate to new rtd config format and pip

* no type field anymore

* use builtin re for docs
2020-03-27 11:43:41 +01:00