package command is used to generate an installable package that includes Guild models and operations. For more information, see Packages. This command simplifies the process of packaging. However, it cannot be used in conjunction with a project’s
setup.py script. To support Guild packages using
setup.py you must make a few changes to that script.
The steps below assume a standard Python distribution created with
You can use Cookiecutter to generate a Python project that supports such distributions.
The steps below are used to add Guild model operation support to such projects.
guild.yml to the project within the Python package directory
Here’s a simple Guild file.
# guild.yml located within the Python package dir op: description: A sample operation
op.py looks like this:
# op.py print("Hello from a Guild package")
The Guild file must be located within the package directory in order to be installed with the package.
Add Guild models as entry points in
Guild models are discovered using entry points under
guild.models. Add them in the format:
If the model name is empty (i.e. the anonymous model) use the special string
__anonymous__. The example above therefore is added like this:
setup( ... entry_points=[ 'guild.models': [ '__anonymous__=guild.model:PackageModel', ], ], ...
The distribution must contain
guild.yml. This file is not added by
setup.py by default. You must add it by including it in
MANIFEST.in, which is located in the project root.
Add it like this:
include <package name>/guild.yml
<package name> with the applicable package.
Note that if the package requires any other files, they must be included here as well.
Build a distribution
Create a wheel using the
bdist_wheel command with
python setup.py bdist_wheel
This generates a wheel distribution in
dist that you can distribute to others.
You can inspect this file using a zip compatible viewer, e.g.
unzip. The file should contain
guild.yml within the Python package. The package
entry_points.txt should contain the entries you make above.
Test the package in a separate virtual environment
Create a virtual environment, activate the environment, and install the wheel created in the previous step.
You should be able to list and run the packaged Guild operations.
<sample package>/op A sample operation
Running the op:
guild run op -y
Hello sample Guild package!
Distribute the distribution
You can upload the wheel file in
dist to PyPI for others to install. They have access to the Guild operations provided by the package.