Make It Installable
This is a replacement for the older
setup.py you may have seen in the past. The
pyproject.toml file is a data file used by the Python build system, and it gets used to determine how a package is built, installed, and run.
If you were going to put your project up on PyPI, this is also the first part of bundling it as well. I won’t go that far here though. I’ll leave you with a local package instead that you can install using
01:05 Installation requires a package, and this says to use setuptools to build it and output a wheel file. The project section contains a bunch of metadata about the program, including the name and where the README file is.
The dynamic attribute in the project section tells setuptools what values of this section should be built dynamically for RP Life. The version attribute is the only thing being built dynamically down at the bottom here in the dynamic section for setuptools, I’m telling setuptools how to generate the value for version in this case by reading it from the
__version__ attribute in the module.
Remember when I said putting in the
__init__ served a dual purpose? Well, this means your version number only ever has to be specified in one place, and the build system can read it just like
The final bit here is the magic that makes our code into a script available on the command line. The project scripts area allows you to define one or more programs. I’ve called mine
rp_life, and the value here says to use the
main() function in the
__main__ file of the
rp_life module as the entry point.
Once you’ve used this
pyproject.toml file to install your project,
rp_life will be available as a directly runnable script. Let’s go do that. I’m creating a new virtual env to install our package into.
03:33 And there you go. You’ve got an installable runnable version of Conway’s Game of Life. In the last lesson, I’ll summarize the course and point you at other similar projects you can do at Real Python.
Become a Member to join the conversation.