mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-29 04:54:02 +03:00
Remove uv-pre-commit from pre-commit in post gen hook when heroku is not used
This commit is contained in:
parent
9978e3f35d
commit
c0b26c9118
|
@ -16,6 +16,7 @@ import os
|
|||
import random
|
||||
import shutil
|
||||
import string
|
||||
from pathlib import Path
|
||||
|
||||
try:
|
||||
# Inspired by
|
||||
|
@ -218,21 +219,25 @@ def handle_js_runner(choice, use_docker, use_async):
|
|||
|
||||
|
||||
def remove_prettier_pre_commit():
|
||||
with open(".pre-commit-config.yaml", "r") as fd:
|
||||
content = fd.readlines()
|
||||
remove_repo_from_pre_commit_config("mirrors-prettier")
|
||||
|
||||
|
||||
def remove_repo_from_pre_commit_config(repo_to_remove: str):
|
||||
pre_commit_config = Path(".pre-commit-config.yaml")
|
||||
content = pre_commit_config.read_text().splitlines(True)
|
||||
|
||||
removing = False
|
||||
new_lines = []
|
||||
new_lines = ""
|
||||
|
||||
for line in content:
|
||||
if removing and "- repo:" in line:
|
||||
removing = False
|
||||
if "mirrors-prettier" in line:
|
||||
if repo_to_remove in line:
|
||||
removing = True
|
||||
if not removing:
|
||||
new_lines.append(line)
|
||||
new_lines += line
|
||||
|
||||
with open(".pre-commit-config.yaml", "w") as fd:
|
||||
fd.writelines(new_lines)
|
||||
pre_commit_config.write_text(new_lines)
|
||||
|
||||
|
||||
def remove_celery_files():
|
||||
|
@ -471,6 +476,7 @@ def main():
|
|||
|
||||
if "{{ cookiecutter.use_heroku }}".lower() == "n":
|
||||
remove_heroku_files()
|
||||
remove_repo_from_pre_commit_config("uv-pre-commit")
|
||||
|
||||
if "{{ cookiecutter.use_docker }}".lower() == "n" and "{{ cookiecutter.use_heroku }}".lower() == "n":
|
||||
if "{{ cookiecutter.keep_local_envs_in_vcs }}".lower() == "y":
|
||||
|
|
|
@ -437,3 +437,15 @@ def test_pyproject_toml(cookies, context):
|
|||
assert data["project"]["authors"][0]["email"] == author_email
|
||||
assert data["project"]["authors"][0]["name"] == author_name
|
||||
assert data["project"]["name"] == context["project_slug"]
|
||||
|
||||
|
||||
def test_pre_commit_without_heroku(cookies, context):
|
||||
context.update({"use_heroku": "n"})
|
||||
result = cookies.bake(extra_context=context)
|
||||
assert result.exit_code == 0
|
||||
|
||||
pre_commit_config = result.project_path / ".pre-commit-config.yaml"
|
||||
|
||||
data = pre_commit_config.read_text()
|
||||
|
||||
assert "uv-pre-commit" not in data
|
||||
|
|
|
@ -48,14 +48,14 @@ repos:
|
|||
hooks:
|
||||
- id: djlint-reformat-django
|
||||
- id: djlint-django
|
||||
{%- if cookiecutter.use_heroku == "y" %}
|
||||
|
||||
- repo: https://github.com/astral-sh/uv-pre-commit
|
||||
# uv version.
|
||||
rev: 0.4.15
|
||||
hooks:
|
||||
- id: uv-export
|
||||
args: ['--frozen', '--no-dev']
|
||||
{%- endif -%}
|
||||
|
||||
# sets up .pre-commit-ci.yaml to ensure pre-commit dependencies stay up to date
|
||||
ci:
|
||||
autoupdate_schedule: weekly
|
||||
|
|
Loading…
Reference in New Issue
Block a user