Skip to content

Commit 7be43d0

Browse files
Merge branch 'main' into better-gitignore
2 parents dd78ecf + 3dc4d89 commit 7be43d0

26 files changed

+219
-134
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,19 @@ Changelog
44
NOTE: isort follows the [semver](https://semver.org/) versioning standard.
55
Find out more about isort's release policy [here](https://pycqa.github.io/isort/docs/major_releases/release_policy).
66

7-
### 5.9.2
7+
### 5.9.3 TBD
8+
- Improved text of skipped file message to mention gitignore feature.
9+
- Fixed #1779: Pylama integration ignores pylama specific isort config overrides.
10+
- Fixed #1781: `--from-first` CLI flag shouldn't take any arguments.
11+
- Fixed #1785: `_ast` module incorrectly excluded from stdlib definition.
12+
13+
### 5.9.2 July 8th 2021
814
- Improved behavior of `isort --check --atomic` against Cython files.
15+
- Fixed #1769: Future imports added below assignments when no other imports present.
16+
- Fixed #1772: skip-gitignore will check files not in the git repository.
17+
- Fixed #1762: in some cases when skip-gitignore is set, isort fails to skip any files.
18+
- Fixed #1767: Encoding issues surfacing when invalid characters set in `__init__.py` files during placement.
19+
- Fixed #1771: Improved handling of skips against named streamed in content.
920

1021
### 5.9.1 June 21st 2021 [hotfix]
1122
- Fixed #1758: projects with many files and skip_ignore set can lead to a command-line overload.

docs/configuration/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Force all imports to be sorted as a single section
622622

623623
## Force Grid Wrap
624624

625-
Force number of from imports (defaults to 2 when passed as CLI flag without value)to be grid wrapped regardless of line length. If 0 is passed in (the global default) only line length is considered.
625+
Force number of from imports (defaults to 2 when passed as CLI flag without value) to be grid wrapped regardless of line length. If 0 is passed in (the global default) only line length is considered.
626626

627627
**Type:** Int
628628
**Default:** `0`

docs/contributing/4.-acknowledgements.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Code Contributors
229229
- Arthur Rio (@arthurio)
230230
- Bob (@bobwalker99)
231231
- Martijn Pieters (@mjpieters)
232+
- Asiel Díaz Benítez (@adbenitez)
232233

233234
Documenters
234235
===================
@@ -256,6 +257,9 @@ Documenters
256257
- David Poznik (@dpoznik)
257258
- Mike Frysinger (@vapier)
258259
- @DanielFEvans
260+
- Giuseppe Lumia (@glumia)
261+
- John Brock (@JohnHBrock)
262+
- Sergey Fedoseev (@sir-sigurd)
259263

260264
--------------------------------------------
261265

isort/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "5.9.1"
1+
__version__ = "5.9.2"

isort/core.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def process(
5555
next_import_section: str = ""
5656
next_cimports: bool = False
5757
in_quote: str = ""
58+
was_in_quote: bool = False
5859
first_comment_index_start: int = -1
5960
first_comment_index_end: int = -1
6061
contains_imports: bool = False
@@ -332,14 +333,15 @@ def process(
332333
and (stripped_line or end_of_file)
333334
and not config.append_only
334335
and not in_top_comment
335-
and not in_quote
336+
and not was_in_quote
336337
and not import_section
337338
and not line.lstrip().startswith(COMMENT_INDICATORS)
338-
and not line.rstrip().endswith(DOCSTRING_INDICATORS)
339+
and not (line.rstrip().endswith(DOCSTRING_INDICATORS) and "=" not in line)
339340
):
340-
import_section = line_separator.join(add_imports) + line_separator
341+
add_line_separator = line_separator or "\n"
342+
import_section = add_line_separator.join(add_imports) + add_line_separator
341343
if end_of_file and index != 0:
342-
output_stream.write(line_separator)
344+
output_stream.write(add_line_separator)
343345
contains_imports = True
344346
add_imports = []
345347

isort/main.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
462462
"--ff",
463463
"--from-first",
464464
dest="from_first",
465+
action="store_true",
465466
help="Switches the typical ordering preference, "
466467
"showing from imports first then straight ones.",
467468
)
@@ -472,7 +473,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
472473
const=2,
473474
type=int,
474475
dest="force_grid_wrap",
475-
help="Force number of from imports (defaults to 2 when passed as CLI flag without value)"
476+
help="Force number of from imports (defaults to 2 when passed as CLI flag without value) "
476477
"to be grid wrapped regardless of line "
477478
"length. If 0 is passed in (the global default) only line length is considered.",
478479
)
@@ -1087,9 +1088,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
10871088
if show_files:
10881089
sys.exit("Error: can't show files for streaming input.")
10891090

1091+
input_stream = sys.stdin if stdin is None else stdin
10901092
if check:
10911093
incorrectly_sorted = not api.check_stream(
1092-
input_stream=sys.stdin if stdin is None else stdin,
1094+
input_stream=input_stream,
10931095
config=config,
10941096
show_diff=show_diff,
10951097
file_path=file_path,
@@ -1098,15 +1100,18 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
10981100

10991101
wrong_sorted_files = incorrectly_sorted
11001102
else:
1101-
api.sort_stream(
1102-
input_stream=sys.stdin if stdin is None else stdin,
1103-
output_stream=sys.stdout,
1104-
config=config,
1105-
show_diff=show_diff,
1106-
file_path=file_path,
1107-
extension=ext_format,
1108-
raise_on_skip=False,
1109-
)
1103+
try:
1104+
api.sort_stream(
1105+
input_stream=input_stream,
1106+
output_stream=sys.stdout,
1107+
config=config,
1108+
show_diff=show_diff,
1109+
file_path=file_path,
1110+
extension=ext_format,
1111+
raise_on_skip=False,
1112+
)
1113+
except FileSkipped:
1114+
sys.stdout.write(input_stream.read())
11101115
elif "/" in file_names and not allow_root:
11111116
printer = create_terminal_printer(
11121117
color=config.color_output, error=config.format_error, success=config.format_success
@@ -1200,8 +1205,9 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
12001205
if config.verbose:
12011206
for was_skipped in skipped:
12021207
print(
1203-
f"{was_skipped} was skipped as it's listed in 'skip' setting"
1204-
" or matches a glob in 'skip_glob' setting"
1208+
f"{was_skipped} was skipped as it's listed in 'skip' setting, "
1209+
"matches a glob in 'skip_glob' setting, or is in a .gitignore file with "
1210+
"--skip-gitignore enabled."
12051211
)
12061212
print(f"Skipped {num_skipped} files")
12071213

isort/place.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ def _is_namespace_package(path: Path, src_extensions: FrozenSet[str]) -> bool:
125125
if filenames:
126126
return False
127127
else:
128-
with init_file.open() as open_init_file:
128+
with init_file.open("rb") as open_init_file:
129129
file_start = open_init_file.read(4096)
130130
if (
131-
"__import__('pkg_resources').declare_namespace(__name__)" not in file_start
132-
and '__import__("pkg_resources").declare_namespace(__name__)' not in file_start
133-
and "__path__ = __import__('pkgutil').extend_path(__path__, __name__)"
131+
b"__import__('pkg_resources').declare_namespace(__name__)" not in file_start
132+
and b'__import__("pkg_resources").declare_namespace(__name__)' not in file_start
133+
and b"__path__ = __import__('pkgutil').extend_path(__path__, __name__)"
134134
not in file_start
135-
and '__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
135+
and b'__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
136136
not in file_start
137137
):
138138
return False

isort/pylama_isort.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
import sys
33
from contextlib import contextmanager
4-
from typing import Any, Dict, Iterator, List
4+
from typing import Any, Dict, Iterator, List, Optional
55

66
from pylama.lint import Linter as BaseLinter # type: ignore
77

@@ -24,11 +24,13 @@ def allow(self, path: str) -> bool:
2424
"""Determine if this path should be linted."""
2525
return path.endswith(".py")
2626

27-
def run(self, path: str, **meta: Any) -> List[Dict[str, Any]]:
27+
def run(
28+
self, path: str, params: Optional[Dict[str, Any]] = None, **meta: Any
29+
) -> List[Dict[str, Any]]:
2830
"""Lint the file. Return an array of error dicts if appropriate."""
2931
with supress_stdout():
3032
try:
31-
if not api.check_file(path, disregard_skip=False):
33+
if not api.check_file(path, disregard_skip=False, **params or {}):
3234
return [
3335
{
3436
"lnum": 0,

isort/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,12 @@ def _check_folder_gitignore(self, folder: str) -> Optional[Path]:
550550

551551
files: List[str] = []
552552
# don't check symlinks; either part of the repo and would be checked
553-
# twice, or is external to the repo and git won't konw anything about it
553+
# twice, or is external to the repo and git won't know anything about it
554554
for root, _dirs, git_files in os.walk(git_folder, followlinks=False):
555555
if ".git" in _dirs:
556556
_dirs.remove(".git")
557557
for git_file in git_files:
558-
files.append(os.path.join(root, git_file))
558+
files.append(os.path.join(root, git_file))\
559559
git_options = ["-C", str(git_folder), "-c", "core.quotePath="]
560560
try:
561561
ignored = subprocess.check_output( # nosec # skipcq: PYL-W1510

isort/stdlibs/py27.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"UserString",
4141
"W",
4242
"__builtin__",
43+
"_ast",
4344
"_winreg",
4445
"abc",
4546
"aepack",

isort/stdlibs/py35.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
stdlib = {
9+
"_ast",
910
"_dummy_thread",
1011
"_thread",
1112
"abc",

isort/stdlibs/py36.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
stdlib = {
9+
"_ast",
910
"_dummy_thread",
1011
"_thread",
1112
"abc",

isort/stdlibs/py37.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
stdlib = {
9+
"_ast",
910
"_dummy_thread",
1011
"_thread",
1112
"abc",

isort/stdlibs/py38.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
stdlib = {
9+
"_ast",
910
"_dummy_thread",
1011
"_thread",
1112
"abc",

isort/stdlibs/py39.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
stdlib = {
9+
"_ast",
910
"_thread",
1011
"abc",
1112
"aifc",

isort/wrap_modes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def hanging_indent_with_parentheses(**interface: Any) -> str:
337337
if (
338338
not interface["line_separator"] in interface["statement"]
339339
and "#" in interface["statement"]
340-
):
340+
): # pragma: no cover # TODO: fix, this is because of test run inconsistency.
341341
line, comments = interface["statement"].split("#", 1)
342342
next_statement = (
343343
f"{line.rstrip()}, {next_import}{interface['comment_prefix']}{comments}"

0 commit comments

Comments
 (0)