Skip to content

Commit bf4c149

Browse files
committed
Use python post gen hook for adding dependencies
1 parent 9dba811 commit bf4c149

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

Diff for: hooks/post_gen_project.py

+47
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import json
2+
import os
23
import random
34
import shutil
45
import string
6+
import subprocess
7+
import sys
58
from pathlib import Path
69

710
try:
@@ -502,8 +505,52 @@ def main():
502505
if "{{ cookiecutter.use_async }}".lower() == "n":
503506
remove_async_files()
504507

508+
setup_dependencies()
509+
505510
print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)
506511

507512

513+
def setup_dependencies():
514+
print("Installing python dependencies using uv...")
515+
516+
if "{{ cookiecutter.use_docker }}".lower() == "y":
517+
# Build the Docker service using Docker Compose
518+
try:
519+
subprocess.run(["docker", "compose", "-f", "docker-compose.local.yml", "build", "django"], check=True)
520+
except subprocess.CalledProcessError as e:
521+
print(f"Error building Docker service: {e}", file=sys.stderr)
522+
sys.exit(1)
523+
524+
# Use Docker to run the uv command
525+
uv_cmd = ["docker", "compose", "-f", "docker-compose.local.yml", "run", "--rm", "django", "uv"]
526+
else:
527+
# Use uv command directly
528+
uv_cmd = ["uv"]
529+
530+
# Install production dependencies
531+
try:
532+
subprocess.run(uv_cmd + ["add", "-r", "requirements/production.txt"], check=True)
533+
except subprocess.CalledProcessError as e:
534+
print(f"Error installing production dependencies: {e}", file=sys.stderr)
535+
sys.exit(1)
536+
537+
# Install local (development) dependencies
538+
try:
539+
subprocess.run(uv_cmd + ["add", "--dev", "-r", "requirements/local.txt"], check=True)
540+
except subprocess.CalledProcessError as e:
541+
print(f"Error installing local dependencies: {e}", file=sys.stderr)
542+
sys.exit(1)
543+
544+
# Remove the requirements directory
545+
if os.path.exists("requirements"):
546+
try:
547+
shutil.rmtree("requirements")
548+
except Exception as e:
549+
print(f"Error removing 'requirements' folder: {e}", file=sys.stderr)
550+
sys.exit(1)
551+
552+
print("Setup complete!")
553+
554+
508555
if __name__ == "__main__":
509556
main()

Diff for: hooks/post_gen_project.sh

-19
This file was deleted.

Diff for: tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ envlist = py312,black-template
44

55
[testenv]
66
passenv = AUTOFIXABLE_STYLES
7-
commands = pytest -n auto {posargs:./tests}
7+
commands = pytest --instafail -n auto {posargs:./tests}
88

99
[testenv:black-template]
1010
deps = black

0 commit comments

Comments
 (0)