-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlint-from-demo.py
More file actions
63 lines (51 loc) · 1.82 KB
/
lint-from-demo.py
File metadata and controls
63 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "cookiecutter",
# "cruft",
# "python-dotenv",
# "retrocookie",
# "typer",
# ]
# ///
import os
from pathlib import Path
from typing import Annotated
import pre_commit.main
import typer
from retrocookie.core import retrocookie
from util import DEMO
from util import git
from util import FolderOption
from util import in_new_demo
from util import require_clean_and_up_to_date_demo_repo
# These still may need linted, but retrocookie shouldn't be used on them
IGNORED_FILES: list[str] = [
"pyproject.toml",
"uv.lock",
]
cli: typer.Typer = typer.Typer()
@cli.callback(invoke_without_command=True)
def lint_from_demo(
demos_cache_folder: Annotated[Path, FolderOption("--demos-cache-folder", "-c")],
add_rust_extension: Annotated[bool, typer.Option("--add-rust-extension", "-r")] = False,
no_cache: Annotated[bool, typer.Option("--no-cache", "-n")] = False
) -> None:
"""Runs precommit in a generated project and matches the template to the results."""
with in_new_demo(
demos_cache_folder=demos_cache_folder,
add_rust_extension=add_rust_extension,
no_cache=no_cache
) as demo_path:
require_clean_and_up_to_date_demo_repo(demo_path=demo_path)
git("checkout", DEMO.develop_branch)
git("branch", "-D", "temp/lint-from-demo", ignore_error=True)
git("checkout", "-b", "temp/lint-from-demo", DEMO.develop_branch)
pre_commit.main.main(["run", "--all-files", "--show-diff-on-failure"])
for path in IGNORED_FILES:
git("checkout", "HEAD", "--", path)
git("add", ".")
git("commit", "-m", "meta: lint-from-demo", "--no-verify")
retrocookie(instance_path=demo_path, commits=[f"{DEMO.develop_branch}..temp/lint-from-demo"])
if __name__ == '__main__':
cli()