我如何配置我的 python 包以将文件复制到脚本 post 安装的子文件夹

How can I configure my python package to copy files to a subfolder of scripts post installation

我有一个 python 包,其中包含各种其他语言的脚本。 Setuptools 已经支持将这些脚本复制到环境的 scripts 目录中,以便可以从命令行访问它们。为此,我可以在设置命令中简单地使用以下关键字:

setup(
    ...
    scripts=["bin/script1.bat", "bin/script2.bat"],
    ...
    )

安装包后,脚本文件将正确结束在环境的 scripts 文件夹中。

我的问题: 有没有办法让这些文件最终位于 scripts 目录的子文件夹中?像 scripts/odd_scripts/script1.batscripts/even_scripts/script2.bat.

这样的东西

因为它们不是 Python 脚本,所以您不需要 scripts 的主要功能(即:重写 shebang 以指向与 Python 相同的可执行文件用于安装包的运行时)。

在这种情况下,您可以将它们打包为 data_files,原始的可执行位和 shebang 将被保留:

from setuptools import setup

setup(
    ...
    data_files=[('bin/odd_scripts', ['bin/script1.bat']),
                ('bin/even_scripts', ['bin/script2.bat'])],
    ...
)