Skip to content

Commit 7ddec49

Browse files
committed
Add isort to ramble style check
1 parent f80af90 commit 7ddec49

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/ramble/ramble/cmd/style.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@
1414
import sys
1515
import tempfile
1616

17-
from llnl.util.filesystem import working_dir, mkdirp
17+
from llnl.util.filesystem import mkdirp, working_dir
18+
from spack.util.executable import ProcessError, which
1819

1920
import ramble.paths
20-
from spack.util.executable import which, ProcessError
21-
2221

2322
description = "runs source code style checks on Ramble."
2423
section = "developer"
@@ -119,7 +118,7 @@ def is_object(f):
119118
}
120119

121120
# Tools run in the given order, with flake8 as the last check.
122-
tool_names = ["black", "flake8"]
121+
tool_names = ["isort", "black", "flake8"]
123122

124123
tools = {}
125124

@@ -473,6 +472,20 @@ def run_black(black_cmd, file_list, args):
473472
return returncode
474473

475474

475+
@tool("isort")
476+
def run_isort(isort_cmd, file_list, args):
477+
isort_args = ("--sp", os.path.join(ramble.paths.prefix, "pyproject.toml"))
478+
if not args.fix:
479+
isort_args += ("--check", "--diff")
480+
output = isort_cmd(
481+
*(isort_args + tuple(file_list)), fail_on_error=False, output=str, error=str
482+
)
483+
returncode = isort_cmd.returncode
484+
print_output(output, args)
485+
print_tool_result("isort", returncode)
486+
return returncode
487+
488+
476489
def validate_toolset(arg_value):
477490
"""Validate --tool and --skip arguments (sets of optionally comma-separated tools)."""
478491
tools = set(",".join(arg_value).split(",")) # allow args like 'black,flake8'

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ force-exclude = '''
1717
)/
1818
'''
1919

20+
[tool.isort]
21+
line_length = 99
22+
profile = "black"
23+
filter_files = true
24+
skip_glob = [
25+
"**/lib/ramble/external/**",
26+
"**/lib/ramble/llnl/**",
27+
"**/lib/ramble/spack/**",
28+
]
29+
2030
[tool.coverage.run]
2131
parallel = true
2232
data_file = "./tests-coverage/.coverage"

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ pre-commit
77
pytest-xdist
88
pytest-cov
99
line_profiler
10+
isort

0 commit comments

Comments
 (0)