Skip to content

Commit

Permalink
ENH: remove target-version from black and ruff config (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Sep 5, 2024
1 parent ca21862 commit 975aa98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ src = [
"src",
"tests",
]
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true
Expand Down
21 changes: 15 additions & 6 deletions src/compwa_policy/check_dev_files/black.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Update :file:`pyproject.toml` black configuration."""

from typing import Any

from ruamel.yaml import YAML

from compwa_policy.utilities import CONFIG_PATH, vscode
Expand Down Expand Up @@ -59,12 +61,19 @@ def _remove_outdated_settings(pyproject: ModifiablePyproject) -> None:

def _update_black_settings(pyproject: ModifiablePyproject) -> None:
settings = pyproject.get_table("tool.black", create=True)
versions = pyproject.get_supported_python_versions()
target_version = to_toml_array(sorted("py" + v.replace(".", "") for v in versions))
minimal_settings = {
"preview": True,
"target-version": target_version,
}
minimal_settings: dict[str, Any] = {"preview": True}
project_root = pyproject.get_table("project", create=True)
if "requires-python" in project_root:
if settings.get("target-version") is not None:
settings.pop("target-version")
msg = "Removed target-version from black configuration"
pyproject.changelog.append(msg)
else:
versions = pyproject.get_supported_python_versions()
target_version = to_toml_array(
sorted("py" + v.replace(".", "") for v in versions)
)
minimal_settings["target-version"] = target_version
if not complies_with_subset(settings, minimal_settings):
settings.update(minimal_settings)
msg = "Updated black configuration"
Expand Down
11 changes: 9 additions & 2 deletions src/compwa_policy/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,18 @@ def __update_global_settings(
pyproject: ModifiablePyproject, has_notebooks: bool
) -> None:
settings = pyproject.get_table("tool.ruff", create=True)
minimal_settings = {
minimal_settings: dict[str, Any] = {
"preview": True,
"show-fixes": True,
"target-version": ___get_target_version(pyproject),
}
project = pyproject.get_table("project", create=True)
if "requires-python" in project:
if settings.get("target-version") is not None:
settings.pop("target-version")
msg = "Removed target-version from Ruff configuration"
pyproject.changelog.append(msg)
else:
minimal_settings["target-version"] = ___get_target_version(pyproject)
if has_notebooks:
key = "extend-include"
default_includes = sorted({
Expand Down

0 comments on commit 975aa98

Please sign in to comment.