Commit Graph

1872 Commits

Author SHA1 Message Date
cobalt
0f18001abf
chore: Refactor delimiter_split() (#4257)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
2024-02-28 08:27:57 -08:00
Victorien
899002399a
Remove usage of pkg_resources in docs/conf.py (#4251) 2024-02-26 07:49:39 -08:00
Shantanu
ea66d40dd7
Update empty line documentation (#4239)
Reflects status quo following #4043

Fixes #4238
2024-02-25 16:36:52 -08:00
Shantanu
d1d4fc58d3
Add new release template (#4228) 2024-02-12 12:46:16 -08:00
Shantanu
6fdf8a4af2
Prepare release 24.2.0 (#4226) 2024-02-12 12:11:15 -08:00
cobalt
8af439407c
fix: Don't remove comments along with parens (#4218)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
2024-02-12 06:27:50 -08:00
dependabot[bot]
35e9776919
Bump pre-commit/action from 3.0.0 to 3.0.1 (#4225)
Bumps [pre-commit/action](https://github.com/pre-commit/action) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/pre-commit/action/releases)
- [Commits](https://github.com/pre-commit/action/compare/v3.0.0...v3.0.1)

---
updated-dependencies:
- dependency-name: pre-commit/action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-12 06:19:25 -08:00
Shantanu
23dfc5b2c3
Fix ignoring input files for symlink reasons (#4222)
This relates to #4015, #4161 and the behaviour of os.getcwd()

Black is a big user of pathlib and as such loves doing `.resolve()`,
since for a long time it was the only good way of getting an absolute
path in pathlib. However, this has two problems:

The first minor problem is performance, e.g. in #3751 I (safely) got rid
of a bunch of `.resolve()` which made Black 40% faster on cached runs.

The second more important problem is that always resolving symlinks
results in unintuitive exclusion behaviour. For instance, a gitignored
symlink should never alter formatting of your actual code. This kind of
thing was reported by users a few times.

In #3846, I improved the exclusion rule logic for symlinks in
`gen_python_files` and everything was good.

But `gen_python_files` isn't enough, there's also `get_sources`, which
handles user specified paths directly (instead of files Black
discovers). So in #4015, I made a very similar change to #3846 for
`get_sources`, and this is where some problems began.

The core issue was the line:
```
root_relative_path = path.absolute().relative_to(root).as_posix()
```
The first issue is that despite root being computed from user inputs, we
call `.resolve()` while computing it (likely unecessarily). Which means
that `path` may not actually be relative to `root`. So I started off
this PR trying to fix that, when I ran into the second issue. Which is
that `os.getcwd()` (as called by `os.path.abspath` or `Path.absolute` or
`Path.cwd`) also often resolves symlinks!
```
>>> import os
>>> os.environ.get("PWD")
'/Users/shantanu/dev/black/symlink/bug'
>>> os.getcwd()
'/Users/shantanu/dev/black/actual/bug'
```
This also meant that the breakage often would not show up when input
relative paths.

This doesn't affect `gen_python_files` / #3846 because things are always
absolute and known to be relative to `root`.

Anyway, it looks like #4161 fixed the crash by just swallowing the error
and ignoring the file. Instead, we should just try to compute the actual
relative path. I think this PR should be quite safe, but we could also
consider reverting some of the previous changes; the associated issues
weren't too popular.

At the same time, I think there's still behaviour that can be improved
and I kind of want to make larger changes, but maybe I'll save that for
if we do something like #3952

Hopefully fixes #4205, fixes #4209, actual fix for #4077
2024-02-12 00:04:09 -08:00
Shantanu
a20100395c
Simplify check for symlinks that resolve outside root (#4221)
This PR does not change any behaviour.

There have been 1-2 issues about symlinks recently. Both over and under
resolving can cause problems. This makes a case where we resolve more
explicit and prevent a resolved path from leaking out via the return.
2024-02-10 23:55:01 -08:00
Logan Hunt
dab37a6a11
Remove redundant parentheses in case statement if guards (#4214)
A follow up to #4024 but for `if` guards in `case` statements. I noticed this
when #4024 was made stable, and noticed I had some code that had extra parens
around the `if` guard.
2024-02-07 06:55:02 -08:00
Seung Wan Yoo
32230e6f5c
fix: bug where the doublestar operation had inconsistent formatting. (#4154)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-02-05 05:33:11 -08:00
Brandon J
7edb50f5a0
fix: additional newline added to docstring when the previous line length is less than the line length limit minus 1 (#4185)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-02-05 04:56:07 -08:00
dependabot[bot]
3e80de3447
Bump furo from 2023.9.10 to 2024.1.29 in /docs (#4211)
Bumps [furo](https://github.com/pradyunsg/furo) from 2023.9.10 to 2024.1.29.
- [Release notes](https://github.com/pradyunsg/furo/releases)
- [Changelog](https://github.com/pradyunsg/furo/blob/main/docs/changelog.md)
- [Commits](https://github.com/pradyunsg/furo/compare/2023.09.10...2024.01.29)

---
updated-dependencies:
- dependency-name: furo
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-05 04:47:35 -08:00
dependabot[bot]
a08b480a2f
Bump pypa/cibuildwheel from 2.16.4 to 2.16.5 (#4212) 2024-02-05 01:09:21 -08:00
cobalt
632f44bd68
docs: Refactor pycodestyle/Flake8 compatibility docs (#4194)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-02-01 22:00:41 -08:00
Jelle Zijlstra
9728b8e9b8
Move hug_parens_with_braces_and_square_brackets into the unstable style (#4198)
Primarily because of #4036 (a crash) but also because of the feedback
in #4098 and #4099.
2024-02-01 21:58:51 -08:00
Shantanu
2623269dab
Ignore pyproject.toml missing tool.black section (#4204)
Fixes #2863

This is pretty desirable in a monorepo situation where you have
configuration in the root since it will mean you don't have to
reconfigure every project.

The good news for backward compatibility is that `find_project_root`
continues to stop at any git or hg root, so in all cases repo root
coincides with a pyproject.toml missing tool.black, we'll continue to
have the project root as before and end up using default config
(i.e. we're unlikely to randomly start using the user config).

The other thing we need to be a little careful about is that changing
find_project_root logic affects what `exclude` is relative to.  Since we
only change in cases where there is no config, this only applies where
users were using `exclude` via command line arg (and had pyproject.toml
missing tool.black in a dir that was not repo root).

Finally, for the few who could be affected, the fix is to put an empty
`[tool.black]` in pyproject.toml
2024-02-01 21:50:45 -08:00
Henry Schreiner
24c9c01e91
fix: minor issue with schemastore part of script (#4195)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2024-02-01 09:25:38 -08:00
Jelle Zijlstra
cca3c0fd9f
Test that preview/unstable features are documented (#4187)
In #4096 I added a list of current preview/unstable features to the docs. I think
this is important for publicizing what's in our preview style. This PR adds an
automated test to ensure the list stays up to date in the future.
2024-01-30 22:22:38 -08:00
dependabot[bot]
d6e11ca399
Bump peter-evans/find-comment from 2.4.0 to 3.0.0 (#4190)
Bumps [peter-evans/find-comment](https://github.com/peter-evans/find-comment) from 2.4.0 to 3.0.0.
- [Release notes](https://github.com/peter-evans/find-comment/releases)
- [Commits](a54c31d7fa...d5fe37641a)

---
updated-dependencies:
- dependency-name: peter-evans/find-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-29 08:27:21 -08:00
dependabot[bot]
8912a33321
Bump peter-evans/create-or-update-comment from 3.1.0 to 4.0.0 (#4192)
Bumps [peter-evans/create-or-update-comment](https://github.com/peter-evans/create-or-update-comment) from 3.1.0 to 4.0.0.
- [Release notes](https://github.com/peter-evans/create-or-update-comment/releases)
- [Commits](23ff15729e...71345be026)

---
updated-dependencies:
- dependency-name: peter-evans/create-or-update-comment
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-29 08:21:00 -08:00
Henry Schreiner
2bc5ce8ae1
feat: add schema and validate-pyproject support (#4181)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-01-29 07:56:48 -08:00
dependabot[bot]
177e306363
Bump pypa/cibuildwheel from 2.16.2 to 2.16.4 (#4191)
Bumps [pypa/cibuildwheel](https://github.com/pypa/cibuildwheel) from 2.16.2 to 2.16.4.
- [Release notes](https://github.com/pypa/cibuildwheel/releases)
- [Changelog](https://github.com/pypa/cibuildwheel/blob/main/docs/changelog.md)
- [Commits](https://github.com/pypa/cibuildwheel/compare/v2.16.2...v2.16.4)
2024-01-28 23:07:34 -08:00
Shantanu
d919746fae
Swallow warnings when performing AST checks (#4189)
Fixes #4188
2024-01-28 07:05:56 -08:00
Jelle Zijlstra
0b4364b7e3 Add new release template 2024-01-28 05:37:12 -08:00
Jelle Zijlstra
e026c93888
Prepare release 24.1.1 (#4186) 2024-01-27 20:51:32 -08:00
Henry Schreiner
79fc1158a9
chore: ignore node_modules (produced by a pre-commit check) (#4184)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
2024-01-27 20:24:36 -08:00
cobalt
8bf04549ff
Consistently add trailing comma on typed parameters (#4164)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-01-27 13:55:22 -08:00
Jelle Zijlstra
1607e9ab20
Fix missing space in option description (#4182) 2024-01-27 12:34:02 -08:00
Jelle Zijlstra
ed770ba4dd
Fix cache file length (#4176)
- Ensure total file length stays under 96
- Hash the path only if it's too long
- Proceed normally (with a warning) if the cache can't be read

Fixes #4172
2024-01-26 11:54:49 -08:00
Jelle Zijlstra
659c29a41c New changelog 2024-01-25 21:12:38 -08:00
Jelle Zijlstra
0e6e46b9eb
Prepare release 24.1.0 (#4170) 2024-01-25 20:35:21 -08:00
Jelle Zijlstra
4f47cac192
Add --unstable flag (#4096) 2024-01-25 17:00:47 -08:00
Daniel Krzeminski
bccec8adfb
Show warning on invalid toml configuration (#4165)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-01-25 16:41:37 -08:00
Shantanu
7d789469ed
Describe 2024 module docstring more accurately (#4168) 2024-01-25 16:15:18 -08:00
Shantanu
17f7f297ef
Simplify code in lines.py (#4167)
This has been getting a little messy. These changes neaten things up, we
don't have to keep guarding against `self.previous_line is not None`, we
make it clearer what logic has side effects, we reduce the amount of
code that tricky `before` could touch, etc
2024-01-25 13:41:45 -08:00
Shantanu
f7d552d9b7
Remove reference (#4169)
This is out-of-date and just a chore. I don't think this is useful to
contributors and Black doesn't even have a public API.
2024-01-25 13:11:26 -08:00
cobalt
a5196e6f1f
fix: Don't normalize whitespace before fmt:skip comments (#4146)
Signed-off-by: RedGuy12 <paul@reid-family.org>
2024-01-25 01:31:49 -08:00
Jelle Zijlstra
59b9d858a3
Create the 2024 stable style (#4106) 2024-01-24 17:06:14 -08:00
Daniel Krzeminski
8fe602b1fa
fix pathlib exception handling with symlinks (#4161)
Fixes #4077
2024-01-22 09:46:57 -08:00
dependabot[bot]
6f3fb78444
Bump actions/cache from 3 to 4 (#4162)
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/cache
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-22 09:22:56 -08:00
Shantanu
995e4ada14
Fix unnecessary nesting when wrapping long dict (#4135)
Fixes #4129
2024-01-19 17:13:26 -08:00
Kevin Paulson
7f60f3dbd7
Update using_black_with_other_tools.md to ensure flake8 configuration examples are consistant (#4157) 2024-01-19 15:54:32 -08:00
cobalt
9a331d606f
fix: Don't allow unparenthesizing walruses (#4155)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Signed-off-by: RedGuy12 <paul@reid-family.org>
2024-01-17 11:04:15 -08:00
Dragorn421
b7c3a9fedd
Docs: Add note on --exclude about possibly verbose regex (#4145)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-01-11 07:46:17 -08:00
Shantanu
e11eaf2f44
Make blank_line_after_nested_stub_class work for methods (#4141)
Fixes #4113

Authored by dhruvmanila
2024-01-01 20:14:57 -08:00
Shantanu
b1d17ef9a2
Fix comment handling when parenthesising conditional expressions (#4134)
Fixes #3555
2024-01-01 17:55:11 -08:00
Shantanu
4ceed0b958
Remove is_function_or_class helper footgun (#4133)
This is a no-op change.

That function was not a good way to tell if something is a function or a
class, since it basically only worked for async functions by accident
(the parent of a suite / simple_stmt of async function body is a
funcdef).
2024-01-01 17:36:49 -08:00
Shantanu
269190274b
Clean up dead code in magic trailing comma logic (#4131) 2024-01-01 17:29:21 -08:00
Shantanu
8e0a9dee1b
Remove empty lines before docstrings in async functions (#4132) 2024-01-01 16:56:39 -08:00