gpt4 book ai didi

python - 为什么 "python setup.py sdist"会在项目根目录中创建不需要的 "PROJECT-egg.info"?

转载 作者:IT老高 更新时间:2023-10-28 20:36:30 25 4
gpt4 key购买 nike

当我运行时

  python setup.py sdist

它在我的 ./dist 目录中创建一个 sdist。这包括我的“dist”文件夹内的 zip 中的“PROJECT-egg.info”文件,我不使用它,但它不会伤害我,所以我忽略了它。

我的问题是为什么它在我的项目根目录中创建一个“PROJECT-egg.info”文件夹?我可以让它停止创建这个吗?如果没有,我可以在创建 sdist 后立即删除它吗?

我正在使用从 setuptools 导入的“setup”功能。WindowsXP、Python2.7、Setuptools 0.6c11、Distribute 0.6.14。

我的设置配置如下:

{'author': 'Jonathan Hartley',
'author_email': 'tartley@tartley.com',
'classifiers': ['Development Status :: 1 - Planning',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 2.7'],
'console': [{'script': 'demo.py'}],
'data_files': [('Microsoft.VC90.CRT',
['..\\lib\\Microsoft.VC90.CRT\\Microsoft.VC90.CRT.manifest',
'..\\lib\\Microsoft.VC90.CRT\\msvcr90.dll'])],
'description': 'Utilities for games and OpenGL graphics, built around Pyglet.\n',
'keywords': '',
'license': 'BSD',
'long_description': "blah blah blah",
'name': 'pygpen',
'options': {'py2exe': {'ascii': True,
'bundle_files': 1,
'dist_dir': 'dist/pygpen-0.1-windows',
'dll_excludes': [],
'excludes': ['_imaging_gif',
'_scproxy',
'clr',
'dummy.Process',
'email',
'email.base64mime',
'email.utils',
'email.Utils',
'ICCProfile',
'Image',
'IronPythonConsole',
'modes.editingmodes',
'startup',
'System',
'System.Windows.Forms.Clipboard',
'_hashlib',
'_imaging',
'_multiprocessing',
'_ssl',
'_socket',
'bz2',
'pyexpat',
'pyreadline',
'select',
'win32api',
'win32pipe',
'calendar',
'cookielib',
'difflib',
'doctest',
'locale',
'optparse',
'pdb',
'pickle',
'pyglet.window.xlib',
'pyglet.window.carbon',
'pyglet.window.carbon.constants',
'pyglet.window.carbon.types',
'subprocess',
'tarfile',
'threading',
'unittest',
'urllib',
'urllib2',
'win32con',
'zipfile'],
'optimize': 2}},
'packages': ['pygpen'],
'scripts': ['demo.py'],
'url': 'http://code.google.com/p/edpath/',
'version': '0.1',
'zipfile': None}

最佳答案

此目录是作为源代码分发构建过程的一部分而有意创建的。稍微看看 developer guide for setuptools提示您原因:

But, be sure to ignore any part of the distutils documentation that deals with MANIFEST or how it's generated from MANIFEST.in; setuptools shields you from these issues and doesn't work the same way in any case. Unlike the distutils, setuptools regenerates the source distribution manifest file every time you build a source distribution, and it builds it inside the project's .egg-info directory, out of the way of your main project directory. You therefore need not worry about whether it is up-to-date or not.

您可以在构建完成后安全地删除该目录。

奖金编辑:

我在我的许多 Python 项目的 setup.py 中自定义 clean 命令以删除 *.egg-infodistbuild*.pyc 等文件。这是一个在 setup.py 中如何完成的示例:

import os
from setuptools import setup, Command

class CleanCommand(Command):
"""Custom clean command to tidy up the project root."""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info')

# Further down when you call setup()
setup(
# ... Other setup options
cmdclass={
'clean': CleanCommand,
}
)

为了说明,在一个名为“poop”的虚拟项目上运行 python setup.py build 后(是的,我很成熟),会发生这种情况:

$ python setup.py build
running build
running build_py
creating build
creating build/lib
creating build/lib/poop
copying poop/__init__.py -> build/lib/poop

现在如果我们运行 python setup.py clean:

$ python setup.py clean
running clean
removed `./build/lib/poop/__init__.py'
removed directory: `./build/lib/poop'
removed directory: `./build/lib'
removed directory: `./build'

多田!

关于python - 为什么 "python setup.py sdist"会在项目根目录中创建不需要的 "PROJECT-egg.info"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3779915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com