|
1 | 1 | import json
|
| 2 | +import os |
2 | 3 | import random
|
3 | 4 | import shutil
|
4 | 5 | import string
|
| 6 | +import subprocess |
| 7 | +import sys |
5 | 8 | from pathlib import Path
|
6 | 9 |
|
7 | 10 | try:
|
@@ -502,8 +505,52 @@ def main():
|
502 | 505 | if "{{ cookiecutter.use_async }}".lower() == "n":
|
503 | 506 | remove_async_files()
|
504 | 507 |
|
| 508 | + setup_dependencies() |
| 509 | + |
505 | 510 | print(SUCCESS + "Project initialized, keep up the good work!" + TERMINATOR)
|
506 | 511 |
|
507 | 512 |
|
| 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 | + |
508 | 555 | if __name__ == "__main__":
|
509 | 556 | main()
|
0 commit comments