Python packaging and dependency management made easy https://github.com/python-poetry/poetry
天问 7c9e65faaf Update 'README.md' | 3 months ago | |
---|---|---|
README.md | 3 months ago |
依赖管理工具,集成pip, virturlenv
pipx install poetry==1.2.0
# 新建项目
poetry new demo
# 老项目加入poetry
poetry init
poetry env info
poetry config --list
poetry config virtualenvs.in-project true
# 国内镜像
poetry source add --priority=primary mirrors https://mirrors.aliyun.com/pypi/simple/
poetry install
poetry install --with data # 安装可选依赖
poetry shell
pyenv local 3.9.10
poetry env use $(pyenv which python)
poetry add httpx
# add from requirements.txt
poetry add $(cat requirements.txt)
# export to requirements.txt
poetry export -f requirements.txt --output requirements.txt --without-hashes
# 增加dev测试依赖
poetry add --dev pre-commit
poetry add --group=dev pre-commit pytest pytest-asyncio
# 执行代码检查
poetry run pre-commit run --all-file
poetry update
poetry export
# 发布
poetry build
poetry publish
错误:
bash: __vsc_prompt_cmd_original: command not found
执行:
unset PROMPT_COMMAND
[tool.poetry]
name = "my-package"
version = "0.1.0"
description = "The description of the package"
license = "MIT"
authors = [
"Sébastien Eustace <sebastien@eustace.io>"
]
repository = "https://github.com/python-poetry/poetry"
homepage = "https://python-poetry.org"
# README file(s) are used as the package description
readme = ["README.md", "LICENSE"]
# Keywords (translated to tags on the package index)
keywords = ["packaging", "poetry"]
[tool.poetry.dependencies]
# Compatible Python versions
python = ">=3.8"
# Standard dependency with semver constraints
aiohttp = "^3.8.1"
# Dependency with extras
requests = { version = "^2.28", extras = ["security"] }
# Version-specific dependencies with prereleases allowed
tomli = { version = "^2.0.1", python = "<3.11", allow-prereleases = true }
# Git dependencies
cleo = { git = "https://github.com/python-poetry/cleo.git", branch = "master" }
# Optional dependencies (installed by extras)
pendulum = { version = "^2.1.2", optional = true }
# Dependency groups are supported for organizing your dependencies
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
pytest-cov = "^3.0"
# ...and can be installed only when explicitly requested
[tool.poetry.group.docs]
optional = true
[tool.poetry.group.docs.dependencies]
Sphinx = "^5.1.1"
# Python-style entrypoints and scripts are easily expressed
[tool.poetry.scripts]
my-script = "my_package:main"