Skip to content

Commit

Permalink
Merge branch 'main' into better-gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 21, 2021
2 parents dd78ecf + 3dc4d89 commit 7be43d0
Show file tree
Hide file tree
Showing 26 changed files with 219 additions and 134 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ Changelog
NOTE: isort follows the [semver](https://semver.org/) versioning standard.
Find out more about isort's release policy [here](https://pycqa.github.io/isort/docs/major_releases/release_policy).

### 5.9.2
### 5.9.3 TBD
- Improved text of skipped file message to mention gitignore feature.
- Fixed #1779: Pylama integration ignores pylama specific isort config overrides.
- Fixed #1781: `--from-first` CLI flag shouldn't take any arguments.
- Fixed #1785: `_ast` module incorrectly excluded from stdlib definition.

### 5.9.2 July 8th 2021
- Improved behavior of `isort --check --atomic` against Cython files.
- Fixed #1769: Future imports added below assignments when no other imports present.
- Fixed #1772: skip-gitignore will check files not in the git repository.
- Fixed #1762: in some cases when skip-gitignore is set, isort fails to skip any files.
- Fixed #1767: Encoding issues surfacing when invalid characters set in `__init__.py` files during placement.
- Fixed #1771: Improved handling of skips against named streamed in content.

### 5.9.1 June 21st 2021 [hotfix]
- Fixed #1758: projects with many files and skip_ignore set can lead to a command-line overload.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ Force all imports to be sorted as a single section

## Force Grid Wrap

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.
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.

**Type:** Int
**Default:** `0`
Expand Down
4 changes: 4 additions & 0 deletions docs/contributing/4.-acknowledgements.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Code Contributors
- Arthur Rio (@arthurio)
- Bob (@bobwalker99)
- Martijn Pieters (@mjpieters)
- Asiel Díaz Benítez (@adbenitez)

Documenters
===================
Expand Down Expand Up @@ -256,6 +257,9 @@ Documenters
- David Poznik (@dpoznik)
- Mike Frysinger (@vapier)
- @DanielFEvans
- Giuseppe Lumia (@glumia)
- John Brock (@JohnHBrock)
- Sergey Fedoseev (@sir-sigurd)

--------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion isort/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "5.9.1"
__version__ = "5.9.2"
10 changes: 6 additions & 4 deletions isort/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def process(
next_import_section: str = ""
next_cimports: bool = False
in_quote: str = ""
was_in_quote: bool = False
first_comment_index_start: int = -1
first_comment_index_end: int = -1
contains_imports: bool = False
Expand Down Expand Up @@ -332,14 +333,15 @@ def process(
and (stripped_line or end_of_file)
and not config.append_only
and not in_top_comment
and not in_quote
and not was_in_quote
and not import_section
and not line.lstrip().startswith(COMMENT_INDICATORS)
and not line.rstrip().endswith(DOCSTRING_INDICATORS)
and not (line.rstrip().endswith(DOCSTRING_INDICATORS) and "=" not in line)
):
import_section = line_separator.join(add_imports) + line_separator
add_line_separator = line_separator or "\n"
import_section = add_line_separator.join(add_imports) + add_line_separator
if end_of_file and index != 0:
output_stream.write(line_separator)
output_stream.write(add_line_separator)
contains_imports = True
add_imports = []

Expand Down
32 changes: 19 additions & 13 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
"--ff",
"--from-first",
dest="from_first",
action="store_true",
help="Switches the typical ordering preference, "
"showing from imports first then straight ones.",
)
Expand All @@ -472,7 +473,7 @@ def _build_arg_parser() -> argparse.ArgumentParser:
const=2,
type=int,
dest="force_grid_wrap",
help="Force number of from imports (defaults to 2 when passed as CLI flag without value)"
help="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.",
)
Expand Down Expand Up @@ -1087,9 +1088,10 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
if show_files:
sys.exit("Error: can't show files for streaming input.")

input_stream = sys.stdin if stdin is None else stdin
if check:
incorrectly_sorted = not api.check_stream(
input_stream=sys.stdin if stdin is None else stdin,
input_stream=input_stream,
config=config,
show_diff=show_diff,
file_path=file_path,
Expand All @@ -1098,15 +1100,18 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =

wrong_sorted_files = incorrectly_sorted
else:
api.sort_stream(
input_stream=sys.stdin if stdin is None else stdin,
output_stream=sys.stdout,
config=config,
show_diff=show_diff,
file_path=file_path,
extension=ext_format,
raise_on_skip=False,
)
try:
api.sort_stream(
input_stream=input_stream,
output_stream=sys.stdout,
config=config,
show_diff=show_diff,
file_path=file_path,
extension=ext_format,
raise_on_skip=False,
)
except FileSkipped:
sys.stdout.write(input_stream.read())
elif "/" in file_names and not allow_root:
printer = create_terminal_printer(
color=config.color_output, error=config.format_error, success=config.format_success
Expand Down Expand Up @@ -1200,8 +1205,9 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
if config.verbose:
for was_skipped in skipped:
print(
f"{was_skipped} was skipped as it's listed in 'skip' setting"
" or matches a glob in 'skip_glob' setting"
f"{was_skipped} was skipped as it's listed in 'skip' setting, "
"matches a glob in 'skip_glob' setting, or is in a .gitignore file with "
"--skip-gitignore enabled."
)
print(f"Skipped {num_skipped} files")

Expand Down
10 changes: 5 additions & 5 deletions isort/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ def _is_namespace_package(path: Path, src_extensions: FrozenSet[str]) -> bool:
if filenames:
return False
else:
with init_file.open() as open_init_file:
with init_file.open("rb") as open_init_file:
file_start = open_init_file.read(4096)
if (
"__import__('pkg_resources').declare_namespace(__name__)" not in file_start
and '__import__("pkg_resources").declare_namespace(__name__)' not in file_start
and "__path__ = __import__('pkgutil').extend_path(__path__, __name__)"
b"__import__('pkg_resources').declare_namespace(__name__)" not in file_start
and b'__import__("pkg_resources").declare_namespace(__name__)' not in file_start
and b"__path__ = __import__('pkgutil').extend_path(__path__, __name__)"
not in file_start
and '__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
and b'__path__ = __import__("pkgutil").extend_path(__path__, __name__)'
not in file_start
):
return False
Expand Down
8 changes: 5 additions & 3 deletions isort/pylama_isort.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
from contextlib import contextmanager
from typing import Any, Dict, Iterator, List
from typing import Any, Dict, Iterator, List, Optional

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

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

def run(self, path: str, **meta: Any) -> List[Dict[str, Any]]:
def run(
self, path: str, params: Optional[Dict[str, Any]] = None, **meta: Any
) -> List[Dict[str, Any]]:
"""Lint the file. Return an array of error dicts if appropriate."""
with supress_stdout():
try:
if not api.check_file(path, disregard_skip=False):
if not api.check_file(path, disregard_skip=False, **params or {}):
return [
{
"lnum": 0,
Expand Down
4 changes: 2 additions & 2 deletions isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,12 @@ def _check_folder_gitignore(self, folder: str) -> Optional[Path]:

files: List[str] = []
# don't check symlinks; either part of the repo and would be checked
# twice, or is external to the repo and git won't konw anything about it
# twice, or is external to the repo and git won't know anything about it
for root, _dirs, git_files in os.walk(git_folder, followlinks=False):
if ".git" in _dirs:
_dirs.remove(".git")
for git_file in git_files:
files.append(os.path.join(root, git_file))
files.append(os.path.join(root, git_file))\
git_options = ["-C", str(git_folder), "-c", "core.quotePath="]
try:
ignored = subprocess.check_output( # nosec # skipcq: PYL-W1510
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py27.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"UserString",
"W",
"__builtin__",
"_ast",
"_winreg",
"abc",
"aepack",
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py35.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

stdlib = {
"_ast",
"_dummy_thread",
"_thread",
"abc",
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py36.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

stdlib = {
"_ast",
"_dummy_thread",
"_thread",
"abc",
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py37.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

stdlib = {
"_ast",
"_dummy_thread",
"_thread",
"abc",
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py38.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

stdlib = {
"_ast",
"_dummy_thread",
"_thread",
"abc",
Expand Down
1 change: 1 addition & 0 deletions isort/stdlibs/py39.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

stdlib = {
"_ast",
"_thread",
"abc",
"aifc",
Expand Down
2 changes: 1 addition & 1 deletion isort/wrap_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def hanging_indent_with_parentheses(**interface: Any) -> str:
if (
not interface["line_separator"] in interface["statement"]
and "#" in interface["statement"]
):
): # pragma: no cover # TODO: fix, this is because of test run inconsistency.
line, comments = interface["statement"].split("#", 1)
next_statement = (
f"{line.rstrip()}, {next_import}{interface['comment_prefix']}{comments}"
Expand Down

0 comments on commit 7be43d0

Please sign in to comment.