How do you add additional files to a wheel?

前端 未结 6 597
北荒
北荒 2020-11-28 21:58

How do control what files are included in a wheel? It appears MANIFEST.in isn\'t used by python setup.py bdist_wheel.

UPDATE

6条回答
  •  遥遥无期
    2020-11-28 22:21

    Before you make any changes in MANIFEST.in or setup.py you must remove old output directories. Setuptools is caching some of the data and this can lead to unexpected results.

    rm -rf build *.egg-info
    

    If you don't do this, expect nothing to work correctly.

    Now that is out of the way.

    1. If you are building a source distribution (sdist) then you can use any method below.

    2. If you are building a wheel (bdist_wheel), then include_package_data and MANIFEST.in are ignored and you must use package_data and data_files.

    INCLUDE_PACKAGE_DATA

    This is a good option, but bdist_wheel does not honor it.

    setup(
        ...
        include_package_data=True
    )
    
    # MANIFEST.in
    include package/data.json
    

    DATA_FILES for non-package data

    This is most flexible option because you can add any file from your repo to a sdist or bdist_wheel

    setup(
        ....
        data_files=[
            ('output_dir',['conf/data.json']),
        ]
        # For sdist, output_dir is ignored!
        #
        # For bdist_wheel, data.json from conf dir in root of your repo 
        # and stored at `output_dir/` inside of the sdist package.
    )
    

    PACKAGE_DATA for non-python files inside of the package

    Similar to above, but for a bdist_wheel let's you put your data files inside of the package. It is identical for sdist but has more limitations than data_files because files can only source from your package subdir.

    setup(
        ...
        package_data={'package':'data.json'},
        # data.json must be inside of your actual package
    )
    

提交回复
热议问题