我已经用C++编写了一个Python扩展模块。我计划用setuptools发布这个模块。将有针对32位和64位Windows的二进制发行版(使用setup.py bdist_egg
构建)和针对类UNIX平台的源代码发行版(使用setup.py sdist
构建)。
我计划在BSD许可下许可该模块。在我的源码树中,文件LICENSE.txt和setup.py一起位于顶部文件夹中。如何将其包含在安装包中?
我尝试了以下setup.py脚本:
from setuptools import setup, Extension
from glob import glob
setup(
name = 'Foo',
version = '0.1.0',
ext_modules = [Extension('Foo', glob('Source/*.cpp'))],
package_data = {'': ['LICENSE.txt']}
)
它不起作用,许可证文件未包含在安装包中。可能是因为setup.py文件没有定义任何包,只定义了一个扩展模块。
我该如何解决这个问题?
发布于 2018-02-09 01:55:28
编写一个setup.cfg
文件,并在其中指定:
[metadata]
license_files = LICENSE.txt
要让它工作,似乎需要安装轮子。这就是:
pip install wheel
如果您已经安装了wheel
,但它不工作,请尝试更新它:
pip install --upgrade wheel
然后,当通过pip install <path>
安装软件包时,许可证文件将包含在内。
发布于 2021-03-03 01:08:52
从setuptools
42.0.0开始,您可以使用license_files
密钥指定要包含在发行版中的许可证文件列表。
请注意,由于有了implementation details,您实际上不需要将此密钥放入setup.cfg
文件中(如documentation和another answer所建议的)。您可以简单地将其作为参数提供给setup()
函数:
from setuptools import setup
setup(
...
license_files = ('LICENSE.txt',),
...
)
还要注意的是,虽然这些文件将包含在二进制文件( will )和源代码发行版中,但如果用户没有安装setup.py
-style软件包,它们将不会随wheel
源代码发行版的软件包一起安装!
为确保许可证文件将随软件包一起安装,您需要对安装脚本进行一些额外的修改:
from setuptools import setup
from setuptools.command.egg_info import egg_info
class egg_info_ex(egg_info):
"""Includes license file into `.egg-info` folder."""
def run(self):
# don't duplicate license into `.egg-info` when building a distribution
if not self.distribution.have_run.get('install', True):
# `install` command is in progress, copy license
self.mkpath(self.egg_info)
self.copy_file('LICENSE.txt', self.egg_info)
egg_info.run(self)
setup(
...
license_files = ('LICENSE.txt',),
cmdclass = {'egg_info': egg_info_ex},
...
)
如果您的项目是一个pyproject.toml
-style project,并且您认为它将由兼容PEP517的前端(例如pip>=19
)安装,则将从您的源代码强制构建一个轮子,并且许可证文件将自动安装到.dist-info
文件夹中。
发布于 2018-04-07 02:23:11
使用METADATA.in文件,许可可以自动包含在源包和控制盘中:
METADATA.in include README.md include COPYING
在这里查看一个示例:https://github.com/node40/smsh
https://stackoverflow.com/questions/9977889
复制相似问题