python-3.x - 诗歌是否忽略了额外内容或 pyproject.toml 配置错误?
问题描述
我有诗歌创建的新项目 yolo。
我确实遵循了以下步骤:
poetry new
poetry add requests
poetry add -D pytz
poetry add -D --optional --extras=dev ipdb
poetry lock
我的 toml 文件如下所示:
[tool.poetry]
name = "yolo"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.6"
requests = "^2.24.0"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
pytz = "^2020.1"
ipdb = {version = "^0.13.3", optional = true, extras = ["dev"]}
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
我删除了环境:
$ poetry env list
yolo-_0wi_Pw3-py3.6 (Activated)
$ poetry env remove yolo-_0wi_Pw3-py3.6
Deleted virtualenv: .cache/pypoetry/virtualenvs/yolo-_0wi_Pw3-py3.6
现在,如果我尝试这样做:
$ poetry install
Creating virtualenv yolo-_0wi_Pw3-py3.6 in .cache/pypoetry/virtualenvs
Installing dependencies from lock file
Package operations: 17 installs, 0 updates, 0 removals
- Installing six (1.15.0)
- Installing wcwidth (0.2.5)
- Installing zipp (3.2.0)
- Installing importlib-metadata (2.0.0)
- Installing pyparsing (2.4.7)
- Installing attrs (20.2.0)
- Installing certifi (2020.6.20)
- Installing chardet (3.0.4)
- Installing idna (2.10)
- Installing more-itertools (8.5.0)
- Installing packaging (20.4)
- Installing pluggy (0.13.1)
- Installing py (1.9.0)
- Installing urllib3 (1.25.10)
- Installing pytest (5.4.3)
- Installing pytz (2020.1)
- Installing requests (2.24.0)
- Installing yolo (0.1.0)
正如预期的那样,没有 ipdb。
但如果我尝试:
$ poetry install --extras='dev'
Installing dependencies from lock file
[ValueError]
Extra [dev] is not specified.
为了澄清和解释更多。
我的问题中生成的 Toml 文件是诗歌的自动工作,并且有一个需要手动干预的修复程序。
[tool.poetry]
name = "yolo"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.6"
requests = "^2.24.0"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
pytz = "^2020.1"
ipdb = {version = "^0.13.3", optional = true, extras = ["dev"]}
[tool.poetry.extras]
dev = ["ipdb"]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
不用说,它令人困惑。
但从现在开始,如果我们这样做:
$ poetry install -E dev
它将按预期工作,并将安装 ipdb。
解决方案
我和我的朋友花了一些时间弄清楚发生了什么。
当你这样做时:
poetry install --extra=dev ipdb
实际上发生的情况是,您指定要使用 ipdb 可能使用或不使用的额外“开发”的 ipdb。
因此在 toml 中它将被声明为:
[tool.poetry.dev-dependencies]
ipdb = {version = "^0.13.3", extras = ["dev"]}
实际上我想要实现的是指定存在额外的 yolo 项目,它称为 dev 并包括安装 ipdb。这是通过在诗歌中添加新部分来实现的:
[tool.poetry.extras]
dev = ["ipdb"]
令人困惑的因素是两者都使用关键字extra,而上下文完全不同。作为依赖定义的一部分,主包 extra 的风格也与 extra 不同。
推荐阅读
- regex - 用于匹配纬度、经度的正则表达式,没有任何字符
- sql - 无法列出在特定月份和年份处理最多约会的员工
- javascript - 当用户重新加载页面时,他无法获取存储在后端数组中的信息
- python - 如何在Python中列表的偶数位置添加值
- php - 使用 Prestashop 1.7 检索类别中的产品数量
- android - 如何在颤动中检查子列表是否为空或为空
- javascript - angularjs中的屏幕阅读器“跳到主要内容”功能
- php - 根据初始上下文选择节点
- php - 使用 fpdm 填充字段后 PHP 展平 PDF 表单而不使用 PDFtk
- flutter - 如何在应用程序启动时运行 Provider 方法?