How to include license file in setup.py script?

前端 未结 5 1803
陌清茗
陌清茗 2021-02-01 14:55

I have written a Python extension module in C++. I plan to distribute the module with setuptools. There will be binary distributions for 32- and 64-bit Windows (built with

相关标签:
5条回答
  • 2021-02-01 15:13

    For example:

    setup(
        ...
        license="ZPL",
        classifiers=[
            ...
            'License :: OSI Approved :: Zope Public License',
            ...
            ],
         ...)
    

    additionally you can insert your licence text into 'long_description':

    setup(
        ...
        long_description="Package description. \nLicense Text",
        ...)
    
    0 讨论(0)
  • 2021-02-01 15:15

    New setuptools (40.x) allows metadata, including license, to be stored in the setup.cfg's "metadata" section. If you use older setuptools you could provide license using the "license" named argument in your setup():

    def read_text(file_name: str):
        return open(os.path.join(base_path, file_name)).read()
    
    
    setup(
        name = 'Foo',
        version = '0.1.0',
        ext_modules = [Extension('Foo', glob('Source/*.cpp'))],
        # package_data = {'': ['LICENSE.txt']}
        license=read_text("LICENSE.txt")
    )
    
    0 讨论(0)
  • 2021-02-01 15:19

    Write a setup.cfg file and in there specify:

    [metadata]
    license_files = LICENSE.txt
    

    For this to work it seems like wheel is required to be installed. That is:

    pip install wheel
    

    If you have wheel already installed and it doesn't work, try to update it:

    pip install --upgrade wheel
    

    Then when installing the package via pip install <path> the LICENSE file gets included.

    0 讨论(0)
  • 2021-02-01 15:20

    Using a METADATA.in file, the license can be included both the source package and wheels automatically:

    METADATA.in include README.md include COPYING

    Check out an example here: https://github.com/node40/smsh

    0 讨论(0)
  • 2021-02-01 15:33

    You have to move the LICENSE.txt file into the package directory for your project. It cannot reside the top level. Python directories get deployed, not the deployment artifact. If you create a python package, that package actually contains a number of subpackages. Each subpackage must contain ALL the files relevant to deployment.

    Do not use data_files as it will actually distribute the files as a separate package. (I've heard package_files works, but I have yet to see a working example to do this).

    0 讨论(0)
提交回复
热议问题