feat: Migrate dependency management from pip to uv workspaces#202
feat: Migrate dependency management from pip to uv workspaces#202haroon0x wants to merge 2 commits into
Conversation
Signed-off-by: haroon0x <haroonbmc0@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Signed-off-by: haroon0x <haroonbmc0@gmail.com>
|
/assign @franciscojavierarceo |
|
@franciscojavierarceo when you have a moment, could you please review this PR and merge if everything looks good? Thank you! |
|
/unassign @franciscojavierarceo |
|
/assign @SanthoshToorpu |
|
@haroon0x: GitHub didn't allow me to assign the following users: SanthoshToorpu. Note that only kubeflow members with read permissions, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@SanthoshToorpu Can we get this merged ? |
|
Hey haroon. We are planning a major refactor of codebase. It'll be done by eow. Post that we'll standardize PR's. The whole templatization of code n all is being changed. |
|
@SanthoshToorpu Alright |
Summary
This PR replaces the per-directory
requirements.txtfiles withpyproject.tomlfiles managed byuvas a workspace. The three Python components (server,server-https,pipelines) are now workspace members under a single root configuration. Dependencies are resolved together, locked into a singleuv.lockfile, and installed into a shared venv at the root.Motivation
The existing setup had each component managing its own
requirements.txtwith no lockfile and no cross-component dependency resolution. This meant:serverandserver-https(which share most of their dependency tree) were using compatible versions of shared packages likepymilvus,sentence-transformers, ortorch.pip installon two different days could produce different dependency trees.pipresolves dependencies at install time.uvsolves all three problems. It resolves dependencies across the entire workspace in a single pass, produces a deterministic lockfile, and installs packages faster thanpip(10-20x in practice).Over the coming months, the codebase will include:
agent/layer with Kagnet for multi-tool routing and stateful reasoningfrontend/chat UI with feedback loops and golden dataset constructionEach of these additions will introduce its own set of Python dependencies. Without a workspace-level dependency manager and a deterministic lockfile, the dependency graph will become unmanageable as the repository scales. Migrating to
uvnow, while the codebase is still small, avoids a much more painful migration later when there are five or six workspace members instead of three.What changed
New files
pyproject.toml(root)requires-python >= 3.11.server/pyproject.tomlwebsockets,httpx,pymilvus,sentence-transformers,torch,numpy.server-https/pyproject.tomlfastapi,uvicorn[standard],pydantic,httpx,pymilvus,sentence-transformers,torch,numpy.pipelines/pyproject.tomlkfp,requests,beautifulsoup4,sentence-transformers,langchain-text-splitters,torch,feast[milvus],pandas,numpy..python-versionuv.lockModified files
server/Dockerfilepip install -r requirements.txtwithuv pip install -r pyproject.toml. Theuvbinary is pulled in as a multi-stage copy fromghcr.io/astral-sh/uv:latest.server-https/Dockerfile.gitignoretest-venv-swfs/(stale test virtual environment that should not be tracked).Deleted files
server/requirements.txtserver/pyproject.toml.server-https/requirements.txtserver-https/pyproject.toml.pipelines/requirements.txtpipelines/pyproject.toml.PyTorch CPU index
The root
pyproject.tomlconfigures a PyTorch CPU-only index:This replicates the
--extra-index-url https://download.pytorch.org/whl/cputhat was previously in therequirements.txtfiles. The servers do not run inference locally (they call KServe), so CUDA support is unnecessary. The CPU-only wheel is ~180 MB versus ~2 GB for the full CUDA build.The Dockerfiles also pass
--extra-index-urlexplicitly since they runuv pip installoutside the workspace context.What does NOT change
deployment.yaml,service.yaml, etc.) are unchanged. They reference Docker image names, which have not changed.docker build -t <image> server/works exactly as before.uv run python pipelines/kubeflow-pipeline.pyproduces the same YAML output.@dsl.componentdecorators still specify their ownpackages_to_installlists, which are resolved independently inside the KFP container runtime.kagent-feast-mcp/is not part of this migration. It retains its own dependency management.How to use
# Install all workspace member dependencies into .venv at root uv sync --all-packagesOnce synced, there are two equivalent ways to run scripts:
Option A: Activate the venv (recommended for active development)
source .venv/bin/activate python server/app.py python pipelines/kubeflow-pipeline.pyOption B: Use
uv run(useful for one-off commands and CI)uv runis a shortcut that temporarily activates the.venvfor a single command. For day-to-day work where you are running things repeatedly, activating the venv is simpler.Managing dependencies:
Verification
All of the following were tested and pass:
uv lockuv sync --all-packagesserver(websockets, httpx, pymilvus, sentence-transformers, numpy)server-https(fastapi, uvicorn, pydantic, httpx, pymilvus, sentence-transformers, numpy)pipelines(kfp, requests, bs4, langchain-text-splitters, feast, pandas, numpy)2.11.0+cpu)kubeflow-pipeline.py)serverserver-https