4
python打包和依赖管理工具poetry
source link: https://www.80shihua.com/archives/3240
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
poetry
Poetry 是 Python 中用于依赖管理和打包的工具。 它允许您声明项目所依赖的库,并将为您管理(安装 / 更新)它们。 Poetry 提供了一个锁文件来确保可重复安装,并且可以构建您的项目以进行分发。
poetry 需要 Python 3.7+。它是多平台的,可以出色地工作 在 Linux、macOS 和 Windows 上。
linux,mac,wsl 安装方式
curl -sSL https://install.python-poetry.org | python3 -
windows 安装方式 (powershell)
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
poetry --versionpoetry self update
zsh 配置自动补全
poetry completions zsh > ~/.zfunc/_poetry
修改.zshrc 添加路径
fpath+=~/.zfuncautoload -Uz compinit && compinit
0h-my-zsh 配置自动补全
mkdir $ZSH_CUSTOM/plugins/poetrypoetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry
plugins( poetry ... )
poetry new poetry-demo
初始化存在的项目
cd pre-existing-projectpoetry init
poetry add pendulum
根据配置文件安装依赖
poetry install
发布 python 包
poetry publish
显示目录信息
$ poetry show --treerequests-toolbelt 0.8.0 A utility belt for advanced users...└── requests <3.0.0,>=2.0.1 ├── certifi >=2017.4.17 ├── chardet >=3.0.2,<3.1.0 ├── idna >=2.5,<2.7 └── urllib3 <1.23,>=1.21.1 $ poetry show --latestpendulum 2.0.4 1.4.5 Python datetimes made easy.django 1.11.11 2.0.3 A high-level Python Web framework ...requests 2.18.4 2.18.4 Python HTTP for Humans.
poetry env use 3.7
poetry env infopoetry env list
poetry env remove /full/path/to/pythonpoetry env remove python3.7poetry env remove 3.7poetry env remove test-O3eWbxRl-py3.7
依赖于 git
[tool.poetry.dependencies]# Get the latest revision on the branch named "next"requests = { git = "https://github.com/kennethreitz/requests.git", branch = "next" }# Get a revision by its commit hashflask = { git = "https://github.com/pallets/flask.git", rev = "38eb5d3b" }# Get a revision by its tagnumpy = { git = "https://github.com/numpy/numpy.git", tag = "v0.13.2" }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK