Cookiecutter is a popular Open Source templating engine that lets experts easily create highly customizable templates to help other users get started on a project. We have brought it to Visual Studio to reduce the time and effort it takes to stand-up apps, prototype experiences that integrate different services, or try out new frameworks. Now users can search, install, and generate projects from Cookiecutter templates within Visual Studio using the Cookiecutter Explorer tool. In this blog post, we will go through the flow of creating an Azure Web App project from its Cookiecutter template using this tool. As we go through the flow, we will talk about the underlying design rationale.
Our experience closely follows the flow of the command line utility developers are familiar with. Here’s a glimpse of the command line experience today:
Getting started with Cookiecutter in VS 15
To get Cookiecutter Explorer, we’ll need to install Python tools. In the new Visual Studio “15” workload installer, select the “Data science and analytics applications” or the “Python development tools” workload. “Cookiecutter template support” will be checked by default. To learn more about workloads check out Steve’s post for Visual Studio “15” Preview 5.
Upon successful install, the Cookiecutter Explorer tool can be launched from the view menu and the file menu.
Lo and behold
The Explorer’s search feature searches Github for template repositories and will catch any with the “cookiecutter-foo” or “bar-cookiecutter” name formats, including yours if you have one out there. For our “Azure” query, the search returns a few results from Github, suggests Azure related templates, and also searches within the installed templates.
Adding Context
Let’s make a project from the Azure Web App template. Choosing the template, and hitting next clones the repository and takes us to a form where we can enter values for template variables specified in the template’s cookiecutter.json file. We can also choose the location where we would like the project folder to be created. For our Azure Web App project, we specify our desired Python version and CPU architecture.
We have also added support for custom metadata in the json file, so developers can specify descriptions and helpful text that shows up in tooltips. We felt this would allow users to avoid syntactical errors while filling in the context. We are thinking of ways to improve error reporting with in the tool UI instead of having the user go through the console output to get error information.
Hit create to generate project files. Once generated, we can choose to open it in the Solution Explorer. Here’s our newly created Web App project open in it. The tool populated the values in the azuredeploy.json, such that the project is targeting a python352x63 package as specified. Template developers can expose variety of variables ranging from location of config files to environment variables and database connection strings.
Updating Templates
The tool checks for updates every time it is launched or a new Visual Studio session is started. Templates with updates available give a cue with a blue and white arrow in their icon. Users can also check for updates for their installed templates anytime by right clicking on a template and choosing the option in the context menu.
Takeaways
We hope you like our take on adapting Cookiecutter to Visual Studio. If you’re thinking about telling a friend or tweeting, here’s the crux for your convenience:
- Cookiecutter Explorer lets users search for templates on Github, install them, and generate projects from them from entirely within Visual Studio.
- Template developers can additional metadata to show up in tooltips.
- Users can update installed templates with two clicks.
Get Involved!
Got a template idea? Cookiecutter Explorer offers developers an outlet to get their templates and work discovered. If it’s on Github, our search will find it! Over the next few months we will be working with internal partners to develop integrated templates that can help cloud developers use a mix of database, streaming, and compute services to make apps for a whole range of scenarios from data analytics to IoT. Check out this documentation on how you can make your own Cookiecutter template.
Got a tooling idea? We are continuously brainstorming new functionality for the tool to make template-driven Python development a breeze in Visual Studio. We’re excited to see where this goes, and we’d love to hear your ideas and feedback. Please let us know by filling an issue on Github. Hope to carry on this conversation over there…
0 comments