为什么“python setup.py sdist”会这样?创建不需要的“PROJECT-egg.info”在项目根目录下?

发布于 2024-09-25 03:04:31 字数 3996 浏览 12 评论 0原文

当我运行时,

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

吃不饱 2024-10-02 03:04:31

该目录是作为源发行版构建过程的一部分有意创建的。稍微浏览一下 setuptools 开发人员指南,您就会得到以下提示:为什么:

但是,请务必忽略其中的任何部分
distutils 文档处理
与 MANIFEST 或它的生成方式
来自 MANIFEST.in;安装工具盾牌
你免受这些问题的困扰,但不起作用
无论如何都以同样的方式。与
distutils、setuptools 重新生成
源分发清单文件
每次构建源代码时
分布,并在内部构建它
项目的 .egg-info 目录,out
你的主要项目的方式
目录。因此您无需
担心它是否是最新的
或不。

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

额外编辑:

我在许多 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'

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:

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.

You may safely delete the directory after your build has completed.

Bonus edit:

I customize the clean command within my setup.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 in 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,
    }
)

To illustrate, after running python setup.py build on a dummy project called "poop" (Yes, I'm very mature), this happens:

$ 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

And now if we run 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'

Tada!

谁的年少不轻狂 2024-10-02 03:04:31

-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 like python 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 a DistributionNotFound error.

池木 2024-10-02 03:04:31

请注意,您可以让 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:

python setup.py egg_info --egg-base /tmp sdist

或者在 setup.cfg 中:

[egg_info]
egg_base = /tmp

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 the PROJECT.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 a setup.cfg to set that property.

The following command to create a sdist without a PROJECT.egg-info works for me:

python setup.py egg_info --egg-base /tmp sdist

Or in a setup.cfg:

[egg_info]
egg_base = /tmp
厌倦 2024-10-02 03:04:31

恕我直言,Python 的打包和构建系统已损坏。因此,对于人们认为开箱即用的事情,有许多技巧和解决方法。

然而,我发现删除 *.egg-info 的“最干净”的黑客方法是使用正常的 clean --all 开关以及 egg_info 来放置 *.egg -info 文件位于将由 clean 命令清理的子文件夹中。这里有一个例子:

在您的 setup.cfg 中使用类似这样的内容:

[egg_info]
egg_base = ./build/lib

其中 ./build/libclean --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 the egg_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:

[egg_info]
egg_base = ./build/lib

where ./build/lib is a folder that clean --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

城歌 2024-10-02 03:04:31

jathanism 的方法可能是使用 egg_info 钩子。我用它在每次构建之前进行清理:

from pathlib import Path
from setuptools import setup
from setuptools.command.egg_info import egg_info

here = Path(__file__).parent.resolve()

class CleanEggInfo(egg_info):
    def run(self):
       shutil.rmtree(here.joinpath('build'), ignore_errors=True)
       shutil.rmtree(here.joinpath('dist'), ignore_errors=True)

        for d in here.glob('*.egg-info'):
            shutil.rmtree(d, ignore_errors=True)

        egg_info.run(self)

setup(
    cmdclass={
        'egg_info': CleanEggInfo,
    }
)

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:

from pathlib import Path
from setuptools import setup
from setuptools.command.egg_info import egg_info

here = Path(__file__).parent.resolve()

class CleanEggInfo(egg_info):
    def run(self):
       shutil.rmtree(here.joinpath('build'), ignore_errors=True)
       shutil.rmtree(here.joinpath('dist'), ignore_errors=True)

        for d in here.glob('*.egg-info'):
            shutil.rmtree(d, ignore_errors=True)

        egg_info.run(self)

setup(
    cmdclass={
        'egg_info': CleanEggInfo,
    }
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文