Skip to content

Commit

Permalink
Merge branch 'main' into feat/use-paren-int-method-calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jan 27, 2022
2 parents 9d6a0d4 + b92822a commit a6551df
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 110 deletions.
47 changes: 0 additions & 47 deletions .github/workflows/primer.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/uvloop_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ jobs:
run: |
python -m pip install -e ".[uvloop]"
- name: Primer uvloop run
- name: Format ourselves
run: |
black-primer
python -m black --check src/
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- Use parentheses for attribute access on decimal float and int literals (#2799)
- Don't add whitespace for attribute access on hexadecimal, binary, octal, and complex
literals (#2799)
- Deprecate the `black-primer` tool (#2809)

### Packaging

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<p align="center">
<a href="https://github.com/psf/black/actions"><img alt="Actions Status" src="https://github.com/psf/black/workflows/Test/badge.svg"></a>
<a href="https://github.com/psf/black/actions"><img alt="Actions Status" src="https://github.com/psf/black/workflows/Primer/badge.svg"></a>
<a href="https://black.readthedocs.io/en/stable/?badge=stable"><img alt="Documentation Status" src="https://readthedocs.org/projects/black/badge/?version=stable"></a>
<a href="https://coveralls.io/github/psf/black?branch=main"><img alt="Coverage Status" src="https://coveralls.io/repos/github/psf/black/badge.svg?branch=main"></a>
<a href="https://github.com/psf/black/blob/main/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>
Expand Down
49 changes: 7 additions & 42 deletions docs/contributing/gauging_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,16 @@ enough to cause frustration to projects that are already "black formatted".

## black-primer

`black-primer` is a tool built for CI (and humans) to have _Black_ `--check` a number of
Git accessible projects in parallel. (configured in `primer.json`) _(A PR will be
accepted to add Mercurial support.)_

### Run flow

- Ensure we have a `black` + `git` in PATH
- Load projects from `primer.json`
- Run projects in parallel with `--worker` workers (defaults to CPU count / 2)
- Checkout projects
- Run black and record result
- Clean up repository checkout _(can optionally be disabled via `--keep`)_
- Display results summary to screen
- Default to cleaning up `--work-dir` (which defaults to tempfile schemantics)
- Return
- 0 for successful run
- \< 0 for environment / internal error
- \> 0 for each project with an error

### Speed up runs 🏎

If you're running locally yourself to test black on lots of code try:

- Using `-k` / `--keep` + `-w` / `--work-dir` so you don't have to re-checkout the repo
each run

### CLI arguments

```{program-output} black-primer --help
```
`black-primer` is an obsolete tool (now replaced with `diff-shades`) that was used to
gauge the impact of changes in _Black_ on open-source code. It is no longer used
internally and will be removed from the _Black_ repository in the future.

## diff-shades

diff-shades is a tool similar to black-primer, it also runs _Black_ across a list of Git
cloneable OSS projects recording the results. The intention is to eventually fully
replace black-primer with diff-shades as it's much more feature complete and supports
our needs better.

The main highlight feature of diff-shades is being able to compare two revisions of
_Black_. This is incredibly useful as it allows us to see what exact changes will occur,
say merging a certain PR. Black-primer's results would usually be filled with changes
caused by pre-existing code in Black drowning out the (new) changes we want to see. It
operates similarly to black-primer but crucially it saves the results as a JSON file
which allows for the rich comparison features alluded to above.
diff-shades is a tool that runs _Black_ across a list of Git cloneable OSS projects
recording the results. The main highlight feature of diff-shades is being able to
compare two revisions of _Black_. This is incredibly useful as it allows us to see what
exact changes will occur, say merging a certain PR.

For more information, please see the [diff-shades documentation][diff-shades].

Expand Down
15 changes: 0 additions & 15 deletions docs/contributing/the_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ the root of the black repo:

# Optional Fuzz testing
(.venv)$ tox -e fuzz

# Optional CI run to test your changes on many popular python projects
(.venv)$ black-primer [-k -w /tmp/black_test_repos]
```

### News / Changelog Requirement
Expand Down Expand Up @@ -69,18 +66,6 @@ If you make changes to docs, you can test they still build locally too.
(.venv)$ sphinx-build -a -b html -W docs/ docs/_build/
```

## black-primer

`black-primer` is used by CI to pull down well-known _Black_ formatted projects and see
if we get source code changes. It will error on formatting changes or errors. Please run
before pushing your PR to see if you get the actions you would expect from _Black_ with
your PR. You may need to change
[primer.json](https://github.com/psf/black/blob/main/src/black_primer/primer.json)
configuration for it to pass.

For more `black-primer` information visit the
[documentation](./gauging_changes.md#black-primer).

## Hygiene

If you're fixing a bug, add a test. Run it first to confirm it fails, then fix the bug,
Expand Down
2 changes: 2 additions & 0 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ def generate_trailers_to_omit(line: Line, line_length: int) -> Iterator[Set[Leaf
if (
prev
and prev.type == token.COMMA
and leaf.opening_bracket is not None
and not is_one_tuple_between(
leaf.opening_bracket, leaf, line.leaves
)
Expand Down Expand Up @@ -991,6 +992,7 @@ def generate_trailers_to_omit(line: Line, line_length: int) -> Iterator[Set[Leaf
if (
prev
and prev.type == token.COMMA
and leaf.opening_bracket is not None
and not is_one_tuple_between(leaf.opening_bracket, leaf, line.leaves)
):
# Never omit bracket pairs with trailing commas.
Expand Down
4 changes: 3 additions & 1 deletion src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ def has_magic_trailing_comma(
if self.is_import:
return True

if not is_one_tuple_between(closing.opening_bracket, closing, self.leaves):
if closing.opening_bracket is not None and not is_one_tuple_between(
closing.opening_bracket, closing, self.leaves
):
return True

return False
Expand Down
6 changes: 5 additions & 1 deletion src/blib2to3/pytree.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ class Leaf(Base):
value: Text
fixers_applied: List[Any]
bracket_depth: int
opening_bracket: "Leaf"
# Changed later in brackets.py
opening_bracket: Optional["Leaf"] = None
used_names: Optional[Set[Text]]
_prefix = "" # Whitespace and comments preceding this token in the input
lineno: int = 0 # Line where this token starts in the input
Expand All @@ -399,6 +400,7 @@ def __init__(
context: Optional[Context] = None,
prefix: Optional[Text] = None,
fixers_applied: List[Any] = [],
opening_bracket: Optional["Leaf"] = None,
) -> None:
"""
Initializer.
Expand All @@ -416,6 +418,7 @@ def __init__(
self._prefix = prefix
self.fixers_applied: Optional[List[Any]] = fixers_applied[:]
self.children = []
self.opening_bracket = opening_bracket

def __repr__(self) -> str:
"""Return a canonical string representation."""
Expand Down Expand Up @@ -448,6 +451,7 @@ def clone(self) -> "Leaf":
self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied,
opening_bracket=self.opening_bracket,
)

def leaves(self) -> Iterator["Leaf"]:
Expand Down
10 changes: 10 additions & 0 deletions tests/data/power_op_newline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
importA;()<<0**0#

# output

importA
(
()
<< 0
** 0
) #
48 changes: 47 additions & 1 deletion tests/data/trailing_comma_optional_parens1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
_winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
pass


class X:
def get_help_text(self):
return ngettext(
"Your password must contain at least %(min_length)d character.",
"Your password must contain at least %(min_length)d characters.",
self.min_length,
) % {'min_length': self.min_length}

class A:
def b(self):
if self.connection.mysql_is_mariadb and (
10,
4,
3,
) < self.connection.mysql_version < (10, 5, 2):
pass


# output

if (
Expand All @@ -12,4 +31,31 @@
)
or _check_timeout(t)
):
pass
pass


class X:
def get_help_text(self):
return (
ngettext(
"Your password must contain at least %(min_length)d character.",
"Your password must contain at least %(min_length)d characters.",
self.min_length,
)
% {"min_length": self.min_length}
)


class A:
def b(self):
if (
self.connection.mysql_is_mariadb
and (
10,
4,
3,
)
< self.connection.mysql_version
< (10, 5, 2)
):
pass
6 changes: 6 additions & 0 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,9 @@ def test_python38() -> None:
def test_python39() -> None:
source, expected = read_data("python39")
assert_format(source, expected, minimum_version=(3, 9))


def test_power_op_newline() -> None:
# requires line_length=0
source, expected = read_data("power_op_newline")
assert_format(source, expected, mode=black.Mode(line_length=0))

0 comments on commit a6551df

Please sign in to comment.