从项目模板创建项目的命令行实用程序,例如从python包项目模板创建python包项目。
cookiecutter的Python项目详细描述
功能
有人说特征吗?
跨平台:官方支持Windows、Mac和Linux。
与python 2.7、3.3、3.4、3.5、3.6和pypy一起使用。 (但你不必 知道/编写python代码以使用cookiecutter。)
项目模板可以是任何编程语言或标记格式: python,javascript,ruby,coffeescript,rst,markdown,css,html,你的名字 它。您可以在同一个项目模板中使用多种语言。
简单的命令行用法:
< Buff行情># Create project from the cookiecutter-pypackage.git repo template # You'll be prompted to enter values. # Then it'll create your Python package in the current working directory, # based on those values. $ cookiecutter https://github.com/audreyr/cookiecutter-pypackage # For the sake of brevity, repos on GitHub can just use the 'gh' prefix $ cookiecutter gh:audreyr/cookiecutter-pypackage
在命令行中与本地模板一起使用:
< Buff行情># Create project in the current working directory, from the local # cookiecutter-pypackage/ template $ cookiecutter cookiecutter-pypackage/
或者从python中使用:
< Buff行情>fromcookiecutter.mainimportcookiecutter# Create project from the cookiecutter-pypackage/ templatecookiecutter('cookiecutter-pypackage/')# Create project from the cookiecutter-pypackage.git repo templatecookiecutter('https://github.com/audreyr/cookiecutter-pypackage.git')
目录名和文件名可以模板化。例如:
{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}/{{cookiecutter.repo_name}}.py
支持无限级别的目录嵌套。
100%的模板制作是用Jinja2完成的。这包括文件名和目录名。
只需在一个 cookiecutter.json 文件中定义模板变量。例如:
< Buff行情>{"full_name":"Audrey Roy","email":"audreyr@gmail.com","project_name":"Complexity","repo_name":"complexity","project_short_description":"Refreshingly simple static site generator.","release_date":"2013-07-10","year":"2013","version":"0.1.1"}
除非用 --无输入来抑制它,否则系统会提示您输入:
- 提示是cookiecutter.json中的键。
- 默认响应是 cookiecutter.json 中的值。
- 提示按顺序显示。
跨平台支持 ~/.cookiecutterc 文件:
< Buff行情>default_context:full_name:"AudreyRoy"email:"audreyr@gmail.com"github_username:"audreyr"cookiecutters_dir:"~/.cookiecutters/"
cookiecutter(克隆的cookiecutter项目模板)被放入 ~/.cookiecutters/ 默认情况下,或指定的cookiecutters目录。
如果您已经将Cookiecutter克隆到了 可以按目录名引用:
< Buff行情># Clone cookiecutter-pypackage $ cookiecutter gh:audreyr/cookiecutter-pypackage # Now you can use the already cloned cookiecutter by name $ cookiecutter cookiecutter-pypackage
您可以使用本地CookieCutter,或者直接从Git使用远程CookieCutter 回购协议或Bitbucket上的Mercurial回购协议。
默认上下文:指定要用作默认值的键/值对 每当生成项目时
使用命令行参数插入额外的上下文:
< Buff行情>$ cookiecutter --no-input gh:msabramo/cookiecutter-supervisor program_name=foobar startsecs=10
直接访问CookiCutter API允许注入额外的上下文。
生成前和生成后钩子:在之前或之后运行的python或shell脚本 生成项目。
本地项目的路径可以指定为绝对路径或相对路径。
项目总是生成到当前目录。