pythonpython-pex

Is there a way to include extra files when building a PEX (i.e. with MANIFEST.in)?


I have a directory structure similar to the following:

├── myproj
│   ├── utils.py
│   ├── __init__.py
│   ├── routes
│   │   ├── __init__.py
│   │   ├── auth.py
│   │   └── stuff.py
├── html
│   ├── index.html
│   └── about.html
├── MANIFEST.in
├── setup.cfg 
└── setup.py

The contents of MANIFEST.in are:

graft html

The following post alludes to being able to use MANIFEST.in with PEX (Python PEX: Pack a package with its sub-packages) but when I run either pex . -o myproject or python setup.py bdist_pex the html/ directory is not included, verified via unzip -Z1 myproject on the resulting output, but it is included when running python setup.py sdist.

How do I include these extra html files when building a PEX binary?


Solution

  • Defining a MANIFEST.in alone isn't enough. You also need to set the include_package_data option to True in setup.cfg.

    This option will include extra files found in the package so you must also move the html directory inside the myproj package.

    So the directory structure looks like:

    ├── myproj
    │   ├── utils.py
    │   ├── __init__.py
    │   ├── routes
    │   │   ├── __init__.py
    │   │   ├── auth.py
    │   │   └── stuff.py
    │   ├── html
    │   │   ├── index.html
    │   │   └── about.html
    ├── MANIFEST.in
    ├── setup.cfg 
    └── setup.py
    

    The contents of MANIFEST.in are:

    graft myproj/html
    

    And setup.cfg contains in the [options] section:

    include_package_data = True