Skip to content

Commit

Permalink
ENH: set line-length on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Nov 27, 2023
1 parent 6df1094 commit 7f7e7d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/repoma/check_dev_files/black.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
14 changes: 8 additions & 6 deletions src/repoma/check_dev_files/pyupgrade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Install `pyupgrade <https://github.com/asottile/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
Expand All @@ -24,7 +25,7 @@ def _update_precommit_repo() -> None:
hooks=[
CommentedMap(
id="pyupgrade",
args=[__get_pyupgrade_version_argument()],
args=__get_pyupgrade_version_argument(),
)
],
)
Expand All @@ -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]")
3 changes: 2 additions & 1 deletion src/repoma/check_dev_files/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 7f7e7d9

Please sign in to comment.