python - 在 python setup.py data_files 中包含整个目录

标签 python setup.py

设置的 data_files 参数采用以下格式输入:

setup(...
    data_files = [(target_directory, [list of files to be put there])]
    ....)

有没有一种方法可以让我指定整个数据目录,这样我就不必单独命名每个文件并在我更改项目中的实现时更新它?

我尝试使用 os.listdir(),但我不知道如何使用相对路径,我不能使用 os.getcwd()os.realpath(__file__) 因为它们没有正确指向我的存储库根目录。

最佳答案

karelv 的想法是正确的,但要更直接地回答所述问题:

from glob import glob

setup(
    #...
    data_files = [
        ('target_directory_1', glob('source_dir/*')), # files in source_dir only - not recursive
        ('target_directory_2', glob('nested_source_dir/**/*', recursive=True)), # includes sub-folders - recursive
        # etc...
    ],
    #...
)

关于python - 在 python setup.py data_files 中包含整个目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27829754/

相关文章:

python - 包导入创建一个模块,子模块仍然可导入

python - 如何覆盖 PBR 中的要求?

Python代码用setuptools打包并用pip安装后看不到数据文件

python - 我应该使用哪些模块来创建游戏树?

python - django 自定义登录 View 和 django 自定义身份验证后端之间的区别?

python - 属性错误 : 'str' object has no attribute 'public_blob'

python - conda : Installing directly from github yields ERROR File "setup.py" not found for legacy project

python - setup.py 中的 2 到 3 没有涵盖测试?

python - opencv python 中的轮廓近似每次都会给出错误的结果

python - 使用 "Strptime()"在 Python 中显示时间