使用 setuptool 从构建的 rpm 发行版中排除源文件 [英] Excluding source files from built rpm distribution with setuptool

查看:50
本文介绍了使用 setuptool 从构建的 rpm 发行版中排除源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个典型的项目结构,如下所示:

I have a typical project structure that looks as follows:

EngineEmulator
    src
        ship
            engine
                emulator
                mapping
            tests
                emulator
                mapping
        utils
            common

    doc
       ....
    tools
       ....
    setup.py
    MANIFEST.in
    setup.cfg
    README.rst

我的 setup.py 如下所示:

My setup.py looks as follows:

from setuptools import setup, find_packages
setup(
   name='Engine',
   version=1.0.0,
   description='Engine Project',       
   package_dir={'': 'src'},
   packages=find_packages(
    'src',
    exclude=["*.tests", "*.tests.*", "tests.*", "tests"]),
   install_requires =['pycrypto', 
                      'kombu >=1.1.3'],
   author='Demo',
   author_email='demo@eliza.net'
   license='MIT',
   classifiers=[
    'Topic :: Demo Engine',
    'Development Status:: 3 - Iteration',
    'Programming Language :: Python -2.6'
]

)

我的 setup.cfg 如下所示:

My setup.cfg looks as follows:

[egg_info]
tag_build = .dev
tag_svn_revision = 1

[rotate]
#keep last 15 eggs, clean up order
match = .egg
keep = 15   

我的 MANIFEST.in 如下所示:

And My MANIFEST.in looks as follows:

include README.rst
recursive-include src/ship/Engine
prune src/utils
prune src/ship/tests
prune tools/

当我运行 python setup.py bdist_eggpython setup.py bdist_rpm 时,我得到了egg 文件和生成的两个 rpm 文件(noarch.rpm 和 src.rpm).

When I run python setup.py bdist_egg and python setup.py bdist_rpm I get the egg file and two rpm files generated (noarch.rpm and src.rpm).

在我的目标机器上,当我运行 easy_install <generated egg file> 我的 eg.info 文件被复制,但源文件没有被复制到/usr/lib/python2.6/站点包.我原以为会有一个名为 Engine 的目录.

In my destination machine when I run easy_install <generated egg file> my eg.info file gets copied over but the source files don't get copied over to /usr/lib/python2.6/site-packages. I was expecting I would have a directory called Engine.

谁能指出我做错了什么?提前致谢.

Can anybody point out what I am doing wrong? Thanks in advance.

推荐答案

尽量让事情变得简单.

试试这个:

$ python setup.py sdist

它将为您的包创建源分发文件.

It shall create source distribution file for your package.

它是 zip 格式,所以解压它并检查里面是否存在所有预期的文件.

It is in zip format, so unpack it and check, if there are all expected files inside present.

如果没有,您必须找到原因,为什么您的发行版中缺少预期文件.

If not, you have to find the reason, why expected files are missing in your distribution.

可能是个愚蠢的问题,但在您的文件列表中,我没有在 src 树中看到任何 py 文件.

May be stupid question, but in your file listing I do not see any py files inside of src tree.

如果您只有没有 .py 扩展名的文件,find_packages 将找不到任何东西.

In case you have there just files without .py extension, find_packages will not find anything.

让我们知道文件在哪里:

Let us know, where the files are:

$ cd src
$ find . -name "*.py"

如果您错过了 __init__.pyfind_packages 将无法找到整个包.

If you miss __init__.py, find_packages will not find whole package.

你为什么把它放在那里?

Why do you have it there?

最好将其安装在您开发的源代码之外或将其移动到您的项目子目录中根.

Better have it installed out of your source code you develop or move it subdirectory in your project root.

这将使 prune src/utils 在您的 MANIFEST.in 中变得不必要.

This will render prune src/utils unnecessary in your MANIFEST.in.

如果您阅读 MANIFEST.in 的文档,它会说明,自动包含哪些文件(全部,什么在 setup 函数的参数中提到,所以在你的情况下,所有 python 源文件返回find_packages).

If you read doc for MANIFEST.in, it states, what files are included automatically (all, what mentioned in arguments of setup function, so in your case all python source files returned by find_packages).

出于这个原因,你应该删除 recursive-include src/shop/Engine 因为它应该已经包含在 setup 调用中.

For this reason, you shall remove recursive-include src/shop/Engine as it shall be already included by setup call.

删除 prune 行.

  • src/utils 不应出现在您的源代码树中 - 它只是把事情搞砸了.
  • tools 不包括在内,因此无需修剪.
  • src/ship/tests 可以在那里,如果你把这些文件保存在分发版中,它不会有什么坏处.
  • src/utils shall not be in your source tree - it is just messing things up.
  • tools is not to be included, so there is no need to prune it.
  • src/ship/tests can be there, it will not harm, if you keep these files in the destribution.

确保您的设置为 packages 提供了正确的名称.

Make sure, your setup get proper names for packages.

为此,您可以更快地调用 find_package 并断言它包含您所期望的内容.

For this purpuse, you can call find_package sooner and assert it containts, what you expect.

只是为了让事情更简单.

Just to keep things simpler.

您应该具有类似如下的文件结构:

You shall have file structure in similar manner as follows:

src/ship/__init__.py
src/ship/engine/__init__.py
src/ship/engine/emulator/__init__.py
src/ship/engine/emulator/module.py
src/ship/engine/emulator/module2.py
src/ship/engine/mapping/other.py
src/ship/engine/mapping/another.py
src/ship/tests/__init__.py
src/ship/tests/emulator/__init__.py
src/ship/tests/emulator/test_module.py
src/ship/tests/emulator/test_module2.py
src/ship/tests/mapping/__init__.py
src/ship/tests/mapping/test_other.py
src/ship/tests/mapping/test_another.py
doc
doc/index.rst
tools
tools/knife.py
setup.py
MANIFEST.in
README.rst

setup.py

from setuptools import setup, find_packages

packages=find_packages("src")
assert "ship.engine" in packages
assert "ship.engine.emulator" in packages
assert "ship.engine.mapping" in packages
#etc

install_requires =['pycrypto', 'kombu>=1.1.3'] #watch the spaces around `>=`, shall not be there

setup(
    name="Engine",
    package_dir={'': 'src'},
    packages=packages,
    install_requires=install_requires
)

MANIFEST.in

include README.rst

结论

可能会发生,运行

Conclusions

It might happen, that running

$ python setup.py sdist

断言会失败.这是标志,缺少一些预期的文件.检查一下.

would fail on asserts. This is sign, some of expected files are missing. Check that.

在您以简单的方式使您的项目生活后,您可能会在周围添加更多细节(并逐步执行)一步一步确保,你不会破坏某些东西).

After you make your project living in simple way, you might add more details around (and do it step by step to be sure, you do not break something).

这篇关于使用 setuptool 从构建的 rpm 发行版中排除源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆