poetry

poetry #

python-poetry/poetry Github stars Github forks Language Last Tag Last commit

# 安装
pipx install poetry

# tab completion, 参考:https://python-poetry.org/docs/#enable-tab-completion-for-bash-fish-or-zsh
mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry

# 在 ~/.zshrc 的  plugins 里面加上 poetry,再执行 zsh
# plugins(
#   poetry
#   ...
#   )

教程 #

Poetry replaces setup.py, requirements.txt, setup.cfg, MANIFEST.in and Pipfile with a simple pyproject.toml based project format.

Poetry will not automatically install a python interpreter for you.

# 新建项目
poetry new poetry-demo

# 从已有的项目初始化
cd pre-existing-project
poetry init

# 进入虚拟环境,还会打开一个嵌套的 shell
poetry shell

# 1. 退出虚拟环境
deactivate
# 2. 退出虚拟环境,并退出会话,丢失当前会话的所有上下文和未保存的状态
exit

# 添加新的依赖
poetry add

# 查看依赖
poetry show
poetry show --tree
poetry show --outdated

# 更新 dependencies
# This is equivalent to deleting the poetry.lock file and running install again
poetry update

# 移除依赖
poetry remove

# https://python-poetry.org/docs/configuration/#cache-dir
# 虚拟环境目录
cd ~/Library/Caches/pypoetry

版本说明 #

  • 脱字符号 ^: 最左侧非零数字不能变
    • ^1.2: 1.2 <= 版本号 < 2.0
    • ^0.2.3: 0.2.3 <= 版本号 < 0.3.0
    • ^1.2.3: 1.2.3 <= 版本号 < 2.0.0
  • 波浪号运算符 ~: 下一个重要版本(右侧第二位不能变)
    • ~1.2: 1.2 <= 版本号 < 2.0
    • ~0.2.3: 0.2.3 <= 版本号 < 0.3.0
    • ~1.2.0: 1.2.0 <= 版本号 < 1.3.0
    • ~1.2.3: 1.2.3 <= 版本号 < 1.3.0

参考:语义化版本


本文访问量

本站总访问量

本站总访客数