From 7f7e7d9242735eb09aedeeb4f500d35ccd347d61 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:16:24 +0100 Subject: [PATCH] ENH: set line-length on one line --- src/repoma/check_dev_files/black.py | 5 +++-- src/repoma/check_dev_files/pyupgrade.py | 14 ++++++++------ src/repoma/check_dev_files/toml.py | 3 ++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/repoma/check_dev_files/black.py b/src/repoma/check_dev_files/black.py index c3c157ee..ca5e6557 100644 --- a/src/repoma/check_dev_files/black.py +++ b/src/repoma/check_dev_files/black.py @@ -1,5 +1,6 @@ """Update :file:`pyproject.toml` black configuration.""" +from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap from repoma.errors import PrecommitError @@ -97,8 +98,8 @@ def _update_precommit_repo(has_notebooks: bool) -> None: if has_notebooks: black_jupyter = CommentedMap( id="black-jupyter", - args=["--line-length=85"], - types_or=["jupyter"], + args=YAML(typ="rt").load("[--line-length=85]"), + types_or=YAML(typ="rt").load("[jupyter]"), ) expected_hook["hooks"].append(black_jupyter) update_single_hook_precommit_repo(expected_hook) diff --git a/src/repoma/check_dev_files/pyupgrade.py b/src/repoma/check_dev_files/pyupgrade.py index 0499d269..df4b9d2d 100644 --- a/src/repoma/check_dev_files/pyupgrade.py +++ b/src/repoma/check_dev_files/pyupgrade.py @@ -1,6 +1,7 @@ """Install `pyupgrade `_ as a hook.""" -from ruamel.yaml.comments import CommentedMap +from ruamel.yaml import YAML +from ruamel.yaml.comments import CommentedMap, CommentedSeq from repoma.utilities import natural_sorting from repoma.utilities.executor import Executor @@ -24,7 +25,7 @@ def _update_precommit_repo() -> None: hooks=[ CommentedMap( id="pyupgrade", - args=[__get_pyupgrade_version_argument()], + args=__get_pyupgrade_version_argument(), ) ], ) @@ -36,20 +37,21 @@ def _update_precommit_nbqa_hook() -> None: repo_url="https://github.com/nbQA-dev/nbQA", expected_hook=CommentedMap( id="nbqa-pyupgrade", - args=[__get_pyupgrade_version_argument()], + args=__get_pyupgrade_version_argument(), ), ) -def __get_pyupgrade_version_argument() -> str: +def __get_pyupgrade_version_argument() -> CommentedSeq: """Get the --py3x-plus argument for pyupgrade. >>> __get_pyupgrade_version_argument() - '--py36-plus' + ['--py36-plus'] """ supported_python_versions = sorted( (v.replace(".", "") for v in get_supported_python_versions()), key=natural_sorting, ) lowest_version = supported_python_versions[0] - return f"--py{lowest_version}-plus" + yaml = YAML(typ="rt") + return yaml.load(f"[--py{lowest_version}-plus]") diff --git a/src/repoma/check_dev_files/toml.py b/src/repoma/check_dev_files/toml.py index 44ef193f..de482c14 100644 --- a/src/repoma/check_dev_files/toml.py +++ b/src/repoma/check_dev_files/toml.py @@ -7,6 +7,7 @@ from typing import List, Union import tomlkit +from ruamel.yaml import YAML from ruamel.yaml.comments import CommentedMap from repoma.errors import PrecommitError @@ -73,7 +74,7 @@ def _update_tomlsort_config() -> None: def _update_tomlsort_hook() -> None: expected_hook = CommentedMap( repo="https://github.com/pappasam/toml-sort", - hooks=[CommentedMap(id="toml-sort", args=["--in-place"])], + hooks=[CommentedMap(id="toml-sort", args=YAML(typ="rt").load("[--in-place]"))], ) excludes = [] if glob("labels/*.toml"):