Compiled on: 2025-06-30 — printable version
(Not to be confused with the system development life cycle (SDLC))
The process of creating tested deployable software artifacts
from source code
May include, depending on the system specifics:
Automation of the build lifecycle
$\Rightarrow$ Create software that automates the building of some software!
Modern build automation systems are declarative
Declarative software $\approx$ the program describes what to do, not how to do it
(as opposed to imperative software $\approx$ the program describes how to do it,
e.g. Python)
In other words:
Many modern languages (such as Rust) come with a build automator as part of their distribution.
Python is an interpreted language
The need for build systems in Python emerged with more complex use cases
Anaconda | Conda | Miniconda | pip |
Poetry | PyBuilder | PyEnv | virtualenv |
Since there were no standard management systems originally, multiple tools proliferated
By default, Python is installed system-wide
All Python installations come with pip
, the package installer for Python
So, one may install Python packages system-wide with pip install PACKAGE_NAME
One problem, many implications: the same package can be installed only once on the same Python installation
- (a) what if two projects on the same system require different versions of the same package as dependencies?
- say, project A requires
Kivy==2.3
and project B requiresKivy==1.4
- (b) what if two projects on the same system require different versions of Python?
- say, project A requires Python
3.8
and project B requires Python3.10
(consider reading this page for further details https://stackoverflow.com/a/41573588)
virtualenv
and venv
are tools to create virtual Python installations on the same system
virtualenv
is a third-party tool, venv
is built-in in Python 3.3 and laterv. XXX
installed on your system…
v. XXX
in other folders
pip
PyEnv
is a tool to manage multiple Python installations on the same system
New problem: many Python installations on the same system,
each one with a different version of Python, and different packages installed
recall all the issues we had in previous lectures?
Smart and adequate convention to work with Python projects: 1-project-1-Python-env
Achieving this requires developers to be disciplined and meticulous
Poetry
is a tool that aims to automate this process
Poetry is a declarative tool for dependency management, packaging, and release in Python
It handles both dependencies and dev-dependencies
requirements.txt
and requirements-dev.txt
It automates the 1-project-1-Python-env convention
It simplifies the packaging process for the project
It simplifies the publication process on PyPI (or other software repositories)
root-directory/
├── main_package/
│ ├── __init__.py
│ ├── sub_module.py
│ └── sub_package/
│ ├── __init__.py
│ └── sub_sub_module.py
├── test/
│ ├── test_something.py
│ └── test_something_else.py/
├── pyproject.toml # File where project configuration (metadata, dependencies, etc.) is stored
├── poetry.toml # File where Poetry configuration is stored
├── poetry.lock # File where Poetry locks the dependencies
└── README.md
Notice that, w.r.t. the canonical project structure we have been using so far:
requirements.txt
and requirements-dev.txt
are not present any morepyproject.toml
, poetry.toml
, and poetry.lock
are new entriespoetry.lock
file is generated automatically by Poetry, and you should not edit itcalculator
repositoryLook at the pyproject.toml
file
[tool.poetry]
# name of the package to be published
name = "unibo-dtm-se-calculator"
# files to be included for publication
packages = [
{ include = "calculator" },
]
# various metadata for publication
version = "0.1.1"
description = "A simple calculator toolkit written in Python, with several UIs. It is part of the Software Engineering course at the University of Bologna."
authors = ["Giovanni Ciatto <giovanni.ciatto@unibo.it>"]
license = "Apache 2.0"
readme = "README.md"
# dependencies (notice that Python is considered a dependency)
[tool.poetry.dependencies]
python = "^3.10.0"
Kivy = "^2.3.0"
# development dependencies
[tool.poetry.group.dev.dependencies]
poetry = "^1.7.0"
pytest = "^8.1.0"
coverage = "^7.4.0"
mypy = "^1.9.0"
# executable commands that will be created then installing this package
[tool.poetry.scripts]
calculator-gui = "calculator.ui.gui:start_app"
calculator = "calculator.ui.cli:start_app"
# where to download the dependencies from
[[tool.poetry.source]]
name = "PyPI"
priority = "primary"
# packaging dependencies
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
# mypy configuration
[tool.mypy]
ignore_missing_imports = true
calculator
repositoryLook at the poetry.toml
file
# the project-specific environment will be created in the local .venv folder
[virtualenvs]
in-project = true
# packages produced by poetry may be published on the pypi-test repository
[repositories.pypi-test]
url = "https://test.pypi.org/legacy/"
# another implicit repository is always available, namely PyPI
# at https://pypi.org/
calculator
repositoryEnsure you have Poetry installed on your system
poetry --version
to checkFork the repository
Clone the repository on your system
git clone https://github.com/unibo-dtm-se/calculator.git
calculator
folder into VS codeRun poetry install
in the terminal. This shall:
.venv
directory
.venv
directory exists in your project directory, after running this commandpyproject.toml
filepoetry.lock
fileThis software is compatible with
library
version 2.3. For our examples, we used version 2.3.10
Expressing something like this is done via dependency locking:
calculator
repositoryLet’s use a shell in the virtual environment created by Poetry
poetry shell
calculator 1+1
to produce 2
as output
Make sure that VS Code is using the same environment as the one created by Poetry.
Python: Select Interpreter
./.venv/bin/python
This is an ordinary project, where you can operate as usual
python -m unittest discover -v -s tests
in the terminalSo many Python environments in the shell… how to avoid mistakes?
If you want to be 100% you’re running commands in the right environment, you can prefix them with
poetry run
:poetry run python -m unittest discover -v -s tests
Ok but what about VS Code’s environments?
Get the habit of configuring the VS Code environment manually when working with Python projects
It supports publishing.
Consider the following Web Page:
https://pypi.org/project/unibo-dtm-se-calculator
This is the PyPI page of the unibo-dtm-se-calculator
package
After the project is made available on PyPI, it can be installed by anyone
pip install unibo-dtm-se-calculator
Let’s first create a new Python environment, and then install the unibo-dtm-se-calculator
package in it
Create a new Python environment (to simulate the initially empty environment of a new developer/user)
python -m venv virgin-env
source virgin-env/bin/activate
.\virgin-env\Scripts\Activate
calculator
or calculator-gui
they should failInstall the unibo-dtm-se-calculator
package pip install unibo-dtm-se-calculator
Try now to run the calculator in the shell
calculator 1+1
should produce 2
as outputcalculao-gui
should open a GUI calculatorHave an account on PyPI
Have an account on Test-PyPI
Publish on Test-Pypi, to ensure the procedure works
Publish on PyPI
Profit
Build the project, i.e. produce installable package (only do this after all Q/A checks pass)
poetry build
.whl
file and a .tar.gz
file in the dist/
directoryUpload installable packages on Test-PyPI
poetry publish --repository pypi-test --username __token__ --password TEST_PYPI_API_TOKEN
__token__
That’s it!
pip install -i https://test.pypi.org/simple/ unibo-dtm-se-calculator
Building may fail if your pyproject.toml
is not properly configured, or missing data
Upload may fail:
Installation may fail:
Build the project, i.e. produce installable package (only do this after all Q/A checks pass)
poetry build
.whl
file and a .tar.gz
file in the dist/
directoryUpload installable packages on PyPI
poetry publish --repository pypi-test --username __token__ --password PYPI_API_TOKEN
__token__
That’s it!
pip install unibo-dtm-se-calculator
Building may fail if your pyproject.toml
is not properly configured, or missing data
Upload may fail:
Installation may fail, but in this case there must be an issue in the package itself
Compiled on: 2025-06-30 — printable version