Compiled on: 2024-10-19 — printable version
calculator
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
fileIf you try to run the scripts defined in the poetry.toml
file, you might get an error like this:
$ calculator-gui
zsh: command not found: calculator-gui
This could be due to the fact that the PATH
variable does not include the .venv/bin
directory (where the scripts are installed).
To solve this, you can do the following:
poetry env info --path
to get the path of the virtual environmentbin
directory to the PATH
variable
export PATH=$PATH:/path/to/.venv/bin
set PATH=%PATH%;C:\path\to\.venv\Scripts
source ~/.zshrc
(or source ~/.bashrc
) on Unix-like systems, or refreshenv
on WindowsNow you should be able to run the scripts without any issues.
This 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