草庐IT

python - 在 setup.py (setuptools) 中包含静态数据

coder 2023-08-21 原文

我目前正在使用 setuptools 编写 setup.py。 我想将静态数据(不是 Python 模块)复制到站点包。

问题是,当前文件夹层次结构如下所示:

setup.py
src
    Pure Python Module
skeleton
    example
        __init__.py
    resources
        static
            error.css
            example.css
            logo_shadow.png
        template
            error.html
            example.html
    server.tmplt

我想将框架目录复制到 site-packages 同时保持文件夹结构/层次结构,但我应该怎么做?

最佳答案

我通过单独处理静态文件解决了这个问题,而不是使用设置工具。

from sys import argv
try:
    if argv[1] == 'install':
        from os.path import join
        from distutils.sysconfig import get_python_lib
        from shutil import copytree
        OrigSkeleton = join('src', 'skeleton')
        DestSkeleton = join(get_python_lib(), 'cumulus', 'skeleton')
        copytree(OrigSkeleton, DestSkeleton)

except IndexError: pass

关于python - 在 setup.py (setuptools) 中包含静态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11203054/

有关python - 在 setup.py (setuptools) 中包含静态数据的更多相关文章

随机推荐