为什么“python setup.py sdist”会这样?创建不需要的“PROJECT-egg.info”在项目根目录下?
当我运行时,
python setup.py sdist
它会在我的 ./dist 目录中创建一个 sdist 。这包括我的“dist”文件夹内的 zip 中的“PROJECT-egg.info”文件,我不使用该文件,但它不会伤害我,所以我只是忽略它。
我的问题是为什么它还在我的项目根目录中创建一个“PROJECT-egg.info”文件夹?我可以让它停止创建这个吗?如果没有,我可以在创建 sdist 后立即将其删除吗?
我正在使用从 setuptools 导入的“setup”功能。 WindowsXP、Python2.7、Setuptools 0.6c11、分发 0.6.14。
我的设置配置如下:
{'author': 'Jonathan Hartley',
'author_email': '[email protected]',
'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}
When I run
python setup.py sdist
it creates an sdist in my ./dist directory. This includes a "PROJECT-egg.info" file in the zip inside my "dist" folder, which I don't use, but it doesn't hurt me, so I just ignore it.
My question is why does it also create a "PROJECT-egg.info" folder in my project root directory? Can I make it stop creating this? If not, can I just delete it immediately after creating the sdist?
I'm using the 'setup' function imported from setuptools.
WindowsXP, Python2.7, Setuptools 0.6c11, Distribute 0.6.14.
My setup config looks like:
{'author': 'Jonathan Hartley',
'author_email': '[email protected]',
'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}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
该目录是作为源发行版构建过程的一部分有意创建的。稍微浏览一下 setuptools 开发人员指南,您就会得到以下提示:为什么:
构建完成后,您可以安全地删除该目录。
额外编辑:
我在许多 Python 项目的
setup.py
中自定义了clean
命令来删除*.egg-info
、dist
、build
和*.pyc
等文件。下面是一个如何在 setup.py 中完成的示例:为了说明这一点,在一个名为“poop”的虚拟项目上运行
python setup.py build
后(是的,我是非常成熟),会发生这种情况:现在如果我们运行 python setup.py clean:
Tada!
This directory is created intentionally as part of the build process for a source distribution. A little gander at the developer guide for setuptools gives you a hint as to why:
You may safely delete the directory after your build has completed.
Bonus edit:
I customize the
clean
command within mysetup.py
on many of my Python projects to delete*.egg-info
,dist
,build
, and*.pyc
and other files. Here's an example of how it's done insetup.py
:To illustrate, after running
python setup.py build
on a dummy project called "poop" (Yes, I'm very mature), this happens:And now if we run
python setup.py clean
:Tada!
-egg.info
文件夹并不总是您可以删除的临时工件。例如,如果您使用
pip install -e YOURPACKAGE
进行“可编辑”安装(通过像python setup.pydevelop
这样的符号链接工作,因此您不必重新安装每次在本地编辑包时都会安装一个包),当您的包导入到另一个源中时,运行时需要-egg.info
文件夹。如果它不存在,您将收到DistributionNotFound
错误。The
-egg.info
folder isn't always a temporary artifact you can delete.For example, if you use
pip install -e YOURPACKAGE
for an "editable" install (works via symlink likepython setup.py develop
so you don't have to re-install a package every time you edit it locally), the-egg.info
folder is required at runtime when your package is imported in another source. If it doesn't exist, you will get aDistributionNotFound
error.请注意,您可以让
PROJECT.egg-info
工件从您的 sdist 中完全消失。命令
setup.py Egg_info
默认情况下将使用源根目录作为 Egg 库,从而将PROJECT.egg-info
目录打包到 sdist 中。您可以通过传递选项
--egg-base
来配置egg基础。这将在其他位置创建
PROJECT.egg-info
目录,将其完全排除在源代码发行版之外。您还可以使用 setup.cfg 来设置该属性。以下命令可以在没有
PROJECT.egg-info
的情况下创建 sdist:或者在
setup.cfg
中:Note that you can have the
PROJECT.egg-info
artifacts disappear completely from your sdist.The command
setup.py egg_info
will use the source root as the egg base by default, resulting in thePROJECT.egg-info
directory being packaged into the sdist.You can configure the egg base by passing the option
--egg-base
.This will create the
PROJECT.egg-info
directory somewhere else, leaving it out of your source distribution completely. You might also use asetup.cfg
to set that property.The following command to create a sdist without a
PROJECT.egg-info
works for me:Or in a
setup.cfg
:恕我直言,Python 的打包和构建系统已损坏。因此,对于人们认为开箱即用的事情,有许多技巧和解决方法。
然而,我发现删除 *.egg-info 的“最干净”的黑客方法是使用正常的
clean --all
开关以及egg_info
来放置 *.egg -info 文件位于将由 clean 命令清理的子文件夹中。这里有一个例子:在您的
setup.cfg
中使用类似这样的内容:其中
./build/lib
是clean --all
将要使用的文件夹删除。然后,当使用 setuptools 构建项目时,请使用带有 --all 标志的 clean 命令,例如python setup.py bdist_wheel clean --all
如果您还想构建源包,只需确保构建bdist_wheel 在 sdist 之前,因此 build/lib 文件夹存在,例如:
python setup.py bdist_wheel sdist clean --all
Pythons packaging and build system is broken imho. So there are many hacks and workarounds for things that one would belive work out of the box.
However, the "cleanest" hack I found for deleting the *.egg-info is using the normal
clean --all
switch along with theegg_info
to place the *.egg-info file in a subfolder that will be cleaned by the clean command. Here an example:In your
setup.cfg
use something like this:where
./build/lib
is a folder thatclean --all
will delete. Then when building your project with setuptools use the clean command with the --all flag, e.g.python setup.py bdist_wheel clean --all
if you want to build a source bundle as well just make sure to build bdist_wheel before sdist so the build/lib folder exists, e.g.:
python setup.py bdist_wheel sdist clean --all
jathanism 的方法可能是使用 egg_info 钩子。我用它在每次构建之前进行清理:
An alternative solution to jathanism's method could be the usage of the egg_info hook. I use it to clean up before each build: