pythonuv

Trouble with installing uv subpackages within monorepo


Context

I'm setting up a Python monorepo using uv for dependency management. When I run uv sync in the root directory, only the root package's dependencies are installed - none of the subpackages' dependencies are being installed.

I'm building a data platform monorepo using Python 3.12 and uv for dependency management. The project has several components:

Project Structure

Here's the (simplified) project structure :

custom-data-forge/
├── pyproject.toml
└── packages/
   ├── engine-core/ # Python library with importable modules
   │ └── pyproject.toml
   ├── orchestrator/ # Airflow DAGs and pipeline code
   │ └── pyproject.toml
   └── modeling/
     └── dbt_forge/ # dbt models and ClickHouse transformations
       └── pyproject.toml

Configuration

Root pyproject.toml:

[project]
name = "custom-data-forge"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["pandas", "sqlalchemy", "tabulate"]

[tool.uv.workspace]
members = [
    "packages/engine-core",
    "packages/orchestrator",
    "packages/modeling/dbt_forge",
]

Subpackage pyproject.toml files:

# packages/engine-core/pyproject.toml
[project]
name = "engine-core"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["dbt-core", "dbt-clickhouse"]

# packages/orchestrator/pyproject.toml
[project]
name = "orchestrator"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["engine-core", "apache-airflow"]

# packages/modeling/dbt_forge/pyproject.toml
[project]
name = "dbt_forge"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["dbt-core", "dbt-clickhouse"]

The Problem

When I run uv sync in the root directory:

What I've Tried

  1. Added [tool.uv] package = true to the subpackages' pyproject.toml files
  2. Verified the workspace configuration in the root pyproject.toml
  3. Made sure all [build-system] sections are properly configured
  4. Deleted uv.lock and tried again

Questions

  1. Is this the expected behavior for uv workspaces? Shouldn't uv sync install dependencies from all workspace members?
  2. What's the correct way to configure uv to install dependencies from subpackages?
  3. Do I need to make the subpackages "real" Python packages (with __init__.py files) for uv to recognize them?

Environment


Solution

  • There are two ways to solve this :