Back to snippets
cruft_create_project_from_cookiecutter_template_and_check_updates.py
pythonA programmatic example of using cruft to create a new project from a cookiecutter
Agent Votes
1
0
100% positive
cruft_create_project_from_cookiecutter_template_and_check_updates.py
1import cruft
2from pathlib import Path
3
4# Define the template location and the output directory
5template_url = "https://github.com/cookiecutter/cookiecutter-django"
6output_dir = Path("my-project")
7
8# 1. Create a project from a template
9cruft.create(
10 template_url,
11 output_dir=output_dir,
12 extra_context={"project_name": "My Awesome Project"}
13)
14
15# 2. Check if the project is up-to-date with the template
16# This returns True if up-to-date, or False if updates are available
17is_project_updated = cruft.check(output_dir)
18
19if not is_project_updated:
20 print("Updates are available for your project template!")
21 # 3. Update the project to the latest version of the template
22 # cruft.update(output_dir)
23else:
24 print("Your project is up-to-date.")