Poetry ์ฌ์ฉํ๊ธฐ#
: Python packaging and dependency management made easy
pyproject.toml
์ด๋ผ๋ ํ์ผ ํ๋๋ก setup.py, requirements.txt, pip๋ฑ ์ด์ฉ๊ตฌ ์ ์ฉ๊ตฌ ๋๋ถ๋ถ์ ์์กด์ฑ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ python์ ๋
ธ๋ ฅ๋ค์ ํ๋๋ก ํตํฉํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
๋ง์ ์ฅ์ ๋ค์ด ์๋ ๊ฒ์ผ๋ก ๋ณด์ด์ง๋ง ์ฐ์ ๊ฐ๋จํ๊ฒ ์ฌ์ฉํด๋ณธ ๊ฒฐ๊ณผ๋ก๋ ์ด๋ ๋ค.
ํ๋ก์ ํธ ๊ฒฉ๋ฆฌ: Poetry๋ ํ๋ก์ ํธ์ ์ข ์์ฑ์ ์๋์ผ๋ก ๊ฒฉ๋ฆฌ๋ ๊ฐ์ ํ๊ฒฝ์ ์ค์นํ๋ค. ์ด๋ pip์์๋ ์๋์ผ๋ก ํด์ผ ํ๋ ๊ฒ์ด์ง๋ง, Poetry์์๋ ์๋์ผ๋ก ์ด๋ฃจ์ด์ง๋ค.
ํจํค์ง ๋ฐฐํฌ: pip๋ ํจํค์ง ์ค์น ๋๊ตฌ๋ก ์ค๊ณ๋์์ง๋ง, Poetry๋ ํจํค์ง ์์ฑ ๋ฐ ๋ฐฐํฌ๋ฅผ ์ง์ํ๋ค. ์ด๋ ํ๋ก์ ํธ๋ฅผ PyPI์ ๊ฒ์ํ๊ณ ๋ค๋ฅธ ์ฌ๋๋ค์ด ์ฌ์ฉํ ์ ์๊ฒ ํ๋ ๋ฐ ๋์๋๋ค.
๊ฒฐ์ ๋ก ์ ์ค์น: Poetry.lock ํ์ผ์ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ์ ์ข ์์ฑ์ ์ ํํ๊ฒ ๋ฒ์ ๋ณ๋ก ์ถ์ ํ๋ค. ์ด๋ ๋์ผํ ํ๋ก์ ํธ๋ฅผ ๋ค๋ฅธ ์์คํ ์์ ์ฌํํ ๋ ๋์๋๋ค.
[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"
main functions#
์ฐจ๊ทผ์ฐจ๊ทผ ํ๋์ฉ ๋ฐ๋ผ๊ฐ๋ณด๋ฉด ์ดํด๋๋ค.
# ์ค์น : py๊ฐ ์๋๋ผ python์ผ๋ก ํด์ค์ผํ๋ค.
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
# ํ๋ก์ ํธ ์์ฑ
poetry new your-project-name
# ๊ธฐ์กด ํด๋์ poetry ๋ฎ๊ธฐ
poetry init
# pyproject.toml ์ฝ์ด์ poetry.lock ์์ฑ - ๊ฐ์ํ๊ฒฝ๋ ์์ฑ
poetry install
poetry add your-package-name
# poetry.lock ๊ฐฑ์
poetry update
# ํจํค์ง ์ญ์
poetry remove your-package-name
# lockํ์ผ์ package ๊ตฌ์ฑ ํ์ธ
poetry show --tree
# poetry.lock ํ์ผ๊ณผ pyproject.toml ํ์ผ์ ์ข
์์ฑ์ด ๋์ผํ์ง ํ์ธ
poetry check
๊ฐ์ํ๊ฒฝ ์ฌ์ฉ
# venv ๋ค์ด๊ฐ๊ธฐ
poetry shell
# venv ๋๊ฐ๊ธฐ
exit
# ํ๊ฒฝ์ ๋ณด ํ์ธ
poetry env info --path
poetry env list
poetry env remove
requirements.txt -> pyproject.toml#
๊ธฐ์กด์ requirements.txt๋ฅผ ์ฌ์ฉํด์ poetry add๋ฅผ ์ผ๊ด์ ์ผ๋ก ํ๋ ๋ฐฉ๋ฒ๋ ์กด์ฌํ๋ค. ๊ทธ๋๋ ๊ผด์ ์์ ๋ถํฐ ์ฌ์ฉํ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ requirements.txt๋ ์ฌ์ ํ ๋ง์ด ์ฌ์ฉ๋๊ณ ์๋ค.
๋งฅ์์๋ ์ด๋ ๊ฒ ํด์ฃผ๋ฉด๋๊ณ
cat requirements.txt | xargs poetry add
์๋์ฐ powershell์์๋ ์๋์ฒ๋ผ ํด์ฃผ๋ฉด ๋๋ค.
Get-Content requirements.txt | ForEach-Object { poetry add $_ }
๋ฆฌ๋
์ค ๋ช
๋ น์ด๋ค์ด ๋ฐ๋ก ํ์์์์๋ ์ฌ์ฉ๋์ง ์๊ธฐ ๋๋ฌธ์ ์กฐ๊ธ ๋ช
๋ น์ด๊ฐ ๋ค๋ฅผ ์ ์๋ค. xargs
๋ ์
๋ ฅ์ ๋ฐ์์ ๊ฐ๊ฐ์ ์
๋ ฅ์ ๋ํด ํน์ ๋ช
๋ น์ด๋ฅผ ์คํํ๋ ์ญํ ์ ํ๋ค. ์ฌ๊ธฐ์๋ js์์ ์ฒ๋ผ foreach๋ฅผ ์ฌ์ฉํ๋ ๋ชจ์ต์ ๋ณด์ธ๋ค.
๋ง์ฝ ์คํฌ๋ฆฝํธ ์คํ ๊ถํ์ด ๋นํ์ฑํ ๋์ด์์ผ๋ฉด Set-ExecutionPolicy remoteSigned
๋ฅผ ์ณ์ค๋ค.