gpt4 book ai didi

cookiecutter - 曲奇刀 : what's the easiest way to specify variables for the prompts

转载 作者:行者123 更新时间:2023-12-04 16:27:32 27 4
gpt4 key购买 nike

通过指向预定义的提示-答案文件,是否有任何提供重播类型功能的东西?
什么有效,我想实现什么。
举个例子,用cookiecutter为pypi准备一个Python包cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

You've downloaded /Users/jluc/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]:
full_name [Audrey Roy Greenfeld]: Spartacus 👈 constant for me/my organization
email [audreyr@example.com]: spartacus@example.com 👈 constant for me/my organization
...
project_name [Python Boilerplate]: GladiatorRevolt 👈 this will vary.
project_slug [q]: gladiator-revolt 👈 this too
...
OK完成。
现在,对于这个项目,我可以通过以下方式轻松重做: cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --replay这很棒!
我想要的是:
假设我创建了另一个项目, 释放 hell .
我想以某种方式准备一个包含我的开发人员信息的文件 Unleash 的项目级别信息。而且我希望能够针对这个模板多次运行它,而不必处理提示。这个特殊的 pypi 模板会定期更新,例如 Python 2.7 支持已被删除。
问题:
A --replay将只为这个 cookiecutter 模板注入(inject)最后一次运行。如果它是针对不同的 pypi 项目运行的,那就太糟糕了。
我很擅长开发人员级别的信息,但我需要更改所有项目级别的信息。
我尝试通过以下方式复制重播文件: cp ~/.cookiecutter_replay/cookiecutter-pypackage.json unleash.json编辑 unleash.json以反射(reflect)必要的变化。
然后通过 --config-file 指定它旗帜 cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --config-file unleash.json我收到一个丑陋的错误,它显然需要 YAML。
cookiecutter.exceptions.InvalidConfiguration: Unable to parse YAML file .../000.packaging/unleash.json. Error: None of the known patterns match for {
"cookiecutter": {
"full_name": "Spartacus",

没问题, json2yaml到救援。
那也行不通。
cookiecutter.exceptions.InvalidConfiguration: Unable to parse YAML file ./cookie.yaml. Error: Unable to determine type for "
full_name: "Spartacus"

我也试过 < stdin重定向:
cookiecutter.prompts.txt :
yes
Spartacus
...
它似乎没有使用它,只是中止了。
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git < ./cookiecutter.prompts.txt
You've downloaded ~/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]
: full_name [Audrey Roy Greenfeld]
: email [audreyr@example.com]
: Aborted
我怀疑我遗漏了一些明显的东西,不确定是什么。首先,--config 文件的意图和格式是什么?
汇报 - 我是如何从接受的答案中得到它的。
接受了答案,但将其调整为 ~/.cookiecutterrc用法。它有效,但格式不是很清楚。尤其不上 rc这必须是 yaml,尽管 rc 文件并不总是/经常是这种情况。
这最终起作用了:
文件 ~/.cookiecutterrc:
不嵌套 default_context ...大量无用的 yaml 解析错误(在有效的 yaml 文档中)。
default_context:
#... cut out for privacy
add_pyup_badge: y
command_line_interface: "Click"
create_author_file: "y"
open_source_license: "MIT license"

# the names to use here are:
# full_name:
# email:
# github_username:
# project_name:
# project_slug:
# project_short_description:
# pypi_username:
# version:
# use_pytest:
# use_pypi_deployment_with_travis:
# add_pyup_badge:
# command_line_interface:
# create_author_file:
# open_source_license:

我还是找不到 ~/.cookiecutterrc的组合和特定于项目的 config.yaml上类。太糟糕了,预期的配置格式记录如此之少。
所以我将使用 .rc 但每次都输入项目名称、slug 和描述。哦,好吧,现在已经足够了。

最佳答案

你在附近。

试试这个 cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git --no-input --config-file config.yaml--no-input参数将抑制终端用户输入,它当然是可选的。

config.yaml 文件可能如下所示:

default_context:
full_name: "Audrey Roy"
email: "audreyr@example.com"
github_username: "audreyr"
cookiecutters_dir: "/home/audreyr/my-custom-cookiecutters-dir/"
replay_dir: "/home/audreyr/my-custom-replay-dir/"
abbreviations:
pp: https://github.com/audreyr/cookiecutter-pypackage.git
gh: https://github.com/{0}.git
bb: https://bitbucket.org/{0}

引用此示例文件: https://cookiecutter.readthedocs.io/en/1.7.0/advanced/user_config.html

您可能只需要 default_context块,因为那是用户输入的地方。

关于cookiecutter - 曲奇刀 : what's the easiest way to specify variables for the prompts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60458434/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com