Skip to content

Commit

Permalink
Merge branch 'main' into no-changing-type-annotation-to-tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Aug 21, 2021
2 parents 3d0fd95 + 104aec5 commit 7464ff1
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 130 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-hooks.yaml
Expand Up @@ -3,7 +3,6 @@
description: "Black: The uncompromising Python code formatter"
entry: black
language: python
language_version: python3
minimum_pre_commit_version: 2.9.2
require_serial: true
types_or: [python, pyi]
Expand All @@ -13,7 +12,6 @@
"Black: The uncompromising Python code formatter (with Jupyter Notebook support)"
entry: black
language: python
language_version: python3
minimum_pre_commit_version: 2.9.2
require_serial: true
types_or: [python, pyi, jupyter]
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Expand Up @@ -6,9 +6,16 @@

- Moved from `appdirs` dependency to `platformdirs` (#2375)
- Add support for formatting Jupyter Notebook files (#2357)
- Move from `appdirs` dependency to `platformdirs` (#2375)
- Present a more user-friendly error if .gitignore is invalid (#2414)
- Avoid changing a function return type annotation's type to a tuple by adding a
trailing comma (#2384)

### Integrations

- The provided pre-commit hooks no longer specify `language_version` to avoid overriding
`default_language_version` (#2430)

## 21.7b0

### _Black_
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Expand Up @@ -21,7 +21,7 @@ setuptools = ">=39.2.0"
setuptools-scm = "*"
twine = ">=1.11.0"
wheel = ">=0.31.1"
black = {editable = true, extras = ["d"], path = "."}
black = {editable = true, extras = ["d", "jupyter"], path = "."}

[packages]
aiohttp = ">=3.6.0"
Expand Down
243 changes: 133 additions & 110 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/integrations/editors.md
Expand Up @@ -295,12 +295,12 @@ Use [sublack plugin](https://github.com/jgirardet/sublack).

Use [blackcellmagic](https://github.com/csurfer/blackcellmagic).

## Python Language Server
## Python LSP Server

If your editor supports the [Language Server Protocol](https://langserver.org/) (Atom,
Sublime Text, Visual Studio Code and many more), you can use the
[Python Language Server](https://github.com/palantir/python-language-server) with the
[pyls-black](https://github.com/rupert/pyls-black) plugin.
[Python LSP Server](https://github.com/python-lsp/python-lsp-server) with the
[python-lsp-black](https://github.com/python-lsp/python-lsp-black) plugin.

## Atom/Nuclide

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -77,7 +77,7 @@ def get_long_description() -> str:
"tomli>=0.2.6,<2.0.0",
"typed-ast>=1.4.2; python_version < '3.8'",
"regex>=2020.1.8",
"pathspec>=0.8.1, <1",
"pathspec>=0.9.0, <1",
"dataclasses>=0.6; python_version < '3.7'",
"typing_extensions>=3.10.0.0; python_version < '3.10'",
"mypy_extensions>=0.4.3",
Expand Down
28 changes: 16 additions & 12 deletions src/black/__init__.py
Expand Up @@ -9,6 +9,7 @@
from multiprocessing import Manager, freeze_support
import os
from pathlib import Path
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
import regex as re
import signal
import sys
Expand Down Expand Up @@ -428,18 +429,21 @@ def main(
content=code, fast=fast, write_back=write_back, mode=mode, report=report
)
else:
sources = get_sources(
ctx=ctx,
src=src,
quiet=quiet,
verbose=verbose,
include=include,
exclude=exclude,
extend_exclude=extend_exclude,
force_exclude=force_exclude,
report=report,
stdin_filename=stdin_filename,
)
try:
sources = get_sources(
ctx=ctx,
src=src,
quiet=quiet,
verbose=verbose,
include=include,
exclude=exclude,
extend_exclude=extend_exclude,
force_exclude=force_exclude,
report=report,
stdin_filename=stdin_filename,
)
except GitWildMatchPatternError:
ctx.exit(1)

path_empty(
sources,
Expand Down
7 changes: 6 additions & 1 deletion src/black/files.py
Expand Up @@ -18,6 +18,7 @@
)

from pathspec import PathSpec
from pathspec.patterns.gitwildmatch import GitWildMatchPatternError
import tomli

from black.output import err
Expand Down Expand Up @@ -122,7 +123,11 @@ def get_gitignore(root: Path) -> PathSpec:
if gitignore.is_file():
with gitignore.open(encoding="utf-8") as gf:
lines = gf.readlines()
return PathSpec.from_lines("gitwildmatch", lines)
try:
return PathSpec.from_lines("gitwildmatch", lines)
except GitWildMatchPatternError as e:
err(f"Could not parse {gitignore}: {e}")
raise


def normalize_path_maybe_ignore(
Expand Down
1 change: 1 addition & 0 deletions tests/data/invalid_gitignore_tests/.gitignore
@@ -0,0 +1 @@
!
Empty file.
1 change: 1 addition & 0 deletions tests/data/invalid_gitignore_tests/pyproject.toml
@@ -0,0 +1 @@
# Empty configuration file; used in tests to avoid interference from Black's own config.
Empty file.
1 change: 1 addition & 0 deletions tests/data/invalid_nested_gitignore_tests/a/.gitignore
@@ -0,0 +1 @@
!
Empty file.
1 change: 1 addition & 0 deletions tests/data/invalid_nested_gitignore_tests/pyproject.toml
@@ -0,0 +1 @@
# Empty configuration file; used in tests to avoid interference from Black's own config.
24 changes: 24 additions & 0 deletions tests/test_black.py
Expand Up @@ -1727,6 +1727,30 @@ def test_nested_gitignore(self) -> None:
)
self.assertEqual(sorted(expected), sorted(sources))

def test_invalid_gitignore(self) -> None:
path = THIS_DIR / "data" / "invalid_gitignore_tests"
empty_config = path / "pyproject.toml"
result = BlackRunner().invoke(
black.main, ["--verbose", "--config", str(empty_config), str(path)]
)
assert result.exit_code == 1
assert result.stderr_bytes is not None

gitignore = path / ".gitignore"
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()

def test_invalid_nested_gitignore(self) -> None:
path = THIS_DIR / "data" / "invalid_nested_gitignore_tests"
empty_config = path / "pyproject.toml"
result = BlackRunner().invoke(
black.main, ["--verbose", "--config", str(empty_config), str(path)]
)
assert result.exit_code == 1
assert result.stderr_bytes is not None

gitignore = path / "a" / ".gitignore"
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()

def test_empty_include(self) -> None:
path = THIS_DIR / "data" / "include_exclude_tests"
report = black.Report()
Expand Down

0 comments on commit 7464ff1

Please sign in to comment.