Skip to content

Commit

Permalink
Upgrade default isort from 4.6 to 5.5 (pantsbuild#10737)
Browse files Browse the repository at this point in the history
Closes pantsbuild#10727.

We originally reverted this in pantsbuild#10460 due to flakiness in the sorting algorithm, but I can't reproduce this. Toolchain has also been using isort 5.x for the past month without any reported issues. Possibly, isort fixed the issue in between 5.0.0 and 5.5.1

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano authored Sep 4, 2020
1 parent fbf17ae commit e637ab4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 52 deletions.
13 changes: 0 additions & 13 deletions .isort.cfg

This file was deleted.

5 changes: 0 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ files(
sources = ['.gitignore'],
)

files(
name = 'isort_cfg',
sources = ['.isort.cfg'],
)

files(
name = 'pants_toml',
sources = ['pants.toml'],
Expand Down
12 changes: 2 additions & 10 deletions examples/.isort.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
# See the menu of settings available here:
# https://github.com/timothycrosley/isort/wiki/isort-Settings

[settings]
profile=black
line_length=100
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True

color_output = true
known_first_party=example
default_section=THIRDPARTY
not_skip=__init__.py
3 changes: 2 additions & 1 deletion pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ extra_requirements.add = [
]

[isort]
config = [".isort.cfg", "examples/.isort.cfg"]
version = "isort[pyproject,colors]>=5.5.1,<5.6"
config = ["pyproject.toml", "examples/.isort.cfg"]

[mypy]
config = "build-support/mypy/mypy.ini"
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ exclude = '''
| compilation_failure
)/
'''


[tool.isort]
profile = "black"
line_length = 100
color_output = true
known_first_party = ["internal_plugins", "pants", "pants_test"]
1 change: 0 additions & 1 deletion src/python/pants/backend/python/goals/coverage_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
from pants.option.custom_types import file_option
from pants.util.logging import LogLevel


"""
An overview:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_passing_source(rule_runner: RuleRunner) -> None:
lint_results, fmt_result = run_isort(rule_runner, [target])
assert len(lint_results) == 1
assert lint_results[0].exit_code == 0
assert lint_results[0].stdout == ""
assert lint_results[0].stderr == ""
assert fmt_result.stdout == ""
assert fmt_result.output == get_digest(rule_runner, [GOOD_SOURCE])
assert fmt_result.did_change is False
Expand All @@ -108,9 +108,8 @@ def test_failing_source(rule_runner: RuleRunner) -> None:
lint_results, fmt_result = run_isort(rule_runner, [target])
assert len(lint_results) == 1
assert lint_results[0].exit_code == 1
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stdout
assert "Fixing" in fmt_result.stdout
assert "bad.py" in fmt_result.stdout
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stderr
assert fmt_result.stdout == "Fixing bad.py\n"
assert fmt_result.output == get_digest(rule_runner, [FIXED_BAD_SOURCE])
assert fmt_result.did_change is True

Expand All @@ -120,10 +119,9 @@ def test_mixed_sources(rule_runner: RuleRunner) -> None:
lint_results, fmt_result = run_isort(rule_runner, [target])
assert len(lint_results) == 1
assert lint_results[0].exit_code == 1
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stdout
assert "good.py" not in lint_results[0].stdout
assert "Fixing" in fmt_result.stdout and "bad.py" in fmt_result.stdout
assert "good.py" not in fmt_result.stdout
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stderr
assert "good.py" not in lint_results[0].stderr
assert fmt_result.stdout == "Fixing bad.py\n"
assert fmt_result.output == get_digest(rule_runner, [GOOD_SOURCE, FIXED_BAD_SOURCE])
assert fmt_result.did_change is True

Expand All @@ -136,10 +134,9 @@ def test_multiple_targets(rule_runner: RuleRunner) -> None:
lint_results, fmt_result = run_isort(rule_runner, targets)
assert len(lint_results) == 1
assert lint_results[0].exit_code == 1
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stdout
assert "good.py" not in lint_results[0].stdout
assert "Fixing" in fmt_result.stdout and "bad.py" in fmt_result.stdout
assert "good.py" not in fmt_result.stdout
assert "bad.py Imports are incorrectly sorted" in lint_results[0].stderr
assert "good.py" not in lint_results[0].stderr
assert "Fixing bad.py\n" == fmt_result.stdout
assert fmt_result.output == get_digest(rule_runner, [GOOD_SOURCE, FIXED_BAD_SOURCE])
assert fmt_result.did_change is True

Expand All @@ -151,9 +148,8 @@ def test_respects_config_file(rule_runner: RuleRunner) -> None:
)
assert len(lint_results) == 1
assert lint_results[0].exit_code == 1
assert "config.py Imports are incorrectly sorted" in lint_results[0].stdout
assert "Fixing" in fmt_result.stdout
assert "config.py" in fmt_result.stdout
assert "config.py Imports are incorrectly sorted" in lint_results[0].stderr
assert fmt_result.stdout == "Fixing needs_config.py\n"
assert fmt_result.output == get_digest(rule_runner, [FIXED_NEEDS_CONFIG_SOURCE])
assert fmt_result.did_change is True

Expand All @@ -163,9 +159,8 @@ def test_respects_passthrough_args(rule_runner: RuleRunner) -> None:
lint_results, fmt_result = run_isort(rule_runner, [target], passthrough_args="--combine-as")
assert len(lint_results) == 1
assert lint_results[0].exit_code == 1
assert "config.py Imports are incorrectly sorted" in lint_results[0].stdout
assert "Fixing" in fmt_result.stdout
assert "config.py" in fmt_result.stdout
assert "config.py Imports are incorrectly sorted" in lint_results[0].stderr
assert fmt_result.stdout == "Fixing needs_config.py\n"
assert fmt_result.output == get_digest(rule_runner, [FIXED_NEEDS_CONFIG_SOURCE])
assert fmt_result.did_change is True

Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/backend/python/lint/isort/subsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class Isort(PythonToolBase):
"""The Python import sorter tool (https://timothycrosley.github.io/isort/)."""

options_scope = "isort"
default_version = "isort>=4.3.21,<4.4"
default_extra_requirements = ["setuptools<45"] # NB: `<45` is for Python 2 support
default_version = "isort[pyproject]>=5.5.1,<5.6"
default_extra_requirements = ["setuptools"]
default_interpreter_constraints = ["CPython>=3.6"]
default_entry_point = "isort.main"

@classmethod
Expand Down
1 change: 0 additions & 1 deletion src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ python_binary(
'//:build_root',
'//:pants_toml',
'//:3rdparty_directory',
'//:isort_cfg',
'//:pyproject',
'build-support/flake8',
'build-support/mypy',
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/goals/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python_integration_tests(
uses_pants_run=True,
dependencies=[
'examples/src/python/example:hello_directory',
'//:isort_cfg',
'//:pyproject',
'examples:isort_cfg',
],
timeout=240,
Expand Down

0 comments on commit e637ab4

Please sign in to comment.