728x90

Poetry 이전의 배포 방식

PIP

pip는 파이썬으로 작성된 패키지 소프트웨어를 설치하는 패키지 관리 시스템입니다.
파이썬 패키지 인덱스 및 기타 인덱스에서 패키지를 설치하는 데 사용할 수 있습니다.

pip를 이용하여 설치하는 패키지는 모두 pypi에 존재하는 패키지이며, 아래와 같이 구조를 구성하여 배포할 수 있습니다.

Wheel?

  • Python의 배포 패키지 파일 (.whl)
  • 설치에 필요한 모든 파일과 메타데이터가 포함되어 있다. (Python 버전 및 플랫폼 정보 포함)

Wheel의 개발 배경?

  • Python에는 sdist보다 설치하기 쉬운 패키지 형식이 필요
    • 새로운 가상 환경에 설치하기 위해 distutils 및 setuptools를 필요로 하는데, 속도가 느리고 유지 관리가 어렵다.
  • 휠은 인스톨러가 빌드 시스템에 대해 알 필요가 없고, 여러 번 설치하는 동안 컴파일 시간을 분할하여 시간을 절약하며, 대상 환경에 빌드 시스템을 설치할 필요가 없다.

Venv, Virtualenv

  • 디렉토리에 각각 독립적인 파이썬 패키지가 설치되는 가상 환경 생성을 지원한다.
  • 선택적으로 기본 환경의 패키지와 분리 될 수 있으므로 가상환경에 명시적으로 설치된 패키지만 사용할 수 있다.
  • 가상 환경에서 사용하는 경우, 명시적으로 지시하지 않아도 pip같은 일반적인 설치 도구를 사용할 경우 가상 환경에 설치한다.
  • Venv가 Python 3.5 부터 내장으로 설치되어 있지만, 관습적으로 Virtualenv를 사용합니다.
    • Venv 모듈은 Virtualenv의 경량화 모듈이므로, 속도나 확장성 측면에서 부족합니다.
  • PEP 405 → 파이썬 가상 환경

가상환경

  • 파이썬 프로젝트를 독립적으로 관리하기 위한 도구
  • 시스템에 설치된 파이썬과 별도로 다른 디렉토리에 파이썬 인터프리터와 파이썬 라이브러리를 설치한 것

Poetry?

  • poetry는 Python 프로젝트의 의존성 관리와 패키지 배포를 도와주는 도구
    • pipvirtualenv 를 대체할 수 있다.
  • pyproject.toml 파일을 사용하여 프로젝트 설정과 의존성을 선언적으로 관리한다.
  • poetry.lock 파일은 의존성 트리에 있는 모든 패키지의 정확한 버전을 고정하고 기록합니다.
    • 반복 설치를 보장합니다.
  • 배포를 위해 프로젝트를 빌드할 수 있습니다.

pip의 경우 requirements.txt를 사용하여 의존성 목록을 관리할 수 있으나, poetry에 비해 빌드 시스템, 의존성 종류, 빌드 설정 등의 기능을 사용할 수 없다.

장점

  • VCS 관리를 위하여 MANIFEST.in 파일이 아닌 .gitignore 등을 사용하여 제외 섹션을 관리합니다.
  • setup.py, requirements.txt, setup.cfg, MANIFEST.inpyproject.toml 파일 하나로 대체합니다.
  • 사용자의 가상 환경에 맞는 패키지를 설치합니다.

명령어

  • poetry init
    • poetry 프로젝트 초기화
    • pyproject.yoml 파일이 생성된다.
  • poetry add <package name>
    • 패키지 추가
  • poetry add --dev <package name>
    • 개발 의존성으로 패키지 추가
  • poetry remove <package name>
    • poetry에 등록된 패키지 삭제
  • poetry shell
    • poetry가 관리하는 프로젝트의 가상 환경 활성화

pyproject.toml

  • 해당 파일은 Poetry에서 만든 것이 아닌 PEP 518에 정의된 표준입니다.
  • setuptools 의 불편한 점들을 개선하기 위해 정의되었습니다.
    • setup.py 파일의 종속성을 알지 못하면 실행할 수 없다.
    • 해당 종속성의 정보를 자동으로 알 수 있는 표준적인 방법이 없다.
    • setup.py파일에 저장되어 있지만, 파일을 실행하지 않고는 내용을 알 수 없다.

toml 예제

# build-system : 빌드 백엔드를 지정하는 키가 포함되어 있다.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "spam-eggs"
version = "2020.0.0"
dependencies = [
  "httpx",
  "gidgethub[httpx]>4.0.0",
  "django>2.1; os_name != 'nt'",
  "django>2.0; os_name == 'nt'",
]
requires-python = ">=3.8"

# authors / maintainers : 작성자, 관리자
authors = [
  {name = "Pradyun Gedam", email = "pradyun@example.com"},
  {name = "Tzu-Ping Chung", email = "tzu-ping@example.com"},
  {name = "Another person"},
  {email = "different.person@example.com"},
]
maintainers = [
  {name = "Brett Cannon", email = "brett@example.com"}
]

# description : PyPI의 프로젝트 페이지의 헤더 및 검색 결과에 소개되는 한 줄 설명
description = "Lovely Spam! Wonderful Spam!"

# readme : PyPI 프로젝트 페이지에 표시되는 프로젝트에 대한 긴 설명
readme = "README.rst"

# license : 잘 알려진 표준 라이센스를 사용하는 경우에는 해당 필드가 필요 없음.
license = {file = "LICENSE.txt"}

# keywords : PyPI 검색 시 프로젝트를 찾을 수 있도록 도와주는 키워드
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]

# classifiers : 프로젝트에 적용할 수 있는 PyPI 분류
classifiers = [
  "Development Status :: 4 - Beta",
  "Programming Language :: Python"
]

[project.optional-dependencies]
gui = ["PyQt5"]
cli = [
  "rich",
  "click",
]

# urls : PyPI 프로젝트 페이지의 왼쪽 사이드바에 표시되는 프로젝트와 연결된 URL 목록
[project.urls]
Homepage = "https://example.com"
Documentation = "https://readthedocs.org"
Repository = "https://github.com/me/spam.git"
"Bug Tracker" = "https://github.com/me/spam/issues"
Changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md"

# 이 명령을 실행하면 다음과 같은 작업이 수행됩니다. from spam import main_cli; main_cli().
[project.scripts]
spam-cli = "spam:main_cli"

# project.scripts와 project.gui-scripts차이는 windows에서만 존재한다.
[project.gui-scripts]
spam-gui = "spam:main_gui"

# Advanced plugins
[project.entry-points."spam.magical"]
tomatoes = "spam:main_tomatoes"

출처

Poetry

poetry

 

poetry

Python dependency management and packaging made easy.

pypi.org

Python Poetry, finally easy build and deploy packages

 

Python Poetry, finally easy build and deploy packages

Until now to build a python package we needed to have a bit complex structure of files like this one

medium.com

PEP 517 – A build-system independent format for source trees | peps.python.org

 

PEP 517 – A build-system independent format for source trees | peps.python.org

While distutils / setuptools have taken us a long way, they suffer from three serious problems: (a) they’re missing important features like usable build-time dependency declaration, autoconfiguration, and even basic ergonomic niceties like DRY-compliant.

peps.python.org

PEP 518 – Specifying Minimum Build System Requirements for Python Projects | peps.python.org

 

PEP 518 – Specifying Minimum Build System Requirements for Python Projects | peps.python.org

This PEP specifies how Python software packages should specify what build dependencies they have in order to execute their chosen build system. As part of this specification, a new configuration file is introduced for software packages to use to specify...

peps.python.org

poetry 의 거의 모든것 (튜토리얼)

 

poetry 의 거의 모든것 (튜토리얼)

poetry 로 가상환경을 구축하는 방법을 단계별로 설명합니다.

teddylee777.github.io

 

Wheel

wheel

 

wheel

A built-package format for Python

pypi.org

PEP 427 – The Wheel Binary Package Format 1.0 | peps.python.org

 

PEP 427 – The Wheel Binary Package Format 1.0 | peps.python.org

This PEP describes a built-package format for Python called “wheel”.

peps.python.org

https://github.com/pypa/wheel

 

GitHub - pypa/wheel: The official binary distribution format for Python

The official binary distribution format for Python - pypa/wheel

github.com

wheel: 파이썬의 표준 바이너리 배포 포멧

 

wheel: 파이썬의 표준 바이너리 배포 포멧

wheel[^wheel]은 Python의 패키지 배포 표준 중 하나로, 패키지 설치를 보다 빠르고 쉽게 만들어주는 바이너리 패키지 형식입니다. wheel의 주요 특징과 예제를…

wikidocs.net

WHL 파일 형식 - Python 휠 패키지 파일

 

WHL 파일 형식 - Python 휠 패키지 파일

WHL 파일 형식과 WHL 파일을 만들고 열 수 있는 API에 대해 알아보세요.

docs.fileformat.com

PIP

pip documentation v24.2

https://github.com/pypa/pip

 

GitHub - pypa/pip: The Python package installer

The Python package installer. Contribute to pypa/pip development by creating an account on GitHub.

github.com

venv

venv — Creation of virtual environments

 

venv — Creation of virtual environments

Source code: Lib/venv/ The venv module supports creating lightweight “virtual environments”, each with their own independent set of Python packages installed in their site directories. A virtual en...

docs.python.org

virtualenv

.toml

Writing your pyproject.toml - Python Packaging User Guide

 

 

반응형
코드플리