【发布时间】:2014-09-05 13:21:44
【问题描述】:
当 pip installing 具有自定义 build_py 命令的项目时,该命令会在构建目录中生成一个附加文件,安装时 pip 生成的 installed-files.txt 文件不会列出生成的文件。结果,当我卸载发行版时,它会留下我生成的文件。
我想我无法以某种方式注册生成的文件,但我找不到任何有关如何执行此操作的文档。
我必须进行哪些更改才能使 pip 的 installed-files.txt 列出我生成的文件?
复制步骤
创建以下文件系统条目。
已安装的文件缺失项目 ├── install-entry-missing │ └── __init__.py └── setup.py将以下内容放入setup.py。
import os
from setuptools import setup
from setuptools.command.build_py import build_py
def touch(fname, times=None):
with open(fname, 'a'):
os.utime(fname, times)
class my_build_py(build_py):
def run(self):
if not self.dry_run:
target_dir = os.path.join(self.build_lib, "install-entry-missing")
self.mkpath(target_dir)
touch(os.path.join(target_dir, "my_file.txt"))
# TODO: missing registration of "my_file.txt"?
build_py.run(self)
setup_args = dict(
name='install-entry-missing',
version='1.0.0',
description='',
author='author',
author_email='author@example.com',
packages = ["install-entry-missing"],
cmdclass={'build_py': my_build_py}
)
if __name__ == '__main__':
setup(**setup_args)
从install-entry-missing-project 目录,运行pip install .。
安装的目录将包含 my_file.txt 和 __init__.py。但是,检查 egg-info 目录的 installed-files.txt 将显示 my_file.txt 未列出。因此,pip uninstall install-entry-missing 将删除 __init__.py 而不是 my_file.txt。
【问题讨论】:
标签: python python-2.7 pip