pip < 1.2 (Ubuntu 12.04 など) のユーザーがいる場合にのみ必要な setup.py を以下に文書化します。誰もが pip 1.2 以降を持っている場合、必要なのはpackages=[..., 'twisted.plugins']
.
pip が行 " twisted
" を.egg-info/top_level.txt
に書き込まないようにすることで、 を引き続き使用し、すべてを削除しないpackages=[..., 'twisted.plugins']
作業を行うことができます。これには、ファイルの上部近くで setuptools/distribute にモンキーパッチを適用することが含まれます。ここにサンプルがあります:pip uninstall
twisted/
setup.py
setup.py
from distutils.core import setup
# When pip installs anything from packages, py_modules, or ext_modules that
# includes a twistd plugin (which are installed to twisted/plugins/),
# setuptools/distribute writes a Package.egg-info/top_level.txt that includes
# "twisted". If you later uninstall Package with `pip uninstall Package`,
# pip <1.2 removes all of twisted/ instead of just Package's twistd plugins.
# See https://github.com/pypa/pip/issues/355 (now fixed)
#
# To work around this problem, we monkeypatch
# setuptools.command.egg_info.write_toplevel_names to not write the line
# "twisted". This fixes the behavior of `pip uninstall Package`. Note that
# even with this workaround, `pip uninstall Package` still correctly uninstalls
# Package's twistd plugins from twisted/plugins/, since pip also uses
# Package.egg-info/installed-files.txt to determine what to uninstall,
# and the paths to the plugin files are indeed listed in installed-files.txt.
try:
from setuptools.command import egg_info
egg_info.write_toplevel_names
except (ImportError, AttributeError):
pass
else:
def _top_level_package(name):
return name.split('.', 1)[0]
def _hacked_write_toplevel_names(cmd, basename, filename):
pkgs = dict.fromkeys(
[_top_level_package(k)
for k in cmd.distribution.iter_distribution_names()
if _top_level_package(k) != "twisted"
]
)
cmd.write_file("top-level names", filename, '\n'.join(pkgs) + '\n')
egg_info.write_toplevel_names = _hacked_write_toplevel_names
setup(
name='MyPackage',
version='1.0',
description="You can do anything with MyPackage, anything at all.",
url="http://example.com/",
author="John Doe",
author_email="jdoe@example.com",
packages=['mypackage', 'twisted.plugins'],
# You may want more options here, including install_requires=,
# package_data=, and classifiers=
)
# Make Twisted regenerate the dropin.cache, if possible. This is necessary
# because in a site-wide install, dropin.cache cannot be rewritten by
# normal users.
try:
from twisted.plugin import IPlugin, getPlugins
except ImportError:
pass
else:
list(getPlugins(IPlugin))
pip install
、pip install --user
、および でこれをテストしましたeasy_install
。どのインストール方法でも、上記の monkeypatch と正常にpip uninstall
動作します。
次のインストールを台無しにしないために、monkeypatch をクリアする必要があるのでしょうか? (例えばpip install --no-deps MyPackage Twisted
; Twisted の に影響を与えたくないでしょうtop_level.txt
。) 答えはノーです。モンキーパッチは、インストールごとpip
に新しいパッチを生成するため、別のインストールには影響しません。python
関連: あなたのプロジェクトには file があってはならない twisted/plugins/__init__.py
ことに注意してください。インストール中にこの警告が表示された場合:
package init file 'twisted/plugins/__init__.py' not found (or not a regular file)
これは完全に正常な動作であり、__init__.py
.