Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22462

Python Engineering at Microsoft: Creating Apps from Templates: Cookiecutter in Visual Studio “15”

$
0
0

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 from 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:

 

cc_cmd_blog

 

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.

 

cc_install_blog

 

Upon successful install, the Cookiecutter Explorer tool can be launched from the view menu and the file menu.

 

 

cc_launch_blog

Lo and behold

 

cc_lo_blog

 

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.

 

cc_search_blog

 

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.

 

 

cc_context_blog

 

We have also added support for custom metadata in the json file, so developers can specify descriptions and helpful text to show 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.

 

cc_ttip_blog

 

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.

 

cc_project_blog

 

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.

 

cc_update_blog

 

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…


Viewing all articles
Browse latest Browse all 22462

Trending Articles