mirror of
				https://github.com/cookiecutter/cookiecutter-django.git
				synced 2025-10-31 16:07:49 +03:00 
			
		
		
		
	Fix issues from Ruff in scripts
This commit is contained in:
		
							parent
							
								
									1a81521ae8
								
							
						
					
					
						commit
						f30c3c036c
					
				|  | @ -1,3 +1,5 @@ | |||
| from __future__ import annotations | ||||
| 
 | ||||
| import json | ||||
| from pathlib import Path | ||||
| 
 | ||||
|  | @ -11,9 +13,6 @@ CI_YML = ROOT / ".github" / "workflows" / "ci.yml" | |||
| 
 | ||||
| def main() -> None: | ||||
|     new_version = get_version_from_dockerfile() | ||||
|     if new_version is None: | ||||
|         raise RuntimeError(f"No version found in {DOCKERFILE}") | ||||
| 
 | ||||
|     old_version = get_version_from_package_json() | ||||
|     if old_version != new_version: | ||||
|         update_package_json_version(old_version, new_version) | ||||
|  | @ -21,7 +20,7 @@ def main() -> None: | |||
|         update_production_node_version(old_version, new_version) | ||||
| 
 | ||||
| 
 | ||||
| def get_version_from_dockerfile() -> str | None: | ||||
| def get_version_from_dockerfile() -> str: | ||||
|     # Extract version out of base image name: | ||||
|     # FROM docker.io/node:22.13-bookworm-slim | ||||
|     # -> 22.13 | ||||
|  | @ -31,6 +30,7 @@ def get_version_from_dockerfile() -> str | None: | |||
|                 _, _, docker_tag = line.partition(":") | ||||
|                 version_str, _, _ = docker_tag.partition("-") | ||||
|                 return version_str | ||||
|     raise RuntimeError("Could not find version in Dockerfile") | ||||
| 
 | ||||
| 
 | ||||
| def get_version_from_package_json() -> str: | ||||
|  |  | |||
|  | @ -1,3 +1,5 @@ | |||
| from __future__ import annotations | ||||
| 
 | ||||
| import subprocess | ||||
| import tomllib | ||||
| from pathlib import Path | ||||
|  | @ -9,7 +11,7 @@ PRE_COMMIT_CONFIG = TEMPLATED_ROOT / ".pre-commit-config.yaml" | |||
| PYPROJECT_TOML = ROOT / "pyproject.toml" | ||||
| 
 | ||||
| 
 | ||||
| def main(): | ||||
| def main() -> None: | ||||
|     new_version = get_requirements_txt_version() | ||||
|     old_version = get_pyproject_toml_version() | ||||
|     if old_version == new_version: | ||||
|  | @ -19,22 +21,23 @@ def main(): | |||
|     subprocess.run(["uv", "lock", "--no-upgrade"], cwd=ROOT) | ||||
| 
 | ||||
| 
 | ||||
| def get_requirements_txt_version(): | ||||
| def get_requirements_txt_version() -> str: | ||||
|     content = REQUIREMENTS_LOCAL_TXT.read_text() | ||||
|     for line in content.split("\n"): | ||||
|         if line.startswith("ruff"): | ||||
|             return line.split(" ")[0].split("==")[1] | ||||
|     return None | ||||
|     raise RuntimeError("Could not find ruff version in requirements/local.txt") | ||||
| 
 | ||||
| 
 | ||||
| def get_pyproject_toml_version(): | ||||
| def get_pyproject_toml_version() -> str: | ||||
|     data = tomllib.loads(PYPROJECT_TOML.read_text()) | ||||
|     for dependency in data["project"]["dependencies"]: | ||||
|         if dependency.startswith("ruff=="): | ||||
|             return dependency.split("==")[1] | ||||
|     raise RuntimeError("Could not find ruff version in pyproject.toml") | ||||
| 
 | ||||
| 
 | ||||
| def update_ruff_version(old_version, new_version): | ||||
| def update_ruff_version(old_version: str, new_version: str) -> None: | ||||
|     # Update pyproject.toml | ||||
|     new_content = PYPROJECT_TOML.read_text().replace( | ||||
|         f"ruff=={old_version}", | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user