Skip to content

Commit

Permalink
ENH: remove uv settings if not package manager (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Oct 15, 2024
1 parent 0ff722e commit bb4c15d
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/compwa_policy/check_dev_files/uv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from jinja2 import Environment, FileSystemLoader

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, vscode
from compwa_policy.utilities import COMPWA_POLICY_DIR, CONFIG_PATH, readme, vscode
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.match import git_ls_files, matches_patterns
from compwa_policy.utilities.precommit.struct import Hook, Repo
from compwa_policy.utilities.readme import add_badge
from compwa_policy.utilities.pyproject import ModifiablePyproject, Pyproject

if TYPE_CHECKING:
from compwa_policy.check_dev_files.conda import PackageManagerChoice
Expand All @@ -28,10 +28,10 @@ def main(
precommit_config: ModifiablePrecommit,
repo_name: str,
) -> None:
if "uv" in package_manager:
with Executor() as do:
with Executor() as do:
if "uv" in package_manager:
do(
add_badge,
readme.add_badge,
"[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)",
)
do(_hide_uv_lock_from_vscode_search)
Expand All @@ -53,6 +53,15 @@ def main(
]
},
)
else:
do(_remove_uv_configuration)
do(_remove_uv_lock)
do(precommit_config.remove_hook, "uv-lock")
do(
readme.remove_badge,
r"\[\!\[[^\[]+\]\(https://img\.shields\.io/[^\)]+/uv/main/assets/badge/[^\)]+\)\]\(https://github\.com/astral-sh/uv\)",
)
do(vscode.remove_settings, {"search.exclude": ["uv.lock", "**/uv.lock"]})


def _hide_uv_lock_from_vscode_search() -> None:
Expand All @@ -73,6 +82,26 @@ def _remove_pip_constraint_files() -> None:
raise PrecommitError(msg)


def _remove_uv_configuration() -> None:
readonly_pyproject = Pyproject.load()._document # noqa: SLF001
if "tool" not in readonly_pyproject:
return
if "uv" not in readonly_pyproject["tool"]:
return
with ModifiablePyproject.load() as pyproject:
tool_table = pyproject.get_table("tool")
tool_table.pop("uv")
pyproject.changelog.append("Removed uv configuration from pyproject.toml.")


def _remove_uv_lock() -> None:
uv_lock_path = Path("uv.lock")
if uv_lock_path.exists():
uv_lock_path.unlink()
msg = f"Removed {uv_lock_path} file."
raise PrecommitError(msg)


def _update_editor_config() -> None:
if not CONFIG_PATH.editorconfig.exists():
return
Expand Down

0 comments on commit bb4c15d

Please sign in to comment.