我发现pip运行的python命令行脚本如下所示:
__file__ = '/setup.py'
from setuptools.command import egg_info
def replacement_run(self):
self.mkpath(self.egg_info)
installer = self.distribution.fetch_build_egg
for ep in egg_info.iter_entry_points('egg_info.writers'):
# require=False is the change we're making:
writer = ep.load(require=False)
if writer:
writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name))
self.find_sources()
egg_info.egg_info.run = replacement_run
execfile(__file__)
在软件包的顶级目录中,没有setup.py,我放置了一个可以重现此行为的setup.py,但是chdir到包含“真正的”setup.py的目录,并在最后执行.
唯一的另一个问题是pip创建了一个目标“pip-egg-info”,它希望填充该目录,需要在具有“真实”setup.py的目录中创建一个符号链接.
新的顶级setup.py看起来像这样:
#! /usr/bin/env python
from os import chdir, symlink, getcwd
from os.path import join, basename, exists
filename = basename(__file__)
chdir("python")
setupdir = getcwd()
egginfo = "pip-egg-info"
if not exists(egginfo) and exists(join("..", egginfo)):
symlink(join("..", egginfo), egginfo)
__file__ = join(setupdir, filename)
from setuptools.command import egg_info
def replacement_run(self):
self.mkpath(self.egg_info)
installer = self.distribution.fetch_build_egg
for ep in egg_info.iter_entry_points('egg_info.writers'):
# require=False is the change we're making:
writer = ep.load(require=False)
if writer:
writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name))
self.find_sources()
egg_info.egg_info.run = replacement_run
execfile(__file__)
它可能很脆弱,但应该继续工作,直到pip更改它生成的命令行python代码