From 9dd97ada880a3d0b42d3f0616749fe801c12871a Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:01:18 +0100 Subject: [PATCH 1/2] ENH: deactivate Ruff isort `split-on-trailing-comma` --- pyproject.toml | 3 +++ src/compwa_policy/check_dev_files/ruff.py | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5e1a6012..223cb5ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -296,6 +296,9 @@ task-tags = ["cspell"] [tool.ruff.isort] known-first-party = ["compwa_policy"] +[tool.ruff.lint.isort] +split-on-trailing-comma = false + [tool.ruff.per-file-ignores] "docs/*" = [ "E402", diff --git a/src/compwa_policy/check_dev_files/ruff.py b/src/compwa_policy/check_dev_files/ruff.py index f0787172..18e4561f 100644 --- a/src/compwa_policy/check_dev_files/ruff.py +++ b/src/compwa_policy/check_dev_files/ruff.py @@ -53,7 +53,6 @@ def main(has_notebooks: bool) -> None: executor(_remove_pydocstyle) executor(_remove_pylint) executor(_update_ruff_settings, has_notebooks) - executor(_update_ruff_pydocstyle_settings) executor(_update_precommit_hook, has_notebooks) executor(_update_pyproject) executor(_update_vscode_settings) @@ -262,7 +261,9 @@ def __remove_nbqa_settings() -> None: def _update_ruff_settings(has_notebooks: bool) -> None: executor = Executor() executor(__update_ruff_settings, has_notebooks) - executor(_update_ruff_per_file_ignores, has_notebooks) + executor(__update_ruff_per_file_ignores, has_notebooks) + executor(__update_ruff_isort_settings) + executor(__update_ruff_pydocstyle_settings) executor(_remove_nbqa) executor.finalize() @@ -433,7 +434,7 @@ def __get_target_version() -> str: return lowest_version -def _update_ruff_per_file_ignores(has_notebooks: bool) -> None: +def __update_ruff_per_file_ignores(has_notebooks: bool) -> None: pyproject = load_pyproject() settings = get_sub_table(pyproject, "tool.ruff.per-file-ignores", create=True) minimal_settings = {} @@ -503,7 +504,18 @@ def _update_ruff_per_file_ignores(has_notebooks: bool) -> None: raise PrecommitError(msg) -def _update_ruff_pydocstyle_settings() -> None: +def __update_ruff_isort_settings() -> None: + pyproject = load_pyproject() + settings = get_sub_table(pyproject, "tool.ruff.lint.isort", create=True) + minimal_settings = {"split-on-trailing-comma": False} + if not complies_with_subset(settings, minimal_settings): + settings.update(minimal_settings) + write_pyproject(pyproject) + msg = f"Updated Ruff isort settings in {CONFIG_PATH.pyproject}" + raise PrecommitError(msg) + + +def __update_ruff_pydocstyle_settings() -> None: pyproject = load_pyproject() settings = get_sub_table(pyproject, "tool.ruff.pydocstyle", create=True) minimal_settings = { From 73d04e58ad8593a03f21c96be976cea104249292 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:02:05 +0100 Subject: [PATCH 2/2] MAINT: remove redundant line splittings --- src/compwa_policy/check_dev_files/citation.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/compwa_policy/check_dev_files/citation.py b/src/compwa_policy/check_dev_files/citation.py index e520a57a..ffcdeb85 100644 --- a/src/compwa_policy/check_dev_files/citation.py +++ b/src/compwa_policy/check_dev_files/citation.py @@ -10,10 +10,7 @@ from html2text import HTML2Text from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap, CommentedSeq -from ruamel.yaml.scalarstring import ( - FoldedScalarString, - PreservedScalarString, -) +from ruamel.yaml.scalarstring import FoldedScalarString, PreservedScalarString from compwa_policy.errors import PrecommitError from compwa_policy.utilities import CONFIG_PATH, vscode