【发布时间】:2021-02-24 20:20:24
【问题描述】:
我有以下python项目结构:
.
├ setup.py
├ doc
| ├ file.css
| ├ file.html
| └ file.js
└ src
├ matlabsources
| └ <several folders architecture with .m and .slx files>
└ mypythonpackage
├ __init__.py
└ <several sub packages architecture with python files>
我想将 doc 文件夹中的所有文件添加到我的 whl 分发文件中。
setuptools.setup(
name='myproject',
author='me',
packages=setuptools.find_packages(where='src', include=['packages*']),
package_dir={'': 'src'},
data_files ={'documentation': find_data_files('doc'), 'matlab': find_data_files('src/matlabsources')},
include_package_data=True,
install_requires=make_deps(REQS_FILENAME),
python_requires='>= 2.7', # Only compatible with Python 2.7.* and 3+
use_scm_version={'version_scheme': simple_version}, # setuptools_scm: the blessed package to manage your versions by scm tags
setup_requires=make_deps(SETUP_FILENAME),
cmdclass=dict(bdist_egg=custom_bdist_egg, build=custom_build, activateIniGeneration=activateIniGeneration)
)
def find_data_files(directory):
"""
Using glob patterns in ``package_data`` that matches a directory can
result in setuptools trying to install that directory as a file and
the installation to fail.
This function walks over the contents of *directory* and returns a list
of only filenames found.
"""
strip = os.path.dirname(os.path.abspath(__file__))
result = []
for root, dirs, files in os.walk(directory):
for filename in files:
filename = os.path.join(root, filename)
result.append(os.path.relpath(filename, strip))
print("\n".join(result))
return result
我收到以下错误:
error: can't copy 'documentation': doesn't exist or not a regular file
据我了解,'documentation'是目标目录,相对于sys.prefix,不存在是正常的。
我正在使用以下命令进行构建:
python setup.py bdist_wheel --universal
我也有这个警告
warning: install_data: setup script did not provide a directory for 'documentation' -- installing right in 'build\bdist.win32\wheel\myproject-1.7.z_gfdc81e60.d20201112.data\data'
这让我觉得我需要对我的setup.py 进行进一步配置才能使其工作
我哪里错了?
【问题讨论】:
-
为什么?为什么要将文档添加到 wheel 文件中?您还想要安装 doc 文件吗?您希望将 doc 文件安装在哪里?谁将访问这些文件?文件将如何被访问? ——我在问,因为这是一个不寻常的问题,我不确定最终目标是什么。知道目的是什么,将有助于为您提供更有用的答案。
-
是的,我想安装 doc 文件,为此必须将它们添加到 wheel 文件中,对吗?还是有其他方法?我简化了示例,但它们也是要安装的 matlab 文件,这些文件是从 python 包中访问的。文件应与源包放置在同一级别。
-
我建议你看看
package_data。我总结了here。 StackOverflow 上还有其他重复的问题。如果你显示你的目录结构,我可能可以在这里写下一个真正的答案。 -
只是为了确保,您希望保留此目录结构,但希望将
doc和matlabsources作为mypythonpackage的子包安装。那正确吗?所以在site-packages目录中,你想让它们分别为[...]/site-packages/mypythonpackage/doc和[...]/site-packages/mypythonpackage/matlabsources?如果没有,请编辑问题以显示安装后的预期目录结构。
标签: python setuptools data-files