Skip to content

Commit

Permalink
ENH: make isort compatible with Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Sep 23, 2024
1 parent d75cc7b commit f66d056
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/compwa_policy/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main(
do(_remove_pylint, precommit, pyproject)
do(_move_ruff_lint_config, pyproject)
if has_notebooks and imports_on_top:
do(_sort_imports_on_top, precommit)
do(_sort_imports_on_top, precommit, pyproject)
do(_update_ruff_config, precommit, pyproject, has_notebooks)
do(_update_precommit_hook, precommit, has_notebooks)
do(_update_lint_dependencies, pyproject)
Expand Down Expand Up @@ -582,7 +582,25 @@ def _update_precommit_hook(precommit: ModifiablePrecommit, has_notebooks: bool)
precommit.update_single_hook_repo(expected_repo)


def _sort_imports_on_top(precommit: ModifiablePrecommit) -> None:
def _sort_imports_on_top(
precommit: ModifiablePrecommit, pyproject: ModifiablePyproject
) -> None:
__add_isort_configuration(pyproject)
__add_nbqa_isort_pre_commit(precommit)


def __add_isort_configuration(pyproject: ModifiablePyproject) -> None:
isort_settings = pyproject.get_table("tool.isort", create=True)
minimal_settings = dict(
profile="black",
)
if not complies_with_subset(isort_settings, minimal_settings):
isort_settings.update(minimal_settings)
msg = "Made isort configuration compatible with Ruff"
pyproject.changelog.append(msg)


def __add_nbqa_isort_pre_commit(precommit: ModifiablePrecommit) -> None:
existing_repo = precommit.find_repo("https://github.com/nbQA-dev/nbQA")
excludes = None
if existing_repo is not None and existing_repo.get("hooks"):
Expand Down

0 comments on commit f66d056

Please sign in to comment.