Skip to content

Commit

Permalink
Merge pull request #1446 from PyCQA/issue/1434/backslash-grid
Browse files Browse the repository at this point in the history
Resovle #1434 add backslash-grid mode
  • Loading branch information
timothycrosley committed Sep 1, 2020
2 parents c13e83e + b3a22bc commit ba8cf2f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Expand Up @@ -164,7 +164,7 @@ notified.

You will notice above the \"multi\_line\_output\" setting. This setting
defines how from imports wrap when they extend past the line\_length
limit and has 6 possible settings:
limit and has 12 possible settings:

**0 - Grid**

Expand Down Expand Up @@ -285,7 +285,18 @@ from third_party import (
lib4, lib5, lib6)
```

Note: to change the how constant indents appear - simply change the
**11 - Backslash Grid**

Same as Mode 0 - _Grid_ but uses backslashes instead of parentheses to group imports.

```python
from third_party import lib1, lib2, lib3, \
lib4, lib5
```

## Indentation

To change the how constant indents appear - simply change the
indent property with the following accepted formats:

- Number of spaces you would like. For example: 4 would cause standard
Expand Down
6 changes: 6 additions & 0 deletions isort/wrap_modes.py
Expand Up @@ -306,6 +306,12 @@ def hanging_indent_with_parentheses(**interface):
return _hanging_indent_common(use_parentheses=True, **interface)


@_wrap_mode
def backslash_grid(**interface):
interface["indent"] = interface["white_space"][:-1]
return _hanging_indent_common(use_parentheses=False, **interface)


WrapModes = enum.Enum( # type: ignore
"WrapModes", {wrap_mode: index for index, wrap_mode in enumerate(_wrap_modes.keys())}
)
29 changes: 29 additions & 0 deletions tests/unit/test_wrap_modes.py
@@ -1,5 +1,6 @@
from hypothesis_auto import auto_pytest_magic

import isort
from isort import wrap_modes

auto_pytest_magic(wrap_modes.grid, auto_allow_exceptions_=(ValueError,))
Expand All @@ -21,6 +22,7 @@
imports=["one", "two"],
)
auto_pytest_magic(wrap_modes.hanging_indent_with_parentheses, auto_allow_exceptions_=(ValueError,))
auto_pytest_magic(wrap_modes.backslash_grid, auto_allow_exceptions_=(ValueError,))


def test_wrap_mode_interface():
Expand Down Expand Up @@ -65,3 +67,30 @@ def test_auto_saved():
)
== '*\x12\x07\U0009e994🁣"\U000ae787\x0e \x00\U0001ae99\U0005c3e7\U0004d08e \x1e '
)


def test_backslash_grid():
"""Tests the backslash_grid grid wrap mode, ensuring it matches formatting expectations.
See: https://github.com/PyCQA/isort/issues/1434
"""
assert (
isort.code(
"""
from kopf.engines import loggers, posting
from kopf.reactor import causation, daemons, effects, handling, lifecycles, registries
from kopf.storage import finalizers, states
from kopf.structs import (bodies, configuration, containers, diffs,
handlers as handlers_, patches, resources)
""",
multi_line_output=11,
line_length=88,
combine_as_imports=True,
)
== """
from kopf.engines import loggers, posting
from kopf.reactor import causation, daemons, effects, handling, lifecycles, registries
from kopf.storage import finalizers, states
from kopf.structs import bodies, configuration, containers, diffs, \\
handlers as handlers_, patches, resources
"""
)

0 comments on commit ba8cf2f

Please sign in to comment.