设置的 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/