如何在python中使用bdist_wheel包含外部shell脚本?

2024-06-14 19:42:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在试图解决这个错误,但就是找不到解决的办法。我敢肯定这只是我的配置中的一些愚蠢的小错误,但无法解决它。。。在https://github.com/tovrleaf/git-utils中查看我的代码存储库

问题

通过在项目根目录中为项目中的项目运行pip3 uninstall -y guts && python setup.py bdist_wheel && pip3 install dist/guts-*.whl && guts branch list-merged,它返回一个错误`FileNotFoundError:[Errno 2]没有这样的文件或目录:'/Users/...local/share/virtualenvs/git-utils-…/lib/python3.8/site-packages/gutsci/services/../scripts/branch-list.sh'

由于某些原因,安装程序包中不包含所需的shell脚本,即使它显示在安装输出复制build/scripts-3.8/branch-list.sh->;build/bdist.macosx-10.15-x86_64/wheel/guts-0.0.data/script

正在运行./src/gutsci/guts.py分支列表合并工作正常

我甚至在自己的个人存储库中创建了关于它的问题。 https://github.com/tovrleaf/git-utils/issues/1


Tags: 项目pyhttpsgitgithubcombranch错误
1条回答
网友
1楼 · 发布于 2024-06-14 19:42:39

您可以使用setup.pypackage_data将任何文件添加到控制盘。 使用下面示例中提供的helper函数,还可以指定递归添加的文件夹(例如web面板源文件夹)

在你的setup.py中:

import setuptools
from shutil import rmtree
import os


def package_files(directories: list):
    """
    This function will return the path of all files in the directories
    recursively, as setup.py package_data cannot handle * placeholders
    """
    paths = []
    for directory in directories:
        for (path, directories, filenames) in os.walk(directory):
            for filename in filenames:
                paths.append(os.path.join('..', path, filename))
    return paths


# add all paths that you want to add recursively to package_files()
# NOTE: this path is relative to the setup.py
my_fancy_script_files = package_files(
                            [
                                "./path/to/your/script/folder/", # my scripts
                                "./path/to/other/stuff/", # other nice stuff
                            ]
                        )

setuptools.setup(
    ...
    package_data={'': my_fancy_script_files}, # you can put various files here (as a list)
    include_package_data=True,
)

如果您有进一步的问题,或者它对您的项目不起作用,请留下评论并发布项目源代码树以进行进一步调试:)

相关问题 更多 >