python之poetry模块,项目管理

一、简介

Poetry 是一个用于管理 Python 项目依赖关系和构建工具的工具。它提供了一个简单的命令行界面,可以帮助您创建、管理和发布 Python 项目,使用方法:command [options] [arguments]
官网:https://python-poetry.org/docs/

  1. 主要功能和用途
  • 创建新的 Python 项目:Poetry 提供了 new 命令,可以创建一个新的 Python 项目,并设置项目的基本配置。
  • 管理依赖项:Poetry 使用 pyproject.toml 文件来管理项目的依赖项。您可以通过运行 add 命令添加依赖项,指定版本要求,并自动解析依赖关系。Poetry 还支持锁定依赖项的版本,以确保项目在不同环境中的一致性。
  • 构建和发布项目:Poetry 提供了 build 命令,用于构建项目。您可以选择将项目打包为源码分发包或二进制分发包。此外,Poetry 还支持将项目发布到 PyPI 或私有仓库。
  • 虚拟环境管理:Poetry 可以为每个项目创建和管理独立的虚拟环境。这使得项目的依赖项与其他项目隔离开来,确保项目的环境独立性和可重现性。
  • 运行命令和脚本:Poetry 允许您在项目的虚拟环境中运行命令和脚本。这样可以确保命令和脚本在正确的环境中执行,并且可以访问项目的依赖项。
  1. poetry优点
  • 简化依赖项管理:Poetry 提供了一个统一的方式来管理项目的依赖项。您可以在 pyproject.toml 文件中指定项目的依赖项,并且可以使用 Poetry 的命令来安装、更新和删除依赖项。这简化了依赖项的管理过程,使得项目的环境配置更加简单和可靠。
  • 虚拟环境和依赖项隔离:Poetry 支持创建和管理虚拟环境,这使得每个项目都可以拥有独立的 Python 环境。这样可以避免不同项目之间的依赖项冲突,并且可以确保每个项目都使用正确的依赖项版本。
  • 自动生成和维护 pyproject.toml 文件:Poetry 可以自动为您的项目生成和维护 pyproject.toml 文件。这个文件包含了项目的元数据、依赖项和构建配置等信息。通过自动生成和维护这个文件,Poetry 简化了项目配置的过程,使得项目的管理更加方便。
  • 构建和发布支持:Poetry 提供了一些命令来构建和发布项目。您可以使用 Poetry 构建项目的分发包,并且可以轻松地发布到 PyPI 或其他包管理平台。这使得项目的构建和发布过程更加简单和一致。
  1. poetry缺点
  • 学习曲线:Poetry 的功能非常丰富,但这也意味着它有一个相对陡峭的学习曲线。对于新用户来说,可能需要一些时间来熟悉 Poetry 的命令和工作流程。然而,一旦掌握了基本的概念和操作,Poetry 可以提供强大的依赖项管理能力。
  • 社区支持:尽管 Poetry 的用户群体在不断增长,但与其他一些依赖项管理工具相比,Poetry 的社区支持可能相对较小。这意味着在遇到问题时,可能需要花费一些时间来寻找解决方案或寻求帮助。
二、poetry使用
  1. 安装poetry,windows打开Power shell运行:Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -,安装成功会显示安装路径,尽量去官网拷贝该命令:https://python-poetry.org/docs/#installing-with-the-official-installer
    在这里插入图片描述
  2. 配置环境变量
    在这里插入图片描述
  3. 打开命令行工具,运行poetry --version,显示版本号安装成功
    在这里插入图片描述
  4. poetry new demo 创建项目
    在这里插入图片描述
  5. poetry add requests 添加依赖项,pyproject.toml项目元数据和构建配置的文件:https://python-poetry.org/docs/pyproject/
    在这里插入图片描述
  6. 卸载依赖项 poetry remove requests
  7. 导出 requirements.txt 文件,poetry export -f requirements.txt --output requirements.txt
  8. 卸载poetry,windows打开Power shell运行:(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python - --uninstall
三、pyproject.toml文件解析

与pyproject.toml相对应的文件poetry.lock,poetry.lock会将第三方库的版本锁定,后面的开发人员根据puproject.toml安装的时候,第三方库的版本是固定的。poetry install安装依赖项时poetry.lock文件存在会解析并安装您在中列出的所有依赖项pyproject.toml,但 Poetry 使用中列出的确切版本poetry.lock来确保包版本对于在您的项目中工作的每个人都是一致的。使用poetry.lock进行项目的版本控制是非常重要的,poetry.lock安装依赖时会自动生成

  1. tool.poetry:配置Poetry的选项和属性
[tool.poetry]
name = "order"  # 项目的名称
version = "0.1.0"  # 项目版本
description = ""  # 项目描述
authors = ["zhansan"]  # 项目作者信息
readme = "README.md"  # 项目的 README 文件路径
homepage = ""  # 项目的主页 URL
license = ""  # 项目的许可证
maintaine = ["lisi"]  # 项目的维护者列表
repository = "https://github.com/python-poetry/poetry"  # 项目的代码仓库 URL
documentation = "https://python-poetry.org/docs/"  # 项目的文档 URL
keywords = "python-poetry"  # 项目的关键词列表
classifiers = ["Topic :: Software Development :: Build Tools",]  # 项目的分类器列表,分类器是一种标记,用于描述项目的特性、用途或所属领域
packages = [ { include = "my_package", from = "lib", format = "sdist"}]  # 最终发行版中包含的包和模块的列表
include = [{path = "for_wheel.txt", format = ["sdist", "wheel"]}]  # 要包含在项目中的其他文件或目录列表
exclude = []  # 要排除在项目之外的文件或目录列表
''''''''''''format''''''''''''
sdist:表示将文件或目录打包为源分发包(source distribution)。
wheel:表示将文件或目录打包为 Wheel 包。
bdist:表示将文件或目录打包为二进制分发包(binary distribution)。
egg:表示将文件或目录打包为 Egg 包。

''''''''''''license''''''''''''
Apache-2.0:Apache 许可证 2.0 版,是一种宽松的开源许可证,允许您使用、修改和分发代码,但需要保留原始版权和许可声明。
BSD-2-Clause:BSD 2-Clause 许可证,也称为简化 BSD 许可证或 FreeBSD 许可证,是一种宽松的开源许可证,允许您使用、修改和分发代码,但需要保留原始版权和许可声明。
BSD-3-Clause:BSD 3-Clause 许可证,也称为新 BSD 许可证或修订 BSD 许可证,是一种宽松的开源许可证,允许您使用、修改和分发代码,但需要保留原始版权和许可声明。
BSD-4-Clause:BSD 4-Clause 许可证,也称为原始 BSD 许可证或古老的 BSD 许可证,是一种宽松的开源许可证,允许您使用、修改和分发代码,但需要保留原始版权和许可声明。
GPL-2.0-only:GNU General Public License (GPL) 2.0 版,是一种强 copyleft 许可证,要求任何基于 GPL 许可的代码的派生作品也必须使用 GPL 许可证。
GPL-2.0-or-later:GNU General Public License (GPL) 2.0 版或任何后续版本,具有与 GPL-2.0-only 相同的要求。
GPL-3.0-only:GNU General Public License (GPL) 3.0 版,是一种强 copyleft 许可证,要求任何基于 GPL 许可的代码的派生作品也必须使用 GPL 许可证。
GPL-3.0-or-later:GNU General Public License (GPL) 3.0 版或任何后续版本,具有与 GPL-3.0-only 相同的要求。
LGPL-2.1-only:GNU Lesser General Public License (LGPL) 2.1 版,是一种较宽松的开源许可证,允许您将 LGPL 许可的代码与其他非 LGPL 许可的代码进行链接,而不需要将整个作品都采用 LGPL 许可。
LGPL-2.1-or-later:GNU Lesser General Public License (LGPL) 2.1 版或任何后续版本,具有与 LGPL-2.1-only 相同的要求。
LGPL-3.0-only:GNU Lesser General Public License (LGPL) 3.0 版,是一种较宽松的开源许可证,允许您将 LGPL 许可的代码与其他非 LGPL 许可的代码进行链接,而不需要将整个作品都采用 LGPL 许可。
LGPL-3.0-or-later:GNU Lesser General Public License (LGPL) 3.0 版或任何后续版本,具有与 LGPL-3.0-only 相同的要求。
MIT:MIT 许可证,是一种宽松的开源许可证,允许您使用、修改和分发代码,但需要保留原始版权和许可声明。
  1. tool.poetry.dependencies:指定项目的依赖项,poetry add 添加的依赖项
[tool.poetry.dependencies]
python = "^3.11"
requests = { version = "^2.13.0", source = "private" }
requests = { git = "https://github.com/kennethreitz/requests.git", branch = "next" }
''''''''''''使用 Git 作为依赖项的源时''''''''''''
git:指定 Git 仓库的 URL
branch:指定要使用的 Git 分支
rev:指定要使用的 Git 提交哈希
tag:指定要使用的 Git 标签
subdirectory:如果 Git 仓库中有多个子目录,并且只需要其中一个子目录作为依赖项,可以使用 subdirectory 选项来指定子目录的路径
optional:如果希望将某个依赖项标记为可选的,即如果依赖项无法安装也不会导致构建失败
develop:如果希望将 Git 仓库作为开发模式下的依赖项,即在开发期间对其进行修改并实时生效
submodules:如果 Git 仓库包含子模块,可以使用 submodules 选项来指定是否需要包括子模块
  1. tool.poetry.source:用于指定依赖包源,可以是私有的,也可以是自定义的,poetry source add 添加的依赖项
[[tool.poetry.source]]
name = "private"
url = "http://example.com/private"
default = false # 是否默认
secondary = false # 是否是辅助源

[[tool.poetry.source]]
name = "custom_source"
url = "http://example.com/custom_source"
  1. tool.poetry.group:分组依赖项
[tool.poetry.group.dev.dependencies]  # 添加依赖到dev组:poetry add pytest --group dev
pytest = "*"
astapi = {version="^0.92.0", extras=["all"]} # extras对应tool.poetry.extras

[tool.poetry.group.docs]
optional = true  # 可选组

[tool.poetry.group.docs.dependencies]  # 添加依赖到可选组:poetry install --with docs
mkdocs = "*"
  1. tool.poetry.scripts:配置用于定义项目的命令行脚本,poetry run script1运行脚本
[tool.poetry.scripts]
script1 = 'module1:function1'
script2 = { reference = "mdule1:function2", extras = ["test"], type = "console" } # extras对应tool.poetry.extras
''''''''''''配置项''''''''''''

1、reference: 这是一个必需的属性,用于指定要执行的函数或命令。它可以采用以下两种形式之一:

"module:function": 表示要执行指定模块中的特定函数。例如,"mymodule:myfunction" 表示要执行 mymodule 模块中的 myfunction 函数。
"command": 表示要执行的命令行命令。例如,"python -m mymodule" 表示要执行 python -m mymodule 命令。

2、extras: 可选属性,用于指定额外的依赖项组。它是一个字符串数组,包含要使用的依赖项组的名称。这通常用于在特定场景或环境中运行脚本时,提供额外的依赖项。


3、type: 这是一个可选的属性,用于指定命令行脚本的类型。它可以是以下值之一:

"console": 表示该脚本是一个控制台命令行脚本,可以在终端中直接执行。
"gui": 表示该脚本是一个图形用户界面 (GUI) 脚本,需要在图形环境中执行。
  1. tool.poetry.extras:配置用于定义额外的依赖项组,poetry install --extras “mysql”
[tool.poetry.dependencies]
psycopg2 = {version = "^2.9", optional = true}
mysqlclient = {version = "^1.3", optional = true}

[tool.poetry.extras]
mysql = ["mysqlclient"]  # 当需要在项目中使用 MySQL 数据库时,可以通过启用 mysql 依赖项组来安装 mysqlclient。

databases = ["mysqlclient", "psycopg2"]  # 您需要在项目中使用多个数据库时,可以通过启用 databases 依赖项组来同时安装这两个依赖项
  1. tool.poetry.plugins:配置允许将自定义的插件集成到 Poetry 或其他工具中,可使用poetry self 管理插件,如:poetry self show plugins 查看插件信息,https://python-poetry.org/docs/plugins/
'''
<plugin-type>:插件类型,core(核心插件)、tool(工具插件)、command(命令插件) 或 export(导出插件),也可以自己定义
<plugin-name>:插件名称,用于标识插件。
<module-path>:自定义插件的 Python 模块的导入路径。
<entry-point>:插件的入口点,可以是一个函数或类的名称。
'''
[tool.poetry.plugins.<plugin-type>]
<plugin-name> = "<module-path>:<entry-point>"
  1. tool.poetry.urls:配置项目相关的 URL,如果在PyPI上发布包,它们将出现在Project Links部分中
[tool.poetry.urls]
"Documentation" = "https://example.com/docs"
"Source Code" = "https://example.com/source"
  1. build-system:定义构建系统相关的配置
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" # poetry build
四、poetry config 用于配置 Poetry 的全局或项目级设置
  1. poetry config --list:查看全局 Poetry 配置
cache-dir:指定 Poetry 缓存的目录路径,用于存储下载的包和其他缓存文件。
experimental.system-git-client:指定是否启用实验性的系统 Git 客户端。如果设置为 true,Poetry 将使用系统中已安装的 Git 客户端进行操作。
installer.max-workers:指定安装器的最大并发工作线程数。如果设置为 null,Poetry 将根据系统的可用 CPU 核心数自动确定并发数。
installer.modern-installation:指定是否启用现代安装模式。如果设置为 true,Poetry 将使用现代安装模式进行包安装。
installer.no-binary:指定是否禁用二进制包的安装。如果设置为 null,则不禁用二进制包。
installer.parallel:指定是否启用并行安装。如果设置为 true,Poetry 将尝试并行安装包以加快安装速度。
repositories.pypi.url:指定 PyPI 仓库的 URL 地址,用于下载包和依赖项。
virtualenvs.create:指定是否在项目中创建虚拟环境。如果设置为 true,Poetry 将在项目目录中创建虚拟环境。
virtualenvs.in-project:指定虚拟环境是否在项目目录中。如果设置为 null,Poetry 将根据项目的配置自动确定虚拟环境的位置。
virtualenvs.options.always-copy:指定是否始终复制虚拟环境。如果设置为 false,Poetry 将尝试使用硬链接或符号链接来创建虚拟环境。
virtualenvs.options.no-pip:指定是否禁用虚拟环境中的 pip 工具。
virtualenvs.options.no-setuptools:指定是否禁用虚拟环境中的 setuptools 库。
virtualenvs.options.system-site-packages:指定是否在虚拟环境中包含系统安装的包。
virtualenvs.path:指定虚拟环境的路径。这里使用了 {cache-dir} 变量,将其替换为缓存目录的路径。
virtualenvs.prefer-active-python:指定是否优先使用活动的 Python 解释器。
virtualenvs.prompt:指定虚拟环境的命令行提示符格式。其中 {project_name} 会被替换为项目名称,{python_version} 会被替换为 Python 版本。
warnings.export:指定是否导出警告信息。如果设置为 true,Poetry 将导出警告信息。
设置镜像源:poetry config repositories.pypi https://pypi.org/simple
添加conda镜像源:poetry config repositories.conda https://repo.anaconda.com/pkgs/main
添加清华大学镜像源:poetry config repositories.thu https://pypi.tuna.tsinghua.edu.cn/simple



''''''''''repositories.pypi.url常用镜像源''''''''''
官网:https://pypi.org/simple
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:https://mirrors.aliyun.com/pypi/simple
豆瓣 :http://pypi.douban.com/
中国科学技术大学 :http://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
conda:https://repo.anaconda.com/pkgs/main
  1. poetry config :查看全局 Poetry 某个配置
  2. poetry config :设置全局 Poetry 配置
  3. poetry config --unset :删除全局 Poetry 配置
  4. poetry config --local --list:查看项目 Poetry 配置
  5. poetry config --local :查看项目 Poetry 某个配置
  6. poetry config --local :设置项目 Poetry 配置
五、poetry new 创建项目
  1. –name Name:设置生成的包名,如:poetry new demo --name newDemo
  2. –src:在项目根目录下创建一个名为 “src” 的目录,用于存放项目的源代码,如:poetry new demo --src
  3. –readme README:定要使用的 README 文件类型,md(默认)或rest之一,如:poetry new demo --readme rst
六、poetry install 安装依赖项
  1. –without WITHOUT:用于指定要忽略的依赖组,可以提供多个值以指定要忽略的多个依赖组,如:poetry install --without dev docs
  2. –with WITH:用于指定要包括的可选依赖组。可以提供多个值以指定要包括的多个依赖组,如:poetry install --with dev docs
  3. –only ONLY:用于指定要包括的唯一依赖组。可以提供多个值以指定要包括的多个依赖组,如:poetry install --only dev docs
  4. –sync:用于将环境(pyproject.toml)与锁定的包(poetry.lock)的依赖组进行同步,如:poetry install --sync
  5. –no-root:用于仅安装项目所依赖的包,而不会将项目本身作为一个包进行安装(tool.poetry.dependencies、build-system的requires和build-backend),希望将项目作为一个库进行开发,可使用 --no-root,如:poetry install --no-root
  6. –no-directory:指示 Poetry 不安装任何目录路径依赖项,这对于安装没有源代码的依赖项(例如用于 Docker 层缓存)很有用。
  7. –dry-run:用于在不实际执行操作的情况下模拟运行 Poetry 命令,以查看将要执行的操作,如:poetry install --dry-run
  8. -E、–extras EXTRAS:用于安装额外的依赖项集,可以提供多个值以指定要安装的多个额外依赖项集,如:poetry install -E extra1 extra2
  9. –all-extras:用于安装所有额外的依赖项集,如:poetry install --all-extras
  10. –only-root:用于排除所有依赖项,只安装根包(tool.poetry.dependencies、build-system的requires和build-backend,如:poetry install --only-root
  11. –compile:用于将 Python 源代码编译为字节码。如果启用了现代安装(modern-installation),此选项将不起作用,默认modern-installation,如:poetry install --compile
七、poetry add 添加依赖项
  1. -G、–group GROUP:将依赖项添加到指定的组中,默认组为 “tool.poetry.dependencies”,指定组添加,如:poetry add --group=dev requests
  2. -e、–editable:用于将依赖项以可编辑模式添加到项目中,可编辑模式允许你在项目中修改依赖项的源代码,而不是将其作为普通的安装包进行安装,如:poetry add --editable …/my-library、poetry add --editable git+https://github.com/user/my-library.git
  3. -E、–extras EXTRAS:用于安装指定的附加依赖项,如:poetry add my-package --extras “feature1,feature2”
  4. –optional:用于安装可选的依赖项,如:poetry add requests --optional
  5. –python PYTHON:指定依赖项要求的 Python 版本,如:poetry add requests --python 3.9
  6. –platform PLATFORM:指定依赖项要求的平台,如:poetry add requests --platform linux
  7. –source SOURCE:指定要使用的安装源的名称,可以指定多个,如:poetry add requests --source pypi --source https://example.com/repository
  8. –allow-prereleases:允许安装预发布版本的依赖项,如:poetry add requests --allow-prereleases
  9. –dry-run:模拟添加依赖项的操作,如:poetry add requests --dry-run
  10. –lock:用于将依赖项添加到项目并更新锁文件,如:poetry add requests --lock
poetry add requests@2.26.0 #安装指定版本
poetry add requests@">=2.26.0,<3.0.0" #安装指定版本范围
poetry add git+https://github.com/python-poetry/poetry.git #提供依赖项的 Git URL,Poetry 将克隆该 Git 仓库并安装依赖项
poetry add git+https://github.com/python-poetry/poetry.git #develop #在 Git URL 后面添加修订版本的标识符,Poetry 将根据指定的修订版本安装依赖项
poetry add git+ssh://github.com/python-poetry/poetry.git #提供依赖项的 Git SSH URL,Poetry 将克隆该 Git 仓库并安装依赖项
poetry add git+ssh://github.com/python-poetry/poetry.git#develop #在 Git SSH URL 后面添加修订版本的标识符,Poetry 将根据指定的修订版本安装依赖项
poetry add ../my-package/my-package.whl #提供依赖项的本地文件路径,Poetry 将安装指定路径下的依赖项
poetry add ../my-package/ #提供依赖项的本地目录路径,Poetry 将安装指定目录中的依赖
poetry add https://example.com/packages/my-package-0.1.0.tar.gz #提供依赖项的远程 URL,Poetry 将下载并安装指定的依赖项
八、poetry remove 删除依赖项
  1. -G、–group=GROUP:从指定的依赖组中移除依赖项, 默认组为 “tool.poetry.dependencies”",指定组删除,如:poetry remove --group=dev pytest
  2. –dry-run:模拟删除依赖项的操作,如:poetry remove requests --dry-run
  3. –lock:用于将依赖项删除并更新锁文件,如:poetry remove requests --lock
九、poetry update 更新依赖项
  1. –without WITHOUT:用于指定要忽略的依赖组,可以提供多个值以指定要忽略的多个依赖组,如:poetry update --without dev docs
  2. –with WITH:用于指定要包括的可选依赖组。可以提供多个值以指定要包括的多个依赖组,如:poetry update --with dev docs
  3. –only ONLY:用于指定要包括的唯一依赖组。可以提供多个值以指定要包括的多个依赖组,如:poetry update --only dev docs
  4. –dry-run:用于在不实际执行操作的情况下模拟运行 Poetry 命令,以查看将要执行的操作,如:poetry update --dry-run
  5. –lock:只更新锁文件,如:poetry update --lock
十、poetry env 环境管理
  1. poetry env use:创建并指定 Poetry 环境,如:poetry env use
  2. poetry env info:显示当前活动 Poetry 环境的信息,如:poetry env info
  3. poetry env list:列出所有可用的 Poetry 环境,如:poetry env list
  4. poetry env remove:移除指定的 Poetry 环境,如:poetry env remove
十一、poetry source 源管理,tool.poetry.source
  1. poetry source add:添加源到 Poetry 配置,如:poetry source add
  2. poetry source show:显示当前配置的源。如:poetry source show
  3. poetry source remove:移除指定的源,如:poetry source remove
十二、poetry self 与Poetry相关的命令
  1. poetry self show:显示 Poetry 的详细信息,如:poetry self show
  2. poetry self update:更新 Poetry 到最新版本,如:poetry self update
  3. poetry self install:安装指定版本的 Poetry,如:poetry self install
  4. poetry self show plugins:显示已安装的 Poetry 插件,如:poetry self show plugins
十三、poetry cache 缓存
  1. poetry cache list:列出当前 Poetry 缓存中的包和版本,如:poetry cache list
  2. poetry cache clear:清除 Poetry 缓存,如:poetry cache clear --all
十四、poetry publish,将包发布到远程仓库(PyPI)
  1. -r、–repository REPOSITORY:指定要发布包的仓库,如:poetry publish -r https://myrepo.com
  2. -u、–username USERNAME:指定访问仓库的用户名,如:poetry publish -u myusername
  3. -p、–password PASSWORD:指定访问仓库的密码,如:poetry publish -p mypassword
  4. –cert CERT:指定访问仓库的证书机构,如:poetry publish --cert /path/to/cert.pem
  5. –client-cert CLIENT-CERT:指定访问仓库的客户端证书,如:poetry publish --client-cert /path/to/client_cert.pem
  6. –build:在发布之前构建包,如:poetry publish --build
  7. –dry-run:模拟发布过程,而不实际发布包,如:poetry publish --dry-run
  8. –skip-existing:忽略已经存在于仓库中的文件的错误,使用该选项可以跳过已经存在于仓库中的文件的发布,如:poetry publish --skip-existing
十五、poetry export,将锁定文件以其他格式导出
  1. -f, --format FORMAT:指定导出的格式,目前支持的格式有constraints.txt和requirements.txt,默认为requirements.txt,如:poetry export --format requirements.txt --output requirements.txt
  2. -o, --output OUTPUT:指定导出文件的名称。如果不指定,将使用默认的文件名,如:poetry export --format requirements.txt --output requirements.txt
  3. –without-hashes:在导出文件中排除哈希值,如:poetry export --format requirements.txt --output requirements.txt --without-hashes
  4. –without-urls:在导出文件中排除源代码仓库的URL,如:poetry export --format requirements.txt --output requirements.txt --without-urls
  5. –without WITHOUT:忽略指定的依赖组,poetry export --format requirements.txt --output requirements.txt --without dev --without docs
  6. –with WITH:包括指定的可选依赖组,如:poetry export --format requirements.txt --output requirements.txt --with dev --extras extra1 --extras extra2
  7. –only ONLY:只包括指定的依赖组,poetry export --format requirements.txt --output requirements.txt --only main --only tests
  8. -E, --extras EXTRAS:包括指定的额外依赖集,如:poetry export --format requirements.txt --output requirements.txt --extras extra1 --extras extra2
  9. –all-extras:包括所有额外依赖集,如:poetry export --format requirements.txt --output requirements.txt --all-extras
  10. –with-credentials:包括额外索引的凭据,如:poetry export --format requirements.txt --output requirements.txt --with-credentials
十六、poetry show 查看项目信息
  1. –without WITHOUT:忽略指定的依赖组,如:poetry show --without=dev --without=docs
  2. –with WITH:只包括指定的可选依赖组,如:poetry show --with=dev --with=docs
  3. –only ONLY:只包括指定的依赖组,如:poetry show --only=dev --only=docs
  4. -t、–tree:以树状结构列出依赖项,如:poetry show -t
  5. –why:在显示完整列表或单个包的树状结构时,同时显示为什么包被包含在其中,如:poetry show --why
  6. -l、–latest:显示最新的版本,如:poetry show -l
  7. -o、–outdated:显示最新的版本,如:poetry show -o
  8. -a、–all:显示所有包,即使它们与当前系统不兼容,如:poetry show -a
  9. -T、–top-level:仅显示顶级依赖项,如:poetry show -T
十七、其他命令
  1. poetry list:列出可用的命令。
  2. poetry about:显示有关 Poetry 的信息。
  3. poetry help:显示命令的帮助信息。
  4. poetry shell:在虚拟环境内启动一个shell。
  5. poetry lock:锁定项目的依赖项。
  6. poetry init:在当前目录创建一个基本的 pyproject.toml 文件。
  7. poetry run:运行脚本,tool.poetry.scripts,如:poetry run script1、poetry run python script.py
  8. poetry build:构建分发包,可指定格式:wheel(.whl文件)、sdist(.tar.gz文件)和egg(.egg文件),默认sdist,如:poetry build、poetry build -f wheel
  9. poetry check:验证 pyproject.toml 文件的内容以及与 poetry.lock 文件的一致性
  10. poetry check --lock::验证 poetry.lock 文件的内容以及与 pyproject.toml 文件的一致性
  11. poetry search <package_name>:在远程仓库上搜索包,如:poetry search requests
十八、通用命令配置项
  1. -h、–help:显示给定命令的帮助信息。如果没有给定命令,则显示 list 命令的帮助信息。
  2. -q、–quiet:不输出任何消息。
  3. -V、–version:显示 Poetry 应用程序的版本信息。
  4. –ansi:强制启用 ANSI 输出。
  5. –no-ansi:禁用 ANSI 输出。
  6. -n、–no-interaction:不要提出任何交互式问题。
  7. –no-plugins:禁用插件。
  8. –no-cache:禁用 Poetry 的源缓存。
  9. -C、–directory=DIRECTORY:指定 Poetry 命令的工作目录(默认为当前工作目录)。
  10. -v|vv|vvv、–verbose:增加消息的详细程度:1 为正常输出,2 为更详细的输出,3 为调试输出。
  • 28
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值