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

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:

etc/vim.git
2 years agoUpdate CHANGES.md for 21.7b0 release (#2376)
Cooper Lees [Fri, 16 Jul 2021 14:42:47 +0000 (07:42 -0700)]
Update CHANGES.md for 21.7b0 release (#2376)

* Update CHANGES.md for 21.7b0 release

* move some changes to the right section

* another one

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoCreate Docker tag 'latest_release' (#2374)
pszlazak [Fri, 16 Jul 2021 14:26:29 +0000 (16:26 +0200)]
Create Docker tag 'latest_release' (#2374)

Docker images created during release process will have extra tag 'latest_release'.

This closes #2373.

2 years agoDon't include profiling/ to cut down sdist by ~2x (#2362)
Richard Si [Fri, 16 Jul 2021 00:21:53 +0000 (20:21 -0400)]
Don't include profiling/ to cut down sdist by ~2x (#2362)

They seem to be used as test cases for a specific region of formatting
that was slow. Now performance testing is probably something end users
won't be needing to do, so this is an easy way of reducing the sdist
size sigificantly.

2 years agoImprove AST safety parsing error message (#2304)
Felix Hildén [Tue, 13 Jul 2021 17:24:55 +0000 (20:24 +0300)]
Improve AST safety parsing error message (#2304)

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2 years agoSwitch `toml` TOML library for `tomli` (#2301)
Richard Si [Mon, 12 Jul 2021 20:01:38 +0000 (16:01 -0400)]
Switch `toml` TOML library for `tomli` (#2301)

toml unfortunately has a lack of maintainership issue right now. It's
evident by the fact toml only supports TOML v0.5.0. TOML v1.0.0 has
been recently released and right now Black crashes hard on its usage.

tomli is a brand new parse only TOML library. It supports TOML
v1.0.0. Although TBH we're switching to this one mostly because
pip is doing the same.

*The upper bound was included at the library maintainer's request.

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Taneli Hukkinen <3275109+hukkin@users.noreply.github.com>
2 years agoAdd LocalStack and Twisted to projects using Black
Łukasz Langa [Mon, 12 Jul 2021 09:56:03 +0000 (11:56 +0200)]
Add LocalStack and Twisted to projects using Black

2 years agoSecond run of tox -e py results in a test error for test marked with no_python2 ...
Marco Edward Gorelli [Sun, 11 Jul 2021 20:03:36 +0000 (21:03 +0100)]
Second run of tox -e py results in a test error for test marked with no_python2 (#2369)

Fixes #2367

2 years agoUse setuptools.find_packages in setup (#2363)
Felix Hildén [Sat, 10 Jul 2021 00:09:29 +0000 (03:09 +0300)]
Use setuptools.find_packages in setup (#2363)

* Use setuptools.find_packages in setup

* Address mypy errors

2 years agoAvoid src being marked as optional in help (#2356)
Richard Si [Fri, 9 Jul 2021 01:46:32 +0000 (21:46 -0400)]
Avoid src being marked as optional in help (#2356)

2 years agofix typo (#2358)
Marco Edward Gorelli [Sun, 4 Jul 2021 18:23:00 +0000 (19:23 +0100)]
fix typo (#2358)

2 years agoAccept empty stdin (close #2337) (#2346)
simaki [Wed, 23 Jun 2021 19:11:23 +0000 (04:11 +0900)]
Accept empty stdin (close #2337) (#2346)

Commit history before merge:

* Accept empty stdin (close #2337)
* Update tests/test_black.py
* Add changelog
* Assert Black reformats an empty string to an empty string (#2337) (#2346)
* fix

2 years agoGet `click` types from main repo (#2344)
Taneli Hukkinen [Tue, 22 Jun 2021 15:58:49 +0000 (18:58 +0300)]
Get `click` types from main repo (#2344)

Click types have been moved to click repo itself. See pallets/click#1856

I've had some issues with typeshed types being outdated in another project
so might be good to avoid that here.

Commit history before merge:

* Get `click` types from main repo
* Fix mypy errors
* Require click v8 for type annotations
* Update Pipfile

2 years agoUpdate pre-commit config (#2331)
SADIK KUZU [Tue, 22 Jun 2021 01:28:25 +0000 (04:28 +0300)]
Update pre-commit config (#2331)

via `pre-commit autoupdate`

```
Updating https://gitlab.com/pycqa/flake8
... updating 3.9.0 -> 3.9.2.
Updating https://github.com/pre-commit/mirrors-mypy
... updating v0.812 -> v0.902.
Updating https://github.com/pre-commit/mirrors-prettier
... updating v2.2.1 -> v2.3.1.
```

Signed-off-by: SADIK KUZU <sadikkuzu@hotmail.com>
* Add necessary typeshed packages to requirements

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoAdd Duolingo to list of users (#2341)
Art Chaidarun [Thu, 17 Jun 2021 16:32:03 +0000 (12:32 -0400)]
Add Duolingo to list of users (#2341)

2 years agoChat on Discord instead of Freenode (#2336)
Felix Hildén [Tue, 15 Jun 2021 14:37:59 +0000 (17:37 +0300)]
Chat on Discord instead of Freenode (#2336)

Now that we've moved, let's direct our users to Discord in the
documentation and readme.

2 years agoDocs: no space is inserted to empty docstrings (#2249) (#2333)
Felix Hildén [Sun, 13 Jun 2021 19:27:57 +0000 (22:27 +0300)]
Docs: no space is inserted to empty docstrings (#2249) (#2333)

2 years agoAdd EOF and trailing whitespace fixer to pre-commit config (#2330)
jack1142 [Sun, 13 Jun 2021 17:22:46 +0000 (19:22 +0200)]
Add EOF and trailing whitespace fixer to pre-commit config (#2330)

2 years agoFix internal error when FORCE_OPTIONAL_PARENTHESES feature is enabled (#2332)
Bryan Bugyi [Sun, 13 Jun 2021 17:20:50 +0000 (13:20 -0400)]
Fix internal error when FORCE_OPTIONAL_PARENTHESES feature is enabled (#2332)

Fixes #2313.

2 years agoVim plugin fix string normalization option (#1869)
Bartosz Telenczuk [Sat, 12 Jun 2021 19:55:10 +0000 (21:55 +0200)]
Vim plugin fix string normalization option (#1869)

This commit fixes parsing of the skip-string-normalization option in vim
plugin. Originally, the plugin read the string-normalization option,
which does not exist in help (--help) and it's not respected by black
on command line.

Commit history before merge:

* fix string normalization option in vim plugin
* fix string normalization option in vim plugin
* Finish and fix patch (thanks Matt Wozniski!)

FYI: this is totally the work and the comments below of Matt (AKA godlygeek)

This fixes two entirely different problems related to how pyproject.toml
files are handled by the vim plugin.

=== Problem #1 ===

The plugin fails to properly read boolean values from pyproject.toml.
For instance, if you create this pyproject.toml:

```
[tool.black]
quiet = true
```

the Black CLI is happy with it and runs without any messages, but the
:Black command provided by this plugin fails with:

```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 102, in Black
  File "<string>", line 150, in get_configs
  File "<string>", line 150, in <dictcomp>
  File "/usr/lib/python3.6/distutils/util.py", line 311, in strtobool
    val = val.lower()
AttributeError: 'bool' object has no attribute 'lower'
```

That's because the value returned by the toml.load() is already a
bool, but the vim plugin incorrectly tries to convert it from a str to a bool.

The value returned by toml_config.get() was always being passed to
flag.cast(), which is a function that either converts a string to an
int or a string to a bool, depending on the flag. vim.eval()
returns integers and strings all as str, which is why we need the cast,
but that's the wrong thing to do for values that came from toml.load().
We should be applying the cast only to the return from vim.eval()
(since we know it always gives us a string), rather than casting the
value that toml.load() found - which is already the right type.

=== Problem #2 ===

The vim plugin fails to take the value for skip_string_normalization
from pyproject.toml. That's because it looks for a string_normalization
key instead of a skip_string_normalization key, thanks to this line
saying the name of the flag is string_normalization:

black/autoload/black.vim (line 25 in 05b54b8)
```
 Flag(name="string_normalization", cast=strtobool),
```

and this dictcomp looking up each flag's name in the config dict:

black/autoload/black.vim (lines 148 to 151 in 05b54b8)
```
 return {
   flag.var_name: flag.cast(toml_config.get(flag.name, vim.eval(flag.vim_rc_name)))
   for flag in FLAGS
 }
```

For the second issue, I think I'd do a slightly different patch. I'd
keep the change to invert this flag's meaning and change its name that
this PR proposes, but I'd also change the handling of the
g:black_skip_string_normalization and g:black_string_normalization
variables to make it clear that g:black_skip_string_normalization is
the expected name, and g:black_string_normalization is only checked
when the expected name is unset, for backwards compatibility.

My proposed behavior is to check if g:black_skip_string_normalization
is defined and to define it if not, using the inverse of
g:black_string_normalization if that is set, and otherwise to the
default of 0. The Python code in autoload/black.vim runs later, and
will use the value of g:black_skip_string_normalization (and ignore
g:black_string_normalization; it will only be used to set
g:black_skip_string_normalization if it wasn't already set).

---

Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
* Fix plugin/black.vim (need to up my vim game)

Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
Co-authored-by: Matt Wozniski <godlygeek@gmail.com>
2 years agoFind pyproject from vim relative to current file (#1871)
Austin Glaser [Sat, 12 Jun 2021 19:52:49 +0000 (12:52 -0700)]
Find pyproject from vim relative to current file (#1871)

Commit history before merge:

* Find pyproject from vim relative to current file
* Merge remote-tracking branch 'upstream/main' into find-pyproject-vim
* Finish and fix this patch (thanks Matt Wozniski!)

Both the existing code and the proposed code are broken.
The vim.eval() call (whether it's vim.eval("@%") or
vim.eval("fnamemodify(getcwd(), ':t')) returns a string, and it passes
that string to find_pyproject_toml, which expects a sequence of strings,
not a single string, and - since a string is a sequence of single
character strings - it gets turned into a list of ridiculous paths. I
tested with a file called foo.py, and added a print(path_srcs) into
find_project_root, which printed out:

[
  PosixPath('/home/matt/f'),
  PosixPath('/home/matt/o'),
  PosixPath('/home/matt/o'),
  PosixPath('/home/matt'),
  PosixPath('/home/matt/p'),
  PosixPath('/home/matt/y')
]

This does work for an unnamed buffer, too - we wind up calling
black.find_pyproject_toml(("",)), and that winds up prepending the
working directory to any relative paths, so "" just gets turned into
the current working directory.

Note that find_pyproject_toml needs to be passed a 1-tuple, not a
list, because it requires something hashable (thanks to
functools.lru_cache being used)

Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
* I forgot the CHANGELOG entry ... again
* I'm really bad at dealing with merge conflicts sometimes
* Be more correct describing search behaviour

Co-authored-by: Austin Glaser <austin.glaser@spacex.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
2 years agoAdd STDIN test to primer (#2315)
Cooper Lees [Fri, 11 Jun 2021 04:06:50 +0000 (21:06 -0700)]
Add STDIN test to primer (#2315)

* Add STDIN test to primer

- Check that out STDIN black support stays working
- Add asyncio.subprocess STDIN pip via communicate
- We just check we format python code from primer's `lib.py`

Fixes #2310

2 years agoFix incorrect document referance (#2326)
Ryan McPartlan [Fri, 11 Jun 2021 00:45:43 +0000 (20:45 -0400)]
Fix incorrect document referance (#2326)

2 years agoUpdate CHANGES.md for 21.6b0 release (#2325)
Cooper Lees [Thu, 10 Jun 2021 22:25:47 +0000 (15:25 -0700)]
Update CHANGES.md for 21.6b0 release (#2325)

2 years agoAdd coverage files to gitignore (#2323)
jack1142 [Wed, 9 Jun 2021 20:33:59 +0000 (22:33 +0200)]
Add coverage files to gitignore (#2323)

2 years agoDon't run Docker workflow on push to forks (#2324)
jack1142 [Wed, 9 Jun 2021 20:33:53 +0000 (22:33 +0200)]
Don't run Docker workflow on push to forks (#2324)

2 years agoSupport named escapes (`\N{...}`) in string processing (#2319)
jack1142 [Wed, 9 Jun 2021 19:29:32 +0000 (21:29 +0200)]
Support named escapes (`\N{...}`) in string processing (#2319)

Co-authored-by: Felix Hildén <felix.hilden@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoFix flake8 configuration by switching from extend-ignore to ignore (#2320)
jack1142 [Wed, 9 Jun 2021 14:01:07 +0000 (16:01 +0200)]
Fix flake8 configuration by switching from extend-ignore to ignore (#2320)

2 years agoRegression fix: leave R prefixes capitalization alone (#2285)
Richard Si [Wed, 9 Jun 2021 00:46:09 +0000 (20:46 -0400)]
Regression fix: leave R prefixes capitalization alone (#2285)

`black.strings.get_string_prefix` used to lowercase the extracted
prefix before returning it. This is wrong because 1) it ignores the
fact we should leave R prefixes alone because of MagicPython, and 2)
there is dedicated prefix casing handling code that fixes issue 1.
`.lower` is too naive.

This was originally fixed in 20.8b0, but was reintroduced since 21.4b0.

I also added proper prefix normalization for docstrings by using the
`black.strings.normalize_string_prefix` helper.

Some more test strings were added to make sure strings with capitalized
prefixes aren't treated differently (actually happened with my original
patch, Jelle had to point it out to me).

2 years agoMention comment non-processing in documentation (#2306)
Felix Hildén [Tue, 8 Jun 2021 21:57:23 +0000 (00:57 +0300)]
Mention comment non-processing in documentation (#2306)

This commit adds a short section discussing the non-processing of docstrings
besides spacing improvements, mentions comment moving and links to the
AST equivalence discussion. I also added a simple spacing test for good
measure.

Commit history before merge:

* Mention comment non-processing in documentation, add spacing test
* Mention special cases for comment spacing
* Add all special cases, improve wording

2 years agoPossible fix for issue with indentation and fmt: skip (#2281)
Sergey Vartanov [Tue, 8 Jun 2021 21:37:34 +0000 (00:37 +0300)]
Possible fix for issue with indentation and fmt: skip (#2281)

Not sure the fix is right.  Here is what I found: issue is connected
with line

    first.prefix = prefix[comment.consumed :]

in `comments.py`.  `first.prefix` is a prefix of the line, that ends
with `# fmt: skip`, but `comment.consumed` is the length of the
`"  # fmt: skip"` string.  If prefix length is greater than 14,
`first.prefix` will grow every time we apply formatting.

Fixes #2254

2 years ago[primer] Enable everything (#2288)
Cooper Lees [Mon, 7 Jun 2021 15:05:08 +0000 (08:05 -0700)]
[primer] Enable everything (#2288)

See if we pass all our repos with experimental string processing enabled.
Django probably needed:
- Ignores >= 3.8 only

We could support PEP440 version specifiers, but that would introduce the packaging module as a dependency that I'd like to avoid ... Or I could implement a poor persons version or vendor

Commit history before merge:
 * [primer] Enable everything
 * Add exclude extend to django CLI args for primer
 * Change default timeout to from 5 to 10 mins for a primer project
 * Skip string normalization for Django
 * Limit Django to >= 3.8 due to := operator

2 years agoFix incorrect custom breakpoint indices when string group contains fake f-strings...
Bryan Bugyi [Mon, 7 Jun 2021 14:03:39 +0000 (10:03 -0400)]
Fix incorrect custom breakpoint indices when string group contains fake f-strings (#2311)

Fixes #2293

2 years agoAccount for += assignment when deciding whether to split string (#2312)
Bryan Bugyi [Mon, 7 Jun 2021 14:01:57 +0000 (10:01 -0400)]
Account for += assignment when deciding whether to split string (#2312)

Fixes #2294

2 years agoGo back to single core for test suite on CI (#2305)
Richard Si [Fri, 4 Jun 2021 01:26:21 +0000 (21:26 -0400)]
Go back to single core for test suite on CI (#2305)

The random asyncio bug is just too frequent and annoying to be
worth the speed improvements. Our test suite is already quite fast.
Random test failures hurt for 3 reasons, 1) they are discouraging for
new contributors who won't understand it's out of their control, 2)
it's annoying and time consuming to rerun the workflow, and 3) it
makes single job failures feel less important (even they should be
treated as important!).

2 years agoAdd option to require a specific version to be running (#2300)
Felix Hildén [Thu, 3 Jun 2021 20:09:41 +0000 (23:09 +0300)]
Add option to require a specific version to be running (#2300)

Closes #1246: This PR adds a new option (and automatically a toml entry, hooray for existing configuration management 🎉) to require a specific version of Black to be running.

For example: `black --required-version 20.8b -c "format = 'this'"`

Execution fails straight away if it doesn't match `__version__`.

2 years agodon't uvloop.install on import (#2303)
Jelle Zijlstra [Thu, 3 Jun 2021 17:13:55 +0000 (10:13 -0700)]
don't uvloop.install on import (#2303)

2 years agoremove unnecessary docs changelog
Jelle Zijlstra [Wed, 2 Jun 2021 03:01:02 +0000 (20:01 -0700)]
remove unnecessary docs changelog

2 years agoMove `--code` #2259 change log to correct unlreased section of CHANGES.md
Cooper Ry Lees [Wed, 2 Jun 2021 02:45:03 +0000 (19:45 -0700)]
Move `--code` #2259 change log to correct unlreased section of CHANGES.md

2 years agoCode Flag Options (#2259)
Hassan Abouelela [Wed, 2 Jun 2021 01:55:21 +0000 (04:55 +0300)]
Code Flag Options (#2259)

Properly handles the diff, color, and fast option when black is run with
 the `--code` option.

Closes #2104, closes #1801.

2 years agoBump urllib3 from 1.26.4 to 1.26.5 (#2298)
dependabot[bot] [Tue, 1 Jun 2021 22:08:17 +0000 (15:08 -0700)]
Bump urllib3 from 1.26.4 to 1.26.5 (#2298)

Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.4 to 1.26.5.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.26.4...1.26.5)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2 years agoAdd `version` to github action (and rewrite the whole thing while at it) (#1940)
Stefan Foulis [Tue, 1 Jun 2021 01:45:50 +0000 (03:45 +0200)]
Add `version` to github action (and rewrite the whole thing while at it) (#1940)

Commit history before merge:

* Add black_version to github action
* Merge upstream/main into this branch
* Add version support for the Black action pt.2

  Since we're moving to a composite based action, quite a few changes
  were made. 1) Support was added for all OSes (Windows was painful).
  2) Isolation from the rest of the workflow had to be done manually
  with a virtual environment.

  Other noteworthy changes:

  - Rewrote basically all of the logic and put it in a Python script
    for easy testing (not doing it here tho cause I'm lazy and I can't
    think of a reasonable way of testing it).
  - Renamed `black_version` to `version` to better fit the existing
    input naming scheme.
  - Added support for log groups, this makes our action's output a
    bit more fancy (I may or may have not added some debug output too).

* Add more to and sorta rewrite the Action's docs

  Reflect compatability and gotchas.

* Add CHANGELOG entry
* Merge main into this branch
* Remove debug; address typos; clean up action.yml

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoCorrect max string length calculation when there are string operators (#2292)
Bryan Bugyi [Tue, 1 Jun 2021 00:57:23 +0000 (20:57 -0400)]
Correct max string length calculation when there are string operators (#2292)

PR #2286 did not fix the edge-cases (e.g. when the string is just long
enough to cause a line to be 89 characters long). This PR corrects that
mistake.

2 years agoUpdate CHANGES.md for 21.5b2 release (#2290)
Cooper Lees [Mon, 31 May 2021 14:25:54 +0000 (07:25 -0700)]
Update CHANGES.md for 21.5b2 release (#2290)

* Update CHANGES.md for 21.5b2 release

2 years agoFix regular expression that black uses to identify f-expressions (#2287)
Bryan Bugyi [Sun, 30 May 2021 22:34:33 +0000 (18:34 -0400)]
Fix regular expression that black uses to identify f-expressions (#2287)

Fixes #1469

2 years agoMake sure to split lines that start with a string operator (#2286)
Bryan Bugyi [Sun, 30 May 2021 21:41:03 +0000 (17:41 -0400)]
Make sure to split lines that start with a string operator (#2286)

Fixes #2284

2 years agoFix --experiemental-string-processing crash when matching parens not found (#2283)
Bryan Bugyi [Sun, 30 May 2021 19:32:28 +0000 (15:32 -0400)]
Fix --experiemental-string-processing crash when matching parens not found (#2283)

Fixes #2271

2 years agoadd discussion of magic comments to FAQ (#2272)
Jelle Zijlstra [Sat, 29 May 2021 17:16:33 +0000 (10:16 -0700)]
add discussion of magic comments to FAQ (#2272)

Co-authored-by: Cooper Lees <me@cooperlees.com>
2 years agoptr nolong requires changes (#2276)
Cooper Lees [Sat, 29 May 2021 17:15:22 +0000 (10:15 -0700)]
ptr nolong requires changes (#2276)

- I worked on this project yesterday and must have fixed the formatting

2 years agoAdd @zzzeek testimonial to README and docs
Łukasz Langa [Sat, 29 May 2021 16:04:45 +0000 (18:04 +0200)]
Add @zzzeek testimonial to README and docs

2 years agoFix path_empty() (#2275)
Jelle Zijlstra [Sat, 29 May 2021 16:03:08 +0000 (09:03 -0700)]
Fix path_empty() (#2275)

Behavior other than output shouldn't depend on the verbose/quiet option. As far as I can tell this currently has no visible effect, since code after this function is called handles an empty list gracefully.

2 years agoAdd --experimental-string-processing to future changes (#2273)
Jelle Zijlstra [Sat, 29 May 2021 14:27:54 +0000 (07:27 -0700)]
Add --experimental-string-processing to future changes (#2273)

* add esp to future style

* changelog

* fix label

2 years agoIssue templates: use HTML comments (#2269)
Matteo Bertucci [Sat, 29 May 2021 13:56:46 +0000 (15:56 +0200)]
Issue templates: use HTML comments (#2269)

This commit makes use of HTML comments inside GitHub issue templates
to make sure that even if they aren't removed by the issue author they won't be shown
in the rendered output.

The goal is to simply make the issues less noisy by removing template messages.

2 years agoUse latest Python in uploading binaries (#2260)
Felix Hildén [Thu, 27 May 2021 13:58:06 +0000 (16:58 +0300)]
Use latest Python in uploading binaries (#2260)

* Use latest Python in uploading binaries

* Don't pin version at all

* Add changelog entry

2 years agoFix and test docs on Windows (#2262)
Richard Si [Thu, 27 May 2021 02:04:10 +0000 (22:04 -0400)]
Fix and test docs on Windows (#2262)

There's some weird interaction between Click and
sphinxcontrib-programoutput on Windows that leads to an encoding error
during the printing of black-primer's help text.

Also symlinks aren't well supported on Windows so let's just use
includes which actually work because we now use MyST :D

2 years agoAdd optional uvloop import (#2258)
Cooper Lees [Wed, 26 May 2021 12:52:09 +0000 (05:52 -0700)]
Add optional uvloop import (#2258)

* Add optional uvloop import

- If we find `uvloop` in the env for black, blackd or black-primer lets try and use it
- Add a uvloop extra install

Fixes #2257

Test:
- Add ci job to install black[uvloop] and run a primer run with uvloop
  - Only with latest python (3.9)
  - Will be handy to compare runtimes as a very unoffical benchmark

* Remove tox install

* Add to CHANGES/news

2 years agoRemoved adding a space into empty docstrings. (#2249)
Mark Bell [Tue, 25 May 2021 22:43:28 +0000 (23:43 +0100)]
Removed adding a space into empty docstrings. (#2249)

Resolves #2168 by disabling the insertion of a " " when the docstring is entirely empty.

Note that this PR is focussed only on the case of empty docstrings. In particular this does not make any changes to the behaviour that a " " is inserted if a non-empty docstring begins with the quoting character. That is, black still prefers:

    """ "something" """

to:

    """"something" """

and that:

    """"Something""""

is not a legal docstring.

2 years agoCreate FAQ documentation (GH-2247)
Felix Hildén [Tue, 25 May 2021 20:07:05 +0000 (23:07 +0300)]
Create FAQ documentation (GH-2247)

This commit creates a Frequently Asked Questions document for our users
to read. Hopefully they actually read it too. Items included are:
Black's non-API, AST safety, style stability, file discovery, Flake8
disagreements and Python 2 support. Hopefully I've got the answers
down in general.

Commit history before merge:

* Create FAQ
* Address feedback
* Move to single markdown file
* Minor wording improvements
* Add changelog entry

2 years agoSolved Problem with Non-ASCII .gitignore Files (#2229)
temeddix [Mon, 24 May 2021 02:19:03 +0000 (11:19 +0900)]
Solved Problem with Non-ASCII .gitignore Files (#2229)

* Solved Problem with non-alphabetical .gitignore files

When .gitignore file in the user's project directory contained non-alphabetical
characters(Japanese, Korean, Chinese, etc), Nothing works and printed this
weird message in the console('cp949' is the encoding for Korean characters
in this case). It even blocks VSCode's formatting from working. This commit
solves the problem.

Traceback (most recent call last):
  File "c:\users\username\anaconda3\envs\project-name\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\username\anaconda3\envs\project-name\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\username\anaconda3\envs\project-name\Scripts\black.exe\__main__.py", line 7, in <module>
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 1056, in patched_main
    main()
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 394, in main
    stdin_filename=stdin_filename,
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\__init__.py", line 445, in get_sources
    gitignore = get_gitignore(root)
  File "c:\users\username\anaconda3\envs\project-name\lib\site-packages\black\files.py", line 122, in get_gitignore
    lines = gf.readlines()
UnicodeDecodeError: 'cp949' codec can't decode byte 0xb0 in position 13: illegal multibyte sequence

* Made .gitignore File Reader Detect Its Encoding
* Revert "Made .gitignore File Reader Detect Its Encoding"

  This reverts commit 6c3a7ea42b5b1e441cc0026c8205d1cee68c1bba.

* Revert "Solved Problem with non-alphabetical .gitignore files"

  This reverts commit b0100b5d91c2f5db544a60f34aafab120f0aa458.

* Made .gitignore Reader Open the File with Auto Encoding Detecting

  https://docs.python.org/3.8/library/tokenize.html#tokenize.open

* Revert "Made .gitignore Reader Open the File with Auto Encoding Detecting"

  This reverts commit 50dd80422938649ccc8c7f43aac752f9f6481779.

* Made .gitignore Reader Use UTF-8
* Updated CHANGES.md for #2229
* Updated CHANGES.md for #2229
* Update CHANGES.md
* Update CHANGES.md

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoBuild macOS releases (#2198)
Salomon Popp [Mon, 24 May 2021 01:59:03 +0000 (03:59 +0200)]
Build macOS releases (#2198)

* Add macOS release target
* Update ubuntu runner

Ubuntu 16.04 runner environment is deprecated
https://github.blog/changelog/2021-04-29-github-actions-ubuntu-16-04-lts-virtual-environment-will-be-removed-on-september-20-2021/

2 years agoLink isort profile to Black code style isort mention (#2246)
Felix Hildén [Wed, 19 May 2021 19:11:37 +0000 (22:11 +0300)]
Link isort profile to Black code style isort mention (#2246)

The isort configuration currently in the Black code style document is
duplicated in Using Black with other tools document. I think it would
be better to consolidate information and simply link to the tool guide,
mentioning the easy profile in the original document.

I changed the link from isort PyPI page to Black's docs on isort
because for users it could be better to see the Black docs on why that
configuration is necessary and what isort is from Black's perspective.

2 years agoFix test requirements file name (#2245)
Felix Hildén [Mon, 17 May 2021 18:47:34 +0000 (21:47 +0300)]
Fix test requirements file name (#2245)

2 years agoMake Prettier preserve line ending type (#2244)
Felix Hildén [Mon, 17 May 2021 18:38:43 +0000 (21:38 +0300)]
Make Prettier preserve line ending type (#2244)

Why? The default in Prettier 2.0 was
[changed](https://prettier.io/docs/en/options.html#end-of-line) from
`auto` to `LF`. This makes development on Windows awkward, because
every file is marked with changes both by Prettier and then by Git
regardless of repository line ending settings, making committing harder
than it should be.

---

Aside from that: I noticed that runnin pre-commit manually seems to add
line endings to symlink files, but they disappear when actually committing.
Don't know if that's a known.. quirk..(?) or not.

---

Commit history before merge:

* Make Prettier preserve line ending type
* Move options to .prettierrc

2 years agoFix: black only respects the root gitignore. (#2225)
Hadi Alqattan [Sun, 16 May 2021 17:51:27 +0000 (20:51 +0300)]
Fix: black only respects the root gitignore. (#2225)

Commit history before merge:

Black now respects .gitignore files in all levels, not only root/.gitignore file
(apply .gitignore rules like git does).

* Fix: typo
* Fix: respect .gitignore files in all levels.
* Add: CHANGELOG note.
* Fix: TypeError: unsupported operand type(s) for +: 'NoneType' and 'PathSpec'
* Update docs.
* Fix: no parent .gitignore
* Add a comment since the if expression is a bit hard to understand
* Update tests - conver no parent .gitignore case.
* Use main's Pipfile.lock instead

  The original changes in Pipfile.lock are whitespace only. The changes
  turned the JSON's file indentation from 4 to 2. Effectively this
  happened: `json.dumps(json.loads(old_pipfile_lock), indent=2) + "\n"`.

  Just using main's Pipfile.lock instead of undoing the changes because
  1) I don't know how to do that easily and quickly, and 2) there's a
  merge conflict.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
* Merge remote-tracking branch 'upstream/main' into i1730 …

  conflicts for days ay?

2 years agoInclude Jelle's review suggestions
Łukasz Langa [Sun, 16 May 2021 16:24:28 +0000 (18:24 +0200)]
Include Jelle's review suggestions

2 years agoUpdate vim plugin manual installation instructions. (#2235)
Matthew Clapp [Sun, 16 May 2021 16:10:59 +0000 (09:10 -0700)]
Update vim plugin manual installation instructions. (#2235)

2 years agoAdd issue triage documentation (#2236)
Richard Si [Sun, 16 May 2021 16:07:27 +0000 (12:07 -0400)]
Add issue triage documentation (#2236)

* Add issue triage documentation

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoAdd lower bound for aiohttp-cors + fix primer (#2231)
Richard Si [Thu, 13 May 2021 19:30:34 +0000 (15:30 -0400)]
Add lower bound for aiohttp-cors + fix primer (#2231)

It appears sqlalchemy has recently reformatted their project with
Black 21.5b1.

Most of our dependencies have a lower bound and creating a test
environment with the oldest acceptable dependencies runs the full
Black test suite just fine. The only exception to this is aiohttp-cors.
It's unbounded and the oldest version 0.1.0 until 0.4.0 breaks the
test suite in such an old environment.

Failure with 0.1.0:

```
tests/test_blackd.py:10: in <module>
    import blackd
testenv/lib/python3.8/site-packages/blackd/__init__.py:12: in <module>
    import aiohttp_cors
testenv/lib/python3.8/site-packages/aiohttp_cors/__init__.py:29: in <module>
    from .urldispatcher_router_adapter import UrlDistatcherRouterAdapter
testenv/lib/python3.8/site-packages/aiohttp_cors/urldispatcher_router_adapter.py:27: in <module>
    class UrlDistatcherRouterAdapter(RouterAdapter):
testenv/lib/python3.8/site-packages/aiohttp_cors/urldispatcher_router_adapter.py:32: in UrlDistatcherRouterAdapter
    def route_methods(self, route: web.Route):
E   AttributeError: module 'aiohttp.web' has no attribute 'Route'
```

For 0.2.0:

```
tests/test_blackd.py:10: in <module>
    import blackd
testenv/lib/python3.8/site-packages/blackd/__init__.py:12: in <module>
    import aiohttp_cors
testenv/lib/python3.8/site-packages/aiohttp_cors/__init__.py:27: in <module>
    from .cors_config import CorsConfig
testenv/lib/python3.8/site-packages/aiohttp_cors/cors_config.py:24: in <module>
    from .urldispatcher_router_adapter import UrlDistatcherRouterAdapter
testenv/lib/python3.8/site-packages/aiohttp_cors/urldispatcher_router_adapter.py:27: in <module>
    class UrlDistatcherRouterAdapter(AbstractRouterAdapter):
testenv/lib/python3.8/site-packages/aiohttp_cors/urldispatcher_router_adapter.py:32: in UrlDistatcherRouterAdapter
    def route_methods(self, route: web.Route):
E   AttributeError: module 'aiohttp.web' has no attribute 'Route'
```

For 0.3.0:

```
ERROR: Cannot install aiohttp-cors==0.3.0 and aiohttp==3.6.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested aiohttp==3.6.0
    aiohttp-cors 0.3.0 depends on aiohttp<=0.20.2 and >=0.18.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
```

2 years agoUse codespell to find typos (#2228)
Christian Clauss [Thu, 13 May 2021 17:28:41 +0000 (19:28 +0200)]
Use codespell to find typos (#2228)

2 years agoModify when Test, Primer, and Documentation Build run (#2226)
Richard Si [Thu, 13 May 2021 01:28:41 +0000 (21:28 -0400)]
Modify when Test, Primer, and Documentation Build run (#2226)

- Test and Primer don't run for documentation only changes since it's
  unnecessary, eating unnecessary cycles and slowing down CI since these
  workflows eat up the 20 max workers limit quite easily!

- Documentation Build runs all of the time now since quite a bit of the
  content depends on Black's code so even a simple 1-file change in
  src/black/__init__.py may break the docs build. It's not like this is
  a costly workflow anyway.

Fuzz is still running on all changes because with fuzzing, the more the
better in general. 6 or 7 jobs on a documentation only commit is much
better than 27/28 jobs anyway :p

I also found an error in our bug report issue template :)

2 years agoClick 8.0 renamed its "die on LANG=C" function so we need to look for that one too...
Łukasz Langa [Wed, 12 May 2021 19:47:32 +0000 (21:47 +0200)]
Click 8.0 renamed its "die on LANG=C" function so we need to look for that one too (#2227)

2 years agoRemove useless flake8 config + test support code (#2221)
Richard Si [Tue, 11 May 2021 18:09:33 +0000 (14:09 -0400)]
Remove useless flake8 config + test support code (#2221)

We've depended on Click 7.x ever since we broke CI systems across the
world (oops lol) and flake8-mypy was purged a fair bit back: #1867

Also remove the primer tests import in tests/test_black.py because it's
annoying when just trying to actually target tests/test_black.py tests.
`pytest -k test_black.py` doesn't do what you expect due to that import.

2 years agoAdd stable tag process to release process documentation (#2224)
Cooper Lees [Tue, 11 May 2021 17:01:03 +0000 (10:01 -0700)]
Add stable tag process to release process documentation (#2224)

* Add stable tag process to release process documentation
- Add reasoning + step commands

* Bah - I ran the linter but forgot to commit

* Update docs/contributing/release_process.md

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agofix typo (#2217)
Jelle Zijlstra [Mon, 10 May 2021 15:01:53 +0000 (08:01 -0700)]
fix typo (#2217)

2 years agoUpdate CHANGES.md for 21.5b1 release (#2215)
Cooper Lees [Mon, 10 May 2021 14:59:32 +0000 (07:59 -0700)]
Update CHANGES.md for 21.5b1 release (#2215)

2 years agoRelease process docs (#2214)
Cooper Lees [Mon, 10 May 2021 14:58:36 +0000 (07:58 -0700)]
Release process docs (#2214)

* Setup groundwork for release process docs

I'm using MyST for the index page since I like it more and it's easier
to work with.

* Fill in Release Process for black

* Apply suggestions from code review

Apply Jelle's grammar + typo fixes. I am a terrible only English speaker.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
* Update release_process.md

Make lint happy via web UI.

* Move to contribution section and fix prettier

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoCover more in the usage docs (#2208)
Richard Si [Mon, 10 May 2021 14:57:22 +0000 (10:57 -0400)]
Cover more in the usage docs (#2208)

Commit history before merge:

* Cover more in the usage docs
* Minor fixes
* Even more corrections by Jelle
* Update docs/usage_and_configuration/the_basics.md

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoAutogenerate black(d|-primer)? help in usage docs (#2212)
Richard Si [Mon, 10 May 2021 02:35:56 +0000 (22:35 -0400)]
Autogenerate black(d|-primer)? help in usage docs (#2212)

So these won't go out of date. This does mean the environment has be
setup a bit more carefully so the right version of the tool is used,
but thankfully the build environment is rebuilt on change on RTD anyway.

Also since the HTML docs are known to build fine, let's provide
downloadable HTMLzips of our docs.

This change needs RTD and GH to install Black with the [d] extra so
blackd's help can generated. While editing RTD's config file, let's
migrate the file to a non-deprecated filename.

Also I missed adding AUTHORS.md to the files key in the doc GHA config.

2 years agoReplace references to master branch (#2210)
Panagiotis Vasilopoulos [Sun, 9 May 2021 21:50:17 +0000 (21:50 +0000)]
Replace references to master branch (#2210)

Commit history before merge:

* Replace references to master branch
* Update .flake8 to reference docs on RTD

  We're moving away from GitHub as a documentation host to only RTD because
  it's makes our lives easier creating good docs. I know this link is dead right now,
  but it won't be once we release a new version with the documentation reorganization
  changes (which should be soon!).

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoRemove docker CI from look at 'master' branch (#2209)
Cooper Lees [Sun, 9 May 2021 07:08:03 +0000 (00:08 -0700)]
Remove docker CI from look at 'master' branch (#2209)

2 years agoFix autodoc refs broken by refactor (#2207)
Richard Si [Sat, 8 May 2021 19:53:01 +0000 (15:53 -0400)]
Fix autodoc refs broken by refactor (#2207)

2 years agoReorganize docs v2 (GH-2174)
Richard Si [Sat, 8 May 2021 19:17:38 +0000 (15:17 -0400)]
Reorganize docs v2 (GH-2174)

I know I know, this is the second reorganization of the docs. I'm not
saying the first one was bad or anything... but.. actually wait nah,
*it was bad*.

Anyway, welcome to probably my biggest commit. The main thing with this
reorganization was to introduce nesting to the documentation! Having
all of the docs be part of the main TOC was becoming too much. There
wasn't much room to expand either. Finally, the old setup required
a documentation generation step which was just annoying.

The goals of this reorganization was to:

1. Significantly restructure the docs to be discoverable and
   understandable

2. Add room for further docs (like guides or contributing docs)

3. Get rid of the doc generation step (it was slow and frustrating)

4. Unblock other improvements and also just make contributing to the
   docs easier

Another important change with this is that we are no longer using GitHub
as a documentation host. While GitHub does support Markdown based docs
actually pretty well, the lack of any features outside of GitHub Flavoured
Markdown is quite limiting. ReadTheDocs is just much better suited for
documentation. You can use reST, MyST, CommonMark, and all of their
great features like toctrees and admonitions.

Related to this change, we're adopting MyST as our flavour of Markdown.
MyST introduces neat syntax extensions to Markdown that pretty much
gives us the best of both worlds. The ease of use and simplicity of MD
and the flexibility and expressiveness of reST. Also recommonmark is
deprecated now. This switch was possible now we don't use GH as a docs
host. MyST docs have to be built to really be usable / pretty, so the MD
docs are going to look pretty bad on GH, but that's fine now!

Another thing that should be noted is that the README has been stripped
of most content since it was confusing. Users would read the README and
then think some feature or bug was fixed already and is available in a
release when in reality, they weren't. They were reading effectively
the latest docs without knowing.

See also: https://github.com/psf/black/issues/1759

FYI: CommonMark is a rationalized version of Markdown syntax

--

Commit history before merge:

* Switch to MyST-Parser + doc config cleanup

  recommonmark is being deprecated in favour of MyST-Parser. This change
  is welcomed, especially since MyST-Parser has syntax extensions for the
  Commonmark standard. Effectively we get to use a language that's powerful
  and expressive like ReST, but get the simplicity of Markdown.

  The rest of this effort will be using some MyST features.

  This reorganization efforts aims to remove as much duplication as possible.
  The regeneration step once needed is gone, significantly simplifing our
  Sphinx documentation configuration.

* Tell pipenv we replaced recommonmark for MyST-Parser

  Also update `docs/requirements.txt`

* Delete all auto generated content
* Switch prettier for mdformat (plus a few plugins)

  **FYI: THIS WAS EFFECTIVELY REVERTED, SEE THIRD TO LAST COMMIT**

  prettier doesn't support MyST's syntax extensions which are going to be
  used in this reorganization effort so we have to switch formatter.

  Unfortanately mdformat's style is different from prettier's so time to
  reformat the whole repo too.

  We're excluding .github/ISSUE_TEMPLATE because I have no idea whether
  its changes are safe, so let's play it safe.

* Fix the heading levels in CHANGES.md + a link

  MyST-Parser / sphinx's linkcheck complains otherwise.

* Move reference docs into a docs/contributing dir

  They're for contributors of Black anyway. Also added a note in the
  summary document warning about the lack of attention the reference has
  been dealing with.

* Rewrite and setup the new landing page + main TOC

  - add some more detail about Black's beta status
  - add licensing info
  - add external links in the main TOC for GitHub, PyPI, and IRC
  - prepare main TOC for new structure

* Break out AUTHORS into its own file

  Not only was the AUTHORS list quite long, this makes it easy to include
  it in the Sphinx docs with just a simple symlink.

* Add license to docs via a simple include

  Yes the document is orphaned but it is linked to in the landing page
  (docs/index.rst).

* Add "The Black Code Style" section

  This mostly was a restructuring commit, there has been a few updates but
  not many. The main goal was to split "current style" and "planned
  changes to the style that haven't happened yet" to avoid confusion.

* Add "Getting Started" page

  This is basically a quick start + even more. This commit is certainly
  one of most creatively involved in this effort.

* Add "Usage and Configuration" section

  This commit was as much restructuring as new content. Instead of being
  in one giant file, usage and configuration documentation can expand
  without bloating a single file.

* Add "Integrations" section

Just a restructuring commit ...

* Add "Guides" section

  This is a promising area of documentation that could easily grow in the
  future, let's prepare for that!

* Add "Contributing" section

  This is also another area that I expect to see significant growth in.
  Contributors to Black could definitely do with some more specific docs
  that clears up certain parts of our slightly confusing project (it's
  only confusing because we're getting big and old!).

* Rewrite CONTRIBUTING.md to just point to RTD
* Rewrite README.md to delegate most info to RTD
* Address feedback + a lot of corrections and edits

  I know I said I wanted to do these after landing this but given there's
  going to be no time between this being merged and a release getting
  pushed, I want these changes to make it in.

  - drop the number flag for mdformat - to reduce diffs, see also:
    https://mdformat.readthedocs.io/en/stable/users/style.html#ordered-lists
  - the GH issue templates should be safe by mdformat, so get rid of the
    exclude
  - clarify our configuration position - i.e. stop claiming we don't have
    many options, instead say we want as little formatting knobs as
    possible
  - lots and lots of punctuation, spelling, and grammar corrections (thanks
    Jelle!)
  - use RTD as the source for the CHANGELOG too
  - visual style cleanups
  - add docs about our .gitignore behaviour
  - expand GHA Action docs
  - clarify we want the PR number in the CHANGELOG entry
  - claify Black's behaviour for with statements post Python 3.9
  - italicize a bunch of "Black"s

  Thank you goes to Jelle, Taneli (hukkinj1 on GH), Felix
  (felix-hilden on GH), and Wouter (wbolster on GH) for the feedback!

* Merge remote-tracking branch 'upstream/master' into reorganize-docs-v2

  merge conflicts suck, although these ones weren't too bad.

* Add changelog entry + fix merge conflict resolution error

  I consider this important enough to be worthy of a changelog entry :)

* Merge branch 'master' into reorganize-docs-v2

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* Actually let's continue using prettier

  Prettier works fine for all of the default MyST syntax so let's not
  rock the boat as much. Dropping the mdformat commit was merge-conflict
  filled so here's additional commit instead.

* Address Cooper's, Taneli's, and Jelle's feedback

  Lots of wording improvements by Cooper. Taneli suggested to disable the
  enabled by default MyST syntax not supported by Prettier and I agreed.
  And Jelle found one more spelling error!

* More minor fixes

2 years agoSpeed up tests even more (#2205)
Richard Si [Sat, 8 May 2021 09:34:25 +0000 (05:34 -0400)]
Speed up tests even more (#2205)

There's three optimizations in this commit:

1. Don't check if Black's output is stable or equivalant if no changes
   were made in the first place. It's not like passing the same code
   (for both source and actual) through black.assert_equivalent or
   black.assert_stable is useful. It's not a big deal for the smaller
   tests, but it eats a lot of time in tests/test_format.py since
   its test cases are big. This is also closer to how Black works IRL.

2. Use a smaller file for `test_root_logger_not_used_directly` since
   the logging it's checking happens during blib2to3's startup so the
   file doesn't really matter.

3. If we're checking a file is formatting (i.e. test_source_is_formatted)
   don't run Black over it again with `black.format_file_in_place`.
   `tests/test_format.py::TestSimpleFormat.check_file` is good enough.

2 years agoRefactor `src/black/__init__.py` into many files (#2206)
Łukasz Langa [Sat, 8 May 2021 09:29:47 +0000 (11:29 +0200)]
Refactor `src/black/__init__.py` into many files (#2206)

* Move string-related utility to functions to strings.py, const.py
* Move Leaf/Node-related functionality to nodes.py
* Move comment-related functions to comments.py
* Move caching to cache.py and Mode/TargetVersion/Feature to mode.py
* Move some leftover functions to nodes.py, comments.py, strings.py
* Add missing files to source list for test runs
* Move line-related functionality into lines.py, brackets into brackets.py
* Move transformers to trans.py
* Move file handling, output, parsing, concurrency, debug, and report
* Move two more functions to nodes.py
* Add CHANGES
* Add numeric.py
* Add linegen.py
* More docstrings
* Include new files in tests

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2 years agoSpeed up test suite via distributed testing (#2196)
Richard Si [Fri, 7 May 2021 14:41:55 +0000 (10:41 -0400)]
Speed up test suite via distributed testing (#2196)

* Speed up test suite via distributed testing

Since we now run the test suite twice, one with Python 2 and another
without, full test runs are getting pretty slow. Let's try to
fix that with parallization.

Also use verbose mode on CI since more logs is usually better since
getting more is quite literally impossible.

The main issue we'll face with this is we'll hit
https://github.com/pytest-dev/pytest-xdist/issues/620 sometimes
(although pretty rarely). I suppose we can test this and see if how bad
this bug is for us, and revert if necessary down the line.

Also let's have some colours :tada:

2 years agoMark blackd tests with the `blackd` optional marker (#2204)
Łukasz Langa [Fri, 7 May 2021 14:33:36 +0000 (16:33 +0200)]
Mark blackd tests with the `blackd` optional marker (#2204)

This is a follow-up of #2203 that uses a pytest marker instead of a bunch of
`skipUnless`.  Similarly to the Python 2 tests, they are running by default and
will crash on an unsuspecting contributor with missing dependencies.  This is
by design, we WANT contributors to test everything.  Unless we actually don't
and then we can run:

  pytest --run-optional=no_blackd

Relatedly, bump required aiohttp to 3.6.0 at least to get rid of expected
failures on Python 3.8 (see 6b5eb7d4651c7333cc3f5df4bf7aa7a1f1ffb45b).

2 years agoUse optional tests for "no_python2" to simplify local testing (#2203)
Łukasz Langa [Fri, 7 May 2021 13:03:13 +0000 (15:03 +0200)]
Use optional tests for "no_python2" to simplify local testing (#2203)

2 years agoDo not use gitignore if explicitly passing excludes (#2170)
Kaleb Barrett [Fri, 7 May 2021 12:54:21 +0000 (07:54 -0500)]
Do not use gitignore if explicitly passing excludes (#2170)

Closes #2164.

Changes behavior of how .gitignore is handled. With this change, the rules in .gitignore are only used as a fallback if no exclusion rule is explicitly passed on the command line or in pyproject.toml. Previously they were used regardless if explicit exclusion rules were specified, preventing any overriding of .gitignore rules.

Those that depend only on .gitignore for their exclusion rules will not be affected. Those that use both .gitignore and exclude will find that exclude will act more like actually specifying exclude and not just another extra-excludes. If the previous behavior was desired, they should move their rules from exclude to extra-excludes.

2 years agoFix broken Action entrypoint (#2202)
Richard Si [Thu, 6 May 2021 19:21:13 +0000 (15:21 -0400)]
Fix broken Action entrypoint (#2202)

2 years agoSimplify GitHub Action entrypoint (#2119)
Shota Ray Imaki [Thu, 6 May 2021 02:25:43 +0000 (11:25 +0900)]
Simplify GitHub Action entrypoint (#2119)

This commit simplifies entrypoint.sh for GitHub Actions by removing
duplication of args and black_args (cf. #1909).

The reason why #1909 uses the input id black_args is to avoid an overlap
with args, but this naming seems redundant. So let me suggest option
and src, which are consistent with CLI. Backward compatibility is
guaranteed; Users can still use black_args as well.

Commit history pre-merge:
* Simplify GitHub Action entrypoint (#1909)
* Fix prettier
* Emit a warning message when `black_args` is used

  This deprecation should be visible in GitHub Action's UI now.

Co-authored-by: Shota Ray Imaki <shota.imaki.0801@gmail.com>
Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoEnable ` --experimental-string-processing` on most primer projects (#2184)
Cooper Lees [Wed, 5 May 2021 15:33:23 +0000 (08:33 -0700)]
Enable ` --experimental-string-processing` on most primer projects (#2184)

* Enable ` --experimental-string-processing` on all primer projects
- We want to make this default so need to test it more
- Fixed splat/star bug in extending black args for each project

* Disable sqlalchemy due to crash

2 years agoDisable pandas while we look into #2193 (#2195)
Cooper Lees [Tue, 4 May 2021 19:49:20 +0000 (12:49 -0700)]
Disable pandas while we look into #2193 (#2195)

2 years agoUpdate CHANGES.md for 21.5b0 release (#2192)
Cooper Lees [Tue, 4 May 2021 18:07:08 +0000 (11:07 -0700)]
Update CHANGES.md for 21.5b0 release (#2192)

* Update CHANGES.md for 21.5b0 release

* Make prettier happy

2 years agoUse pre-commit/action to simplify CI (#2191)
Hugo van Kemenade [Tue, 4 May 2021 11:41:04 +0000 (14:41 +0300)]
Use pre-commit/action to simplify CI (#2191)

2 years agocompatible isort config: mention profile first (#2180)
reka [Tue, 4 May 2021 08:48:59 +0000 (10:48 +0200)]
compatible isort config: mention profile first (#2180)

Change the order of possible ways to configure isort:
1. using the profile black
2. custom configuration

Formats section:
change the examples to use the profile black

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2 years agoDrop Travis CI and migrate Coveralls (#2186)
Richard Si [Tue, 4 May 2021 08:47:59 +0000 (04:47 -0400)]
Drop Travis CI and migrate Coveralls (#2186)

Travis CI for Open Source is shutting down in a few weeks so the queue
for jobs is insane due to lower resources. I'm 99.99% sure we don't need
it as our Test, Lint, Docs, Upload / Package, Primer, and Fuzz workflows
are all on GitHub Actions. So even though we *can* migrate to the .com
version with its 1000 free Linux minutes(?), I don't think we need to.

more information here:
- https://blog.travis-ci.com/oss-announcement
- https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing
- https://docs.travis-ci.com/user/migrate/open-source-repository-migration

This commit does the following:
- delete the Travis CI configuration
- add to the GHA test workflows so coverage continues to be recorded
  - tweaked coverage configuration so this wouldn't break
- remove any references to Travis CI in the docs (i.e. readme + sphinx
  docs)

Regarding the Travis CI to GitHub Actions Coveralls transition, the
official action doesn't support the coverage files produced by coverage.py
unfornately. Also no, I don't really know what I am doing so don't @ me
if this breaks :p (well you can, but don't expect me to be THAT useful).

The Coveralls setup has two downfalls AFAIK:
- Only Linux runs are used because AndreMiras/coveralls-python-action
  only supports Linux. Although this isn't a big issue since the Travis
  Coveralls configuration only used Linux data too.
- Pull requests from an internal branch (i.e. one on psf/black) will be
  marked as a push coverage build by Coveralls since our anti-duplicate-
  workflows system runs under the push even for such cases.

2 years agoadd test configurations that don't contain python2 optional install (#2190)
KotlinIsland [Tue, 4 May 2021 08:47:22 +0000 (18:47 +1000)]
add test configurations that don't contain python2 optional install (#2190)

add test for negative scenario: formatting python2 code
tag python2 only tests

Co-authored-by: KotlinIsland <kotlinisland@users.noreply.github.com>
2 years agoDetect `'@' dotted_name '(' ')' NEWLINE` as a simple decorator (#2182)
Richard Si [Tue, 4 May 2021 08:46:46 +0000 (04:46 -0400)]
Detect `'@' dotted_name '(' ')' NEWLINE` as a simple decorator (#2182)

Previously the RELAXED_DECORATOR detection would be falsely True on that
example. The problem was that an argument-less parentheses pair didn't
pass the `is_simple_decorator_trailer` check even it should. OTOH a
parentheses pair containing an argument or more passed as expected.

2 years agoprimer: Add `--no-diff` option (#2187)
Cooper Lees [Tue, 4 May 2021 08:44:40 +0000 (01:44 -0700)]
primer: Add `--no-diff` option (#2187)

- Allow runs with no code diff output
- This is handy for reducing output to see which file is erroring

Test:
- Edit config for 'channels' to expect no changes and run with `--no-diff` and see no diff output

2 years agoprimer: Renable pandas (#2185)
Cooper Lees [Mon, 3 May 2021 21:58:17 +0000 (14:58 -0700)]
primer: Renable pandas (#2185)

- It no longer crashes black so we should test on it's code
- Update django reason to name the file causing error
  - Seems it has a syntax error on purpose

2 years agoSet `is_pyi` if `stdin_filename` ends with `.pyi` (#2169)
Bryan Forbes [Sun, 2 May 2021 12:48:54 +0000 (07:48 -0500)]
Set `is_pyi` if `stdin_filename` ends with `.pyi` (#2169)

Fixes #2167

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>