setuptools 的麻烦——排除包,包括数据文件 [英] setuptools troubles -- excluding packages, including data files

查看:32
本文介绍了setuptools 的麻烦——排除包,包括数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 setuptools 还很陌生.我看到了一些类似的问题,这让我有点疯狂,因为我似乎遵循了我看到的建议,但 setuptools 仍然做一些与我想要的不同的事情.

这是我的项目结构:

<预><代码>...包1/__init__.pyabc.py...测试/__init__.pytest_package1.py执照自述文件发布设置文件

这是我的 setup.py 的内容:

#!/usr/bin/env python导入操作系统#from distutils.core 导入设置从 setuptools 导入设置,find_packages设置(名称='包1',版本='1.1',test_suite="测试",包=find_packages(exclude=['tests']),include_package_data=真,包数据 = {'': ['许可证', 'README.md5', '发布']},)

此外,在我的清单文件中,我有:

包括许可证包括发布包括 README.md

我使用以下方法构建 tar:

python setup.py sdist

我想:

  1. 从源代码分发中排除 tests 目录;
  2. 在 site-packages 目录中拥有 LICENSE、README.md、RELEASE 文件,无论是在顶层,还是在 package1 目录中(此时我都会同意).

相反,会发生以下情况:

  1. tests 目录仍保留在创建的 tar 存档中并安装到站点包中;
  2. 文件会复制到存档中,但不会安装到包的站点打包目录中.

我没有想法,有人可以向我解释我做错了什么以及如何解决吗?

解决方案

您应该在包的根级别创建一个名为 MANIFEST.in 的新文件,然后按照以下说明操作:

  1. 要控制哪些文件最终出现在 tar 文件中,请在包的根级别创建一个名为 MANIFEST.in 的新文件.例如,您可以使用 MANIFEST.in 文件中的 recursive-exclude 从发行版中排除整个目录.在您的情况下,您需要 MANIFEST.in 文件包含:

    递归排除测试 *

  2. 在 site-packages 目录中包含 README 和其他文件并不常见,但如果您真的想要,请进入 package1 并创建指向您想要的文件的符号链接包括:

    cd package1ln -s ../许可证ln -s ../README.mdln -s ../发布

    然后在 setup.py 中更改以下行:

    package_data = {'': ['许可证', 'README.md', '发布']

    到:

    package_data = {'package1': ['许可证'、'README.md'、'发布']

I'm fairly new to setuptools. I've seen a few similar questions and it drives a little bit insane that I've seemed to follow advice I saw but setuptools still does something different than what I want.

Here is the structure of my project:

.
..
package1/
    __init__.py
    abc.py
    ...
tests/
    __init__.py
    test_package1.py
LICENSE
README.md
RELEASE
setup.py

And here is the contents of my setup.py:

#!/usr/bin/env python
import os
#from distutils.core import setup
from setuptools import setup, find_packages

setup(
    name='package1',
    version='1.1',
    test_suite="tests",
    packages=find_packages(exclude=['tests']),    
    include_package_data=True,
    package_data = {
        '': ['LICENSE', 'README.md5', 'RELEASE']
    },   
)

Also, in my manifest file I have:

include LICENSE
include RELEASE
include README.md

I build the tar with:

python setup.py sdist

I want to:

  1. Exclude tests directory from the source distribution;
  2. Have LICENSE, README.md, RELEASE files in the site-packages directory, either at the top level, or inside the package1 directory (at this point I will agree to either).

Instead, here's what happens:

  1. tests directory remains to be in the created tar archive and gets installed to the site-packages;
  2. Files are copied to the archive, but do not get installed to the site-packaged directory of the package.

I am out of ideas, can someone explain to me what I am doing wrong and how to fix it?

解决方案

You should create a new file called MANIFEST.in in the root level of your package, then follow these instructions:

  1. To control which files end up in your tar file, create a new file called MANIFEST.in in the root level of your package. For example, you can exclude whole directories from your distribution, using recursive-exclude in the MANIFEST.in file. In your case, you need your MANIFEST.in file to contain:

    recursive-exclude tests *
    

  2. It's not common to include README and other files in the site-packages directory, but if you really want to, then go inside package1 and create symbolic links to the files you want to include:

    cd package1
    ln -s ../LICENSE
    ln -s ../README.md
    ln -s ../RELEASE
    

    Then change the following line in your setup.py:

    package_data = {
        '': ['LICENSE', 'README.md', 'RELEASE']
    

    to:

    package_data = {
        'package1': ['LICENSE', 'README.md', 'RELEASE']
    

这篇关于setuptools 的麻烦——排除包,包括数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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