Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][TBD] Update how we handle dependencies and run environment for our Python examples #5890

Closed
wants to merge 3 commits into from

Conversation

abey79
Copy link
Member

@abey79 abey79 commented Apr 10, 2024

What

This PR aims to update the way we handle the dependencies and run environment of our Python examples.

Goals:

  • Per-example dependency specification: different example must be able to have conflicting dependencies.
  • Per-example Python version requirement: although the Rerun SDK has a well-defined Python compatibility range, specific example should be able to restrict it when required by their specific dependencies.
  • Per-example isolated environment: it follows from what precedes that each example should be run in their own venv.
  • Minimal overhead and as "standard" as possible.
  • (Nice to have) Lockfile.

In addition, we should support both dev environment (install rerun-sdk from the working directory) and end-user environment (install rerun-sdk from PyPI).

WIP: for now, here are 3 versions of the human_pose_tracking example, with handling by uv, poetry, and hatch, to serve a discussion basis.


Using uv

Example: human_pose_tracking

Tooling Installation

pipx install uv

# or

curl -LsSf https://astral.sh/uv/install.sh | sh

Environment Setup

Must be manually created but uv has facilities for that:

cd example/python/human_pose_tracking
uv venv --python 3.11 
source .venv/bin/activate
uv pip install -r requirements.txt

# to use local rerun-sdk (this triggers a maturin compilation)
uv pip install -e ../../../rerun_py

⚠️There don't seem to be a way to specify Python version requirement for uv yet, so the user must pick a compatible python version.

Note: since this is basically based on a (locked) requirement file, "standard" Python tooling will also work:

cd example/python/human_pose_tracking
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pip install -e ../../../rerun_py

In that sense, uv is only required for example authors (to update the requirements.txt file).

Run the example

python main.py

Create/update the lockfile

The direct dependencies are specified in requirements.in. From that, uv is able to generate a requirements.txt which essentially is a lockfile:

uv pip compile requirements.in -o requirements.txt

Using poetry with package-mode = false

Example: human_pose_tracking_poetry

Note: package-mode = false is very nice for lone scripts that don't need to be "pip installed" to run, just like our examples.

Tooling Installation

pipx install poetry

# or

curl -sSL https://install.python-poetry.org | python3 -

Environment Setup

poetry install

# to use the local rerun-sdk (this triggers maturin compilation)
poetry run pip install -e ../../../rerun_py

This will do the following:

  • Unless a venv is already active, it will create one using some python interpreter that it can find and is compatible with constraints listed in pyproject.toml.
  • Install all dependencies.
  • Create the main executable script as specified in the pyproject.toml.

Additional facilities provided by Poetry:

poetry run ${ARGS}  #  run stuff inside the default environment
poetry env use 3.8  # create another environment with the specified python version
poetry env list     # list all available environments
poetry shell        # activate the default environment

Run the example

poetry run python main.py

# or

poetry shell  # activate the venv
python main.py

Create/update the lockfile

poetry update

Using hatch

Example: human_pose_tracking_hatch

hatch is similar to poetry, but with wider scope and a richer plug-in ecosystem to support it.

Tooling Installation

pipx install hatch

Environment Setup

Basically nothing, hatch creates a venv on the fly.

To use the dev rerun-sdk:

hatch run pip install ../../../rerun_py

Run the example

hatch run python main.py

# or

hatch shell
python main.py 

Using pixi

Tooling Installation

curl -fsSL https://pixi.sh/install.sh | bash

Environment Setup

None

Run the example

pixi run py-ex-human-pose-tracking

Checklist

  • I have read and agree to Contributor Guide and the Code of Conduct
  • I've included a screenshot or gif (if applicable)
  • I have tested the web demo (if applicable):
  • The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG
  • If applicable, add a new check to the release checklist!

@abey79 abey79 added 💬 discussion examples Issues relating to the Rerun examples do-not-merge Do not merge this PR include in changelog labels Apr 10, 2024
Copy link

github-actions bot commented Apr 10, 2024

Deployed docs

Commit Link
d5c3945 https://landing-l8thcnqq1-rerun.vercel.app/docs

Wumpf added a commit that referenced this pull request Apr 10, 2024
### What

* Fixes #5595

Has a few judgment calls on what is no longer needed, but preserves most
of what we had.
Notably removes `py-requirements` command for the time being - the hope
is that #5890 will fix things. (porting it proved difficult)
See
* #5894

Other things in here:
* taplo (toml formatting) was very slow since despite extensive
'exclude' list it looked at too many files. Turned it around to
'include' things and it's a LOT faster now
* Updated Ruff & removed last use of blackdoc. The only thing we're not
properly catching with this now is too long lines, I figured it's not
worth keeping it around just for that.
* various cleanups of pixi.toml file: trying to make commands a bit more
consistent overall

Tested on:
* [x] mac
* [x] windows

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[rerun.io/viewer](https://rerun.io/viewer/pr/5892)
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5892?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/5892?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5892)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
@abey79 abey79 closed this Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💬 discussion do-not-merge Do not merge this PR examples Issues relating to the Rerun examples include in changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve python dependency management for our examples
1 participant