AESB2122 - Signals and Systems with Python
Packaging is the process of preparing your Python code so that others can easily install and use it.
pip install your code and its dependencies automaticallyHow is Python packaging done? or How does pip know how to install my package?
pyproject.toml filepyproject.tomlpip) how to build and distribute your packageEvery Python package (nowadays) would have a pyproject.toml file. The absolute minimum you need is something like this:
setuptools is a tool that helps build and distribute Python packagesNow let’s add information about your project:
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "my-package"
version = "0.1.0"
description = "Generates signals, modifies them, and plots them"The [project] section tells everyone what your project is called, what version it is, and what it does!
You can specify who created the project:
[project]
name = "my-package"
version = "0.1.0"
description = "Generates signals, modifies them, and plots them"
authors = [
    {name = "Your Name", email = "you@example.com"}
]
dependencies = ["numpy", "pandas", "matplotlib"]authors is an array (a list) of objects. So, there can be multiple authors…
When someone installs your package, pip will automatically install these dependencies too! :)
You can also specify versions for your dependencies (e.g. numpy>=1.20)
pyproject.toml (exactly this name!)Start with the minimum:
Copy this into your file and save it.
Add information about your project:
[project]
name = "give-a-sensible-name"
version = "0.1.0"
description = "Give an appropriate description of your project here!"
authors = [
    {name = "Your Name", email = "your.email@student.uni.nl"}
]
dependencies = ["what", "packages", "you-actually-use"]Replace the placeholders with your actual information! For dependencies, only include packages that your code actually imports. If you’re not sure what you need, you can always add more later!
Save your file as pyproject.toml in your project root. Your file structure should look like this:
my-awesome-project/
├── pyproject.toml
├── functions.py
├── script.py
└── plots/That’s it! You’ve created your first pyproject.toml file!
❌ Wrong:
✅ Correct:
Without the section header, TOML doesn’t know where to put the information!
pyproject.tomlpyproject.txtpyproject-tomlmy_pyproject.tomlpyproject.toml.pyproject.toml will grow as your project grows