Transition from existing python packaging infrastructure

Even if you are convinced than bento is more appropriate for your needs than current distutils-based tools, there is a significant hurdle to transition to a new infrastructure for your package. First, you need to convert your package, but you also potentially loose goodies such a putting your package on pypi, or being installable through tools such as pip or easy_install.

Ideally, such tools would become pluggable so that they can be made aware of new packaging formats, but in the mean-time, the practical approach of bento is to “emulate” distutils just enough to make them work with the most useful bits of the current python packaging infrastructure, and to provide tools to convert existing to the bento format.

Converting distutils-based packages

The bentomaker command-line tool has a convert command which should be run at the top of your source tree (the directory containing your top Because the convert command works by running the, you need to make sure you can run the To convert your package, just do:

bentomaker convert

If successfull, this will write a file whose content has been pulled of the convert command analysis (it will not overwrite an existing one). It first tries to determine whether your uses setuptools or not, and then run it with mocked distutils objects for the actual conversion. Since the convert command works by inserting various hooks into distutils internals, it is inherently fragile.

It will definitely not work in the following cases:

  • you use the package_dir feature: bento does not support the feature at all.
  • you have your own distutils extensions (setuptools and numpy.distutils are somehow handled, though, and other common distutils extensions may be added as well).

It should support the following features:

  • All the distutils metadata
  • Some setuptools metadata (like require or console scripts)
  • module, packages and extensions
  • data files as specified in data_files
  • source files in MANIFEST[.in]

Note:: because the convert command does not parse the, but runs it instead, it only handles package description as defined by this one run of For example, bento convert cannot automatically handle the following

import sys
from setuptools import setup

if sys.platform == "win32":
    requires = ["sphinx", "pywin32"]
    requires = ["sphinx"]

setup(name="foo", install_requires=requires)

If run on windows, the generated will be:

Name: foo



Name: foo



Note:: bento syntax supports simple conditional, so after conversion, you could modify the generated file as follows:

Name: foo

    if os(win32):

Adding bento-based for compatibility with pip, etc...

Although nothing fundamentally prevents bento to work under installers such as pip, pip currently does not know anything about bento. To help transition, bento has a distutils compatibility layer. A as simple as:

import setuptools
from bento.distutils.monkey_patch import monkey_patch

from setuptools import setup

if __name__ == '__main__':

will enable commands such as:

python install
python sdist

to work as expected, taking all the package information from file. Note that the monkey-patching done by bento.distutils on top of setuptools is explicit - solely importing bento.distutils will not monkey patch anything. A simpler, setuptools-style monkey patch is also possible:

import setuptools
from bento.distutils.monkey_patch import setup

if __name__ == '__main__':

Note:: obviously, this mode will not enable all the features offered by bento. If it were possible, bento would not have been written in the first place. Nevertheless, the following commands should work relatively well as long as you don’t have hooks:

  • sdist
  • bdist_egg
  • install

This should be enough for pip install foo or easy_install foo to work for a bento-based package.

当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
若有不妥, 欢迎评注提醒:


订阅 substack 体验古早写作:

点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:


关于 ~ DebugUself with DAMA ;-)
公安备案号: 44049002000656 ...::