Coding environment¶
This page explains how to set up your computer to develop on the RS-Python Python repositories (rs-server, rs-client-libraries, rs-dpr-service, rs-testmeans...). It assumes a Linux or macOS computer. No specific IDE is required, Visual Studio Code and PyCharm are both used by the team.
Prerequisites¶
| Tool | Usage |
|---|---|
| git | Get the source code. |
| Docker | Run the local mode, build the Docker images. |
| pyenv (recommended) | Install the Python versions used by the project. |
| pipx (recommended) | Install the Python tools in isolated environments. |
| Poetry | Manage the dependencies and the virtual environments of the projects. |
| pre-commit | Run the code checks before each commit. |
| Trivy | Security and license checks, run by pre-commit and the CI. |
# Install the Python version used by the project (see the "python" constraint of each pyproject.toml)
pyenv install 3.13.16
pyenv global 3.13.16
# Install Poetry (use the version of the CI, see the RS-PYTHON/actions repository)
pipx install poetry
Get the source code¶
Clone the repositories in a common parent folder, e.g.:
mkdir ~/rspy && cd ~/rspy
for repo in rs-server rs-client-libraries rs-dpr-service rs-demo rs-testmeans rs-documentation; do
git clone https://github.com/RS-PYTHON/${repo}.git
done
The default branch of the repositories is develop.
Set up a project¶
From each repository:
cd ~/rspy/rs-server
# Create the virtual environment and install the dependencies, including the development ones
poetry install --with dev
# Install the OpenTelemetry instrumentation of the installed libraries
poetry run opentelemetry-bootstrap -a install
# Install the git hooks
poetry run pre-commit install
Configure your IDE to use the Poetry virtual environment (poetry env info --path), and to run the formatters
(black, isort) when you save a file.
Run the tests¶
The tests are written with pytest and categorised with markers:
poetry run pytest -m unit # fast unit tests, with mockup servers
poetry run pytest -m integration # integration tests
Tips:
- In rs-client-libraries, the tests start a Prefect test server, which is slow. Instead, start a Prefect server
from the local mode with
docker compose up prefect-server -dand setSKIP_PREFECT_TEST_HARNESS=1. - The local mode runs the whole system on your computer, and allows to test your local source code without rebuilding the Docker images.
Code quality¶
The checks run by pre-commit and by the CI are described in Contributing. Run them on all the files with:
If pre-commit fails after a dependency update or a git conflict resolution, reinstall it with
poetry run pre-commit uninstall && poetry run pre-commit install.
Develop on the cluster¶
You can also develop from your JupyterHub session on a cluster: clone the repositories in your home directory, and add them to the Python path of your notebooks:
import sys
sys.path.insert(0, "/home/rspy/rs-demo/notebooks")
sys.path.insert(0, "/home/rspy/rs-client-libraries")
import rs_client, resources
print(rs_client.__path__, resources.__path__)
See Create a custom flow for the development of Prefect flows.