Skip to content

Commit

Permalink
FIX: only update pyright settings if tool.pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 9, 2023
1 parent eb80d4d commit 43feb8f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/repoma/check_dev_files/pyright.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Check and update :code:`mypy` settings."""
import json
import os
from typing import TYPE_CHECKING, Optional

from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH
Expand All @@ -13,6 +14,9 @@
write_pyproject,
)

if TYPE_CHECKING:
from tomlkit.items import Table

Check warning on line 18 in src/repoma/check_dev_files/pyright.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pyright.py#L18

Added line #L18 was not covered by tests


def main() -> None:
executor = Executor()
Expand Down Expand Up @@ -41,12 +45,14 @@ def _merge_config_into_pyproject() -> None:

def _update_settings() -> None:
pyproject = load_pyproject()
settings = get_sub_table(pyproject, "tool.pyright", create=True)
pyright_settings: Optional[Table] = pyproject.get("tool", {}).get("pyright")

Check warning on line 48 in src/repoma/check_dev_files/pyright.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pyright.py#L48

Added line #L48 was not covered by tests
if pyright_settings is None:
return

Check warning on line 50 in src/repoma/check_dev_files/pyright.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pyright.py#L50

Added line #L50 was not covered by tests
minimal_settings = {
"typeCheckingMode": "strict",
}
if not complies_with_subset(settings, minimal_settings):
settings.update(minimal_settings)
if not complies_with_subset(pyright_settings, minimal_settings):
pyright_settings.update(minimal_settings)

Check warning on line 55 in src/repoma/check_dev_files/pyright.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/pyright.py#L55

Added line #L55 was not covered by tests
write_pyproject(pyproject)
msg = f"Updated pyright configuration in {CONFIG_PATH.pyproject}"
raise PrecommitError(msg)

0 comments on commit 43feb8f

Please sign in to comment.