6

所以我正在制作 setuptool 包。

要在包中包含额外的数据文件,我需要在data_file里面指定参数setup()

代码示例:

datadir = os.path.join('share','data')
datafiles = [(datadir, [f for f in glob.glob(os.path.join(datadir, '*'))])]
import metainfo # a file with relevant information
setup(
    name             = 'yourpackage',
    version          = metainfo.version,
    maintainer       = metainfo.maintainer,
    maintainer_email = metainfo.maintainer_email,
    author           = metainfo.authors,
    author_email     = metainfo.authors,
    description      = metainfo.description,
    keywords         = metainfo.keywords,
    long_description = metainfo.long_description,

    # package installation
    packages = find_packages('src'),
    package_dir  = package_dir,

    data_files = datafiles,
}

datafile本例中的变量将包含这样的数据

[('share/data', ['share/data/addon.xml.tmplt', 'share/data/default.py.tmplt'])]

但是,我的示例不会递归地列出文件夹和包含文件。

我需要作为参数 folder_path 并返回元组列表的函数:

[
    ('share/data', ['share/data/addon.xml.tmplt', 'share/data/default.py.tmplt']),
    ('share/data/inside', ['share/data/inside/file.iside', 'share/data/inside/file2.inside']),
    .........

]
4

1 回答 1

10

用于os.walk()生成该信息:

datafiles = [(root, [os.path.join(root, f) for f in files])
    for root, dirs, files in os.walk(datadir)]

这将产生绝对路径;如果需要,您可以root多处理变量以使它们相对于setup.py目录。

于 2012-11-29T15:26:49.740 回答