Skip to content

Commit

Permalink
Make Pylint and Flake8 happy
Browse files Browse the repository at this point in the history
(only for regions we touched in this branch)
  • Loading branch information
akaihola committed Aug 6, 2020
1 parent e775077 commit d32c5c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def format_edited_parts(
srcs: Iterable[Path],
isort: bool,
enable_isort: bool,
black_args: BlackArgs,
print_diff: bool,
check_only: bool,
Expand All @@ -43,7 +43,7 @@ def format_edited_parts(
10. write the reformatted source back to the original file
:param srcs: Directories and files to re-format
:param isort: ``True`` to also run ``isort`` first on each changed file
:param enable_isort: ``True`` to also run ``isort`` first on each changed file
:param black_args: Command-line arguments to send to ``black.FileMode``
:param print_diff: ``True`` to output diffs instead of modifying source files
:param check_only: ``True`` to not modify files but return a boolean stating whether
Expand All @@ -62,7 +62,7 @@ def format_edited_parts(
worktree_content = src.read_text()

# 1. run isort
if isort:
if enable_isort:
edited_content = apply_isort(
worktree_content,
src,
Expand All @@ -79,7 +79,11 @@ def format_edited_parts(
edited_linenums = edited_linenums_differ.head_vs_lines(
path_in_repo, edited_lines, context_lines
)
if isort and not edited_linenums and edited_content == worktree_content:
if (
enable_isort
and not edited_linenums
and edited_content == worktree_content
):
logger.debug("No changes in %s after isort", src)
break

Expand Down Expand Up @@ -190,5 +194,5 @@ def main(argv: List[str] = None) -> int:


if __name__ == "__main__":
retval = main()
sys.exit(retval)
RETVAL = main()
sys.exit(RETVAL)
7 changes: 4 additions & 3 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_format_edited_parts_empty():


@pytest.mark.parametrize(
'isort, black_args, print_diff, expect_stdout, expect_a_py',
'enable_isort, black_args, print_diff, expect_stdout, expect_a_py',
[
(False, {}, True, A_PY_DIFF_BLACK, A_PY),
(True, {}, False, [''], A_PY_BLACK_ISORT,),
Expand All @@ -125,7 +125,7 @@ def test_format_edited_parts(
git_repo,
monkeypatch,
capsys,
isort,
enable_isort,
black_args,
print_diff,
expect_stdout,
Expand All @@ -137,7 +137,7 @@ def test_format_edited_parts(
paths['b.py'].write('print(42 )\n')

all_unchanged = darker.__main__.format_edited_parts(
[Path('a.py')], isort, black_args, print_diff, False
[Path('a.py')], enable_isort, black_args, print_diff, False
)

stdout = capsys.readouterr().out.replace(str(git_repo.root), '')
Expand All @@ -148,6 +148,7 @@ def test_format_edited_parts(


def test_format_edited_parts_all_unchanged(git_repo, monkeypatch):
"""``format_edited_parts()`` returns ``True`` if no reformatting was needed"""
monkeypatch.chdir(git_repo.root)
paths = git_repo.add({'a.py': 'pass\n', 'b.py': 'pass\n'}, commit='Initial commit')
paths['a.py'].write('"properly"\n"formatted"\n')
Expand Down
2 changes: 2 additions & 0 deletions src/darker/version.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
"""The version number for Darker is governed by this file"""

__version__ = "1.1.0.dev"

0 comments on commit d32c5c9

Please sign in to comment.