Commit Graph

111 Commits

Author SHA1 Message Date
Richard Si
48dfda084a
Push contributors to use Next PR Number (#2080)
This is a tool of my own making. Right now our requirement to have the
PR number in the changelog entry is pretty painful / annoying since
the contributor either has to guess or add the # retroactively after
the PR creation. This tool should make it way less painful by making
it simple to get your PR number beforehand.
2021-04-01 14:24:18 -07:00
Harish Rajagopal
9451c57d1c
Support for top-level user configuration (#1899)
* Added support for top-level user configuration

At the user level, a TOML config can be specified in the following locations:
* Windows: ~\.black
* Unix-like: $XDG_CONFIG_HOME/black (~/.config/black fallback)

Instead of changing env vars for the entire black-primer process, they
are now changed only for the black subprocess, using a tmpdir.
2021-04-01 18:39:18 +02:00
dependabot[bot]
c702588daa
Bump pygments from 2.6.1 to 2.7.4 in /docs (#2076)
Bumps [pygments](https://github.com/pygments/pygments) from 2.6.1 to 2.7.4.
- [Release notes](https://github.com/pygments/pygments/releases)
- [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES)
- [Commits](https://github.com/pygments/pygments/compare/2.6.1...2.7.4)

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-29 18:59:57 -07:00
Richard Si
0be7f96d9c
Fix indentation in docs/editor_integration.md (#2056)
Numbered list entries' bodies need to be indented or else the list won't
render correctly.
2021-03-20 12:15:55 -07:00
Jairo Llopis
d62d677ca2
Recommend B950 + 88 char limit instead of 80 (#2050)
[The section about line length][1] was contradictory.

On one side, it said:

> Black will try to respect that [line length limit]. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.

So black doesn't guarantee that your code is formatted at 88 chars, even when configured with `--line-length=88` (default). Black uses this limit as a "hint" more than a "rule".

OTOH, it also said:

> If you're using Flake8, you can bump max-line-length to 88 and forget about it. Alternatively, use Bugbear's B950 warning instead of E501 and keep the max line length at 80 which you are probably already using.

But that's not true. You can't "forget about it" because Black sometimes won't respect the limit. Both E501 at 88 and B950 at 80 behave the same: linter error at 89+ length. So, if Black happens to decide that a line of code is better at 90 characters that some other fancy style, you land on a unlucky situation where both tools will fight.

So, AFAICS, the best way to align flake8 and black is to:

1. Use flake8-bugbear
2. Enable B950
3. Disable E501
4. Set `max-line-length = 88`

This way, we also tell flake8 that 88 limit is a "hint" and not a "rule". The real rule will be 88 + 10%. If black decides that a line fits better in 97 characters than in 88 + some formatting, _that_ probably means your code has a real problem.

To avoid further confusion, I change the official recommendation here.

[1]: e82bb8d8b8 (opinionated-warnings)
2021-03-18 08:14:15 -07:00
John Meow
1f7e73506c
Add ALE (#1753) 2021-03-05 20:22:19 -08:00
Utkarsh Gupta
e293473ea9
Add formatters-python for atom to editor_integration (#1834) 2021-03-03 16:46:27 -08:00
Joshua Cannon
beecd6fd0a
Add --extend-exclude parameter (#2005)
Look ma! I contribute to open source!

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2021-03-01 14:07:36 -08:00
James Addison
fe4a9d6bee
Fixup: update function name in docs to match source (#1997) 2021-02-22 07:46:38 -08:00
Paul "TBBle" Hampson
cd4295dd98
Indicate that a final newline was added in --diff (#1897) (#1897)
Fixes: #1662

Work-around for https://bugs.python.org/issue2142

The test has to slightly mess with its input data, because the utility
functions default to ensuring the test data has a final newline, which
defeats the point of the test.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-02-21 22:43:23 -08:00
Archit Gopal
71bbb678b9
add gedit integration (#1988) 2021-02-15 08:05:23 -08:00
James Addison
1c364f42ee
Regenerate documentation (#1980)
Resolves #1979 and ensures that the content from #1861 is included in the repository-published documentation.
2021-02-09 17:10:02 -08:00
Shantanu
692c0f50d9
Add --skip-magic-trailing-comma (#1824) 2021-01-17 16:59:06 -08:00
Peter Stensmyr
b55fb821e7
Update link pointing to how-black-wraps-lines (#1925)
The section about the Black code style has been moved to its own file.
Update link on the compatible configs page to point to the right place.
2021-01-14 15:57:45 -08:00
Cooper Lees
4310f39bd9
Update Contributing Docs (#1915)
* Update Contributing Docs
- Update docs with all new tox hotness
- Test running docs build:
  - `sphinx-build -a -b html -W docs/ docs/_build/`

Fixes #1907

* Fix docs/contributing_to_black.md lint

* Remove autogenerated copy pasta

* Fix review typos + regen automated docs via Running Sphinx v1.8.5
2021-01-13 15:17:30 -08:00
Shota Ray Imaki
ce269d2da5
fix #1917 (#1918) 2021-01-11 08:21:14 -08:00
Hugo van Kemenade
d34eb7fea3
As long as it's black (#1893)
Make background transparent for dark mode
2020-12-31 09:03:39 -08:00
Noel Evans
2989dc1bf8
vim plugin: Add quiet flag so non-error actions go unreported (#1733) 2020-12-09 15:40:45 -08:00
Thiago Bellini Ribeiro
dea81b7ad5
Provide a stdin-filename to allow stdin to respect force-exclude rules (#1780)
* Provide a stdin-filename to allow stdin to respect exclude/force-exclude rules

This will allow automatic tools to enforce the project's
exclude/force-exclude rules even if they pass the file through stdin to
update its buffer.

This is a similar solution to --stdin-display-name in flake8.

* Update src/black/__init__.py

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>

* --stdin-filename should only respect --exclude-filename

* Update README with the new --stdin-filename option

* Write some tests for the new stdin-filename functionality

* Apply suggestions from code review

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

* Force stdin output when we asked for stdin even if the file exists

* Add an entry in the changelog regarding --stdin-filename

* Reduce disk reads if possible

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>

* Check for is_stdin and p.is_file before checking for p.is_dir()

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-11-13 07:26:07 -08:00
Shota Ray Imaki
b64fd2bbec
Add compatible configuration files. (psf#1789) (#1792)
* Add compatible configuration files. (psf#1789)

* Simplify isort configuration files. (#1789)
2020-10-30 08:13:55 -07:00
Bibo-Joshi
cabeb5b545
Document some culprits with pre-commit (#1783)
* Document some culprits with pre-commit

* make pre-commit happy

* don't use monospace for black & pre-commit

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

* make pre-commit happy again

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-10-27 13:59:43 -07:00
Antek S
989ea69bd1
Update readme.md with current version (#1788)
* Update readme.md with current version

* Update version_control_integration.md
2020-10-27 11:52:19 +01:00
johnthagen
3be0aa71d9
Update PyCharm integrations instructions to avoid running on external changes (#1769) 2020-10-19 10:34:42 -07:00
David W.H. Swenson
3e3da8eef6
Fix GitHub markdown links to work on RTD (#1752)
* Fix internal links to work on RTD

Note that these still lead to GitHub, instead of staying on RTD.

* Point links to better anchors
2020-10-18 14:27:15 -07:00
Hadi Alqattan
4d6a84a829
Allow black's Github action params overriding. (#1755)
* Allow default params overriding.

* Update: docs and action.yaml.

* The second contirbution, add my name to authors.md

* Correct docs `with.args` example.

* Just to rerun the Travis jobs.

* chmod 755
2020-10-18 14:24:33 -07:00
Hadi Alqattan
dd2f86ac0a
Support stable Python3.9. (#1748)
* Support stable Python3.9.

* Get back to 3.9-dev

* Add py39 to black usage.

* remove 3.9 temporarily.
2020-10-08 14:13:13 -07:00
Vipul
bc138d1263
End 'force-exclude' help message with a period (#1727)
It would be nice, if like other options help message, force-exclude's
help message also ends with a period punctuation mark.
2020-09-27 07:54:21 +02:00
Richard Si
c0a8e42243
Fix empty line handling when formatting typing stubs (#1646)
Black used to erroneously remove all empty lines between non-function
code and decorators when formatting typing stubs. Now a single empty
line is enforced.

I chose for putting empty lines around decorated classes that have empty
bodies since removing empty lines around such classes would cause a
formatting issue that seems to be impossible to fix.

For example:

```
class A: ...
@some_decorator
class B: ...
class C: ...
class D: ...

@some_other_decorator
def foo(): -> None: ...
```

It is easy to enforce no empty lines between class A, B, and C.
Just return 0, 0 for a line that is a decorator and precedes an stub
class. Fortunately before this commit, empty lines after that class
would be removed already.

Now let's look at the empty line between class D and function foo. In
this case, there should be an empty line there since it's class code next
to function code. The problem is that when deciding to add X empty lines
before a decorator, you can't tell whether it's before a class or a
function. If the decorator is before a function, then an empty line
is needed, while no empty lines are needed when the decorator is
before a class.

So even though I personally prefer no empty lines around decorated
classes, I had to go the other way surrounding decorated classes with
empty lines.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2020-09-10 13:21:37 -07:00
Łukasz Langa
6b935a34d0
Clarify current trailing comma behavior in the docs 2020-09-01 13:24:31 +02:00
Łukasz Langa
1af648d0c1
Mention optional invalid W503 warning in pycodestyle 2020-09-01 13:18:46 +02:00
Richard Si
1d2d7264ec
Fix incorrect space before colon in if/while stmts (#1655)
* Fix incorrect space before colon in if/while stmts

Previously Black would format this code

```
if (foo := True):
	print(foo)
```

as

```
if (foo := True) :
	print(foo)
```

adding an incorrect space after the RPAR. Buggy code in the
normalize_invisible_parens function caused the colon to be wrapped in
invisible parentheses. The LPAR of that pair was then prefixed with a
single space at the request of the whitespace function.

This commit fixes the accidental skipping of a pre-condition check
which must return True before parenthesis normalization of a specific
child Leaf or Node can happen. The pre-condition check being skipped
was why the colon was wrapped in invisible parentheses.

* Add an entry in CHANGES.md
2020-08-31 14:20:05 -07:00
Jon Dufresne
573b8de544
Remove flake8 W503 from docs as it is ignored by default (#1661)
Fixes #1660
2020-08-31 14:18:43 -07:00
Richard Si
7fe19fac5b Fix multiline docstring quote normalization
The quotes of multiline docstrings are now only normalized when string
normalization is off, instead of the string normalization setting being
ignored and the quotes being *always* normalized.

I had to make a new test case and data file since the current pair for
docstrings only worked when there is no formatting difference between the
formatting results with string normalization on and off. I needed to add
tests for when there *are* differences between the two. So I split
test_docstring's test code when string normalization is disabled into a
new test case along with a new data file.
2020-08-27 01:59:41 +02:00
Łukasz Langa
235412635e
v20.8b1 2020-08-26 17:50:44 +02:00
Łukasz Langa
824d06f720
v20.8b0 2020-08-26 16:00:55 +02:00
Ned Twigg
4a065a43e1
Add links regarding Spotless integration for gradle/maven users (#1622)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2020-08-26 03:54:05 +02:00
Łukasz Langa
5faabb5616
Make doc generation a little smarter, update doc sections 2020-08-24 14:42:17 +02:00
Łukasz Langa
205f3b67fb Fix dealing with generated files in docs 2020-08-21 16:45:30 +02:00
Łukasz Langa
cb6f2198b8 Use properly renamed function name in docs 2020-08-21 16:45:30 +02:00
Łukasz Langa
05cc7ede6a Reformat docs/conf.py according to the new style 2020-08-21 16:45:30 +02:00
Richard Si
37a0020e07
Upgrade docs to Sphinx 3+ and add doc build test (#1613)
* Upgrade docs to Sphinx 3+
* Fix all the warnings...

- Fixed bad docstrings
- Fixed bad fenced code blocks in documentation
- Blocklisted some sections from being generated from the README
- Added missing documentation to index.rst
- Fixed an invalid autofunction directive in reference/reference_functions.rst
- Pin another documentation dependency

* Add documentation build test
2020-08-21 00:06:41 +02:00
Maximilian Cosmo Sitter
537ea8df35
Update to accomodate isort 5 release changes. (#1559)
Isort 5 introduced profiles and ensure_newline_before_comments options. Either needs to be added to work correctly with black.

Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
2020-07-21 17:29:38 -07:00
Steven Maude
5010bb4279
Update curl command to use stable branch (#1543) 2020-07-15 11:36:14 -07:00
Richard Si
f90f50a743
Fix toml hashes and make it clear that only TOML is supported (#1510)
* Fix TOML hashes

* Make it clear that only TOML is supported
2020-06-19 22:29:53 -07:00
Bharat Raghunathan
e4c55b4887
Fix grammatical typos in black_primer and blackd (#1504) 2020-06-16 11:57:33 -07:00
Richard Si
7403d95862
Refactor docs / Maintenance of docs (#1456)
* Split code style and components documentation

Splits 'the_black_code_style', 'pragmatism', 'blackd',and 'black_primer'
into their own files. The exception being 'the_black_code_style' and
'pragmatism'. They have been merged into one 'the_black_code_style_and_pragmatism'
file.

These changes are being made because the README is becoming very long. And
a README isn't great if it dissuades its reader because of its length.

* Update the doc generation logic and configuration

With the moving of several sections in the README and the renaming of a
few files, 'conf.py' needs to be able to support custom sections.

This commit introduces DocSection which can be used to specify custom
sections of documentation. The information stored in DocSection will be
used by the process_sections function to read, process, and write the section
to CURRENT_DIR.

A large change has been made to the how the docs are prepared to be built.
Instead of just generating the files needed by reading the README, this
has a full chain of operations so custom sections are supported. First,
it reads the README and spits out a list of DocSection objects representing
the sections to be generated by process_sections. This is done since most
of the docs still live in README. Then along with the defined custom_sections
, the process_sections will be begin to process the DocSection objects.
It reads the information it needs to generate the section. Then fetches
the section's contents, calls processors required by the section to process
the section's contents, and finally writes the section to CURRENT_DIR.

This large change is so processing of the documentation can be done just
for the versions hosted on ReadTheDocs.org. An example processor using this
feature is a 'replace_links' processor. It will replace documentation
links that point to the docs hosted on GitHub with links that point to the
version hosted on ReadTheDocs.org. (I won't be coding that ATM)

This also means that files will be overwritten or created once the docs
have been built. It is annoying, since you have to 'git reset --hard'
and 'git clean -f -d' after each build, but there's nothing better. The old
system had the same side effects, so yeah :(

* Update filenames and delete unnecessary files

Update the filenames since 'the_black_code_style' and 'pragmatism' were
merged and 'contributing' was deleted in favor of 'contributing_to_black'.

All symlinks were deleted since their home (_build/generated) is no longer
used.

* Fix broken links and a few redirections

* Merge master into refactor_docs (manually done)

* Add my and most of @hugovk suggestions

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

* Add logging and improve configurability

Just some cleaning up up of the DocSection dataclass and added logging
support so you know what's going on.

* Rename a section and please the grammar gods of Black

Thanks @hugovk for the suggestion!

* Fix Markdown comments

* Add myself as an author :P

Seems like the right time.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2020-05-24 09:37:46 -07:00
Richard Si
0196437f8e
Scrollable sidebar (#1457)
* Make the sidebar navigation scrollable

This is necessary since we have so many documentation sections that even
on a desktop screen, the navigation can sometimes be clipped. The only
annoyance is that on Firefox, the scrollbar can't be hidden :(

* allow the docs to build
2020-05-23 11:56:50 -07:00
Kevin Kirsche
f3599b22d4
Fix typos (#1442) 2020-05-21 06:44:43 -07:00
Cooper Lees
b0f3798aab
Add black-primer docs (#1427)
* Add `black-primer` docs

- Document the idea, CLI args, config and a example run for `black-primer` in README.md
- Add to docs/index.rst

* Add @hugovk suggestions - Thanks.
2020-05-18 07:25:40 -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