Skip to content

Instantly share code, notes, and snippets.

@knzm
Last active December 30, 2020 14:34
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knzm/5185369 to your computer and use it in GitHub Desktop.
Save knzm/5185369 to your computer and use it in GitHub Desktop.

Python パッケージングのこれまでとこれから

第1世代: distutils

$ python setup.py build
$ python setup.py install
$ python setup.py sdist
$ python setup.py register
$ python setup.py upload

第2世代: setuptools

$ python setup.py bdist_egg
$ python setup.py develop
$ easy_install
$ ez_setup.py

第3世代: distribute & pip

  • distribute = better setuptools
  • pip は easy_install に相当
$ pip install
$ pip search
$ pip freeze      # インストール済みパッケージのリストを出力
$ pip uninstall   # アンインストールもできる!

次世代: distutils2 / packaging

  • distutils を改良したものが distutils2
  • Python のバージョンによって呼び名が変わる
    • Python 3.x => packaging (標準)
    • Python 2.4-3.3 => distutils2 (サードパーティー)
$ pysetup search
$ pysetup install
$ pysetup list
$ pysetup remove
$ pysetup metadata
$ pysetup create
$ generate-setup
$ pysetup run [ build | sdist | bdist | register | upload ]
  • 新標準を実装
    • PEP345: Metadata 1.2
    • PEP376: インストール情報データベース
    • PEP386: バージョン番号標準

次世代: distlib

  • packaging の後継? → No
  • packaging から派生した低レベルライブラリ → Yes

Distlib evolved out of packaging

Distlib is a library which implements low-level functions that relate to packaging and distribution of Python software. It consists in part of the functions in the packaging Python package, which was intended to be released as part of Python 3.3, but was removed shortly before Python 3.3 entered beta testing.

http://pythonhosted.org/distlib/overview.html

次世代: wheel

  • egg に変わる新フォーマット
  • wheel フォーマットを操作するためのライブラリやツールを集めたパッケージの名前でもある
  • 新標準に対応
    • PEP345: Metadata 1.2 (not requires.txt)
    • PEP376: インストール情報データベース (dist-info)

Why not egg?

Python’s egg format predates the packaging related standards we have today, the most important being PEP 376 “Database of Installed Python Distributions” which specifies the .dist-info directory (instead of .egg-info) and PEP 345 “Metadata for Python Software Packages 1.2” which specifies how to express dependencies (instead of requires.txt in .egg-info).

Wheel implements these things. It also provides a richer file naming convention that communicates the Python implementation and ABI as well as simply the language version used in a particular package.

Unlike .egg, wheel will be a fully-documented standard at the binary level that is truly easy to install even if you do not want to use the reference implementation.

http://wheel.readthedocs.org/en/latest/

現状の課題

  • entry points の代替手段
  • egg と wheel は非互換
    • 既存の egg から wheel にどれだけスムーズに移行が進むか
  • pip が egg を扱えない
    • バイナリパッケージをインストールできない
    • wheel への移行で解決?

最近の動き

  • packaging が Python 3.3 に入らなかった
  • pip に wheel 対応コードがマージされた
  • setuptools と distribute が統合される?

関連する PEP

各パッケージの用途と概要 (未完)

distutils

  • Python の標準パッケージ
  • 特徴
    • python setup.py build
    • python setup.py install
    • python setup.py register
    • python setup.py bdist sdist upload
    • egg は作れない

setuptools

  • 作者: Phillip J. Eby (PEAK)
  • distutils の拡張
  • 特徴
    • easy_install コマンドを提供
    • python setup.py bdist_egg
  • 状況: メンテが止まっているように見える

distribute

  • 作者: Tarek Ziade
  • setuptools のフォーク
  • 特徴
    • setuptools と互換
    • setuptools より可読性が高い
    • Python 3 をサポート
  • 状況: setuptools と再度統合される?

pip

  • 作者: Ian Bicking
  • easy_install と同様の機能を提供
  • 特徴
    • pip uninstall
    • pip freeze
    • pip bundle は非推奨
    • 複数バージョンの共存は行わない
    • ソース提供されているパッケージのみインストールできる
    • egg パッケージからのインストールはできない
    • Windows では不安定?
  • 状況: wheel branch がマージされた

wheel

distlib

distutils2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment