Skip to content

Commit

Permalink
chore: migrate monorepo to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
IcaroG committed Feb 24, 2025
1 parent dce19a9 commit 47f914b
Show file tree
Hide file tree
Showing 25 changed files with 5,042 additions and 8,594 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/check-duckdb-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ jobs:
with:
fetch-depth: 1

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python and UV
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
poetry-version: 1.8.2

- name: Install dependencies
run: uv sync --all-extras --dev

- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
Expand All @@ -61,7 +63,7 @@ jobs:
if: ${{ !inputs.fresh }}

- name: Initialize local data
run: poetry install && poetry run oso local initialize --max-results-per-query 100 --max-days 2
run: uv run oso local initialize --max-results-per-query 100 --max-days 2

- name: Compare database files
id: file-diff
Expand Down
18 changes: 10 additions & 8 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ jobs:
node-version: "20.x"
cache: "pnpm"

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python and UV
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
poetry-version: 1.8.5

- name: Install dependencies
run: uv sync --all-extras --dev

- name: Authenticate to google with a test-dummy user
uses: "google-github-actions/auth@v2"
Expand Down Expand Up @@ -141,7 +143,7 @@ jobs:
if: ${{ matrix.component == 'sqlmesh' }}

- name: Validate local database
run: poetry install && poetry run oso local initialize --max-results-per-query 50 --max-days 3
run: uv run oso local initialize --max-results-per-query 50 --max-days 3
if: ${{ matrix.component == 'sqlmesh' }}

# Automatically retry if the build fails
Expand Down Expand Up @@ -170,7 +172,7 @@ jobs:
# Temporarily include this separately. Eventually this should all be part of lint
- name: Lint SQL (dbt)
run: |
poetry run sqlfluff lint --dialect bigquery ./warehouse/dbt/models
uv run sqlfluff lint --dialect bigquery ./warehouse/dbt/models
if: ${{ always() && matrix.component == 'dbt' }}

- name: Type Check (Python)
Expand All @@ -180,15 +182,15 @@ jobs:

- name: Lint (Python)
run: |
poetry run ruff check
uv run ruff check
if: ${{ always() && matrix.component == 'python' }}

- name: Test (Python)
run: |
poetry run pytest
uv run pytest
if: ${{ always() && matrix.component == 'python' }}

- name: Test SQLMesh
run: |
poetry install && cd warehouse/metrics_mesh && poetry run -C ../../ sqlmesh plan dev --start '1 month' --end now --auto-apply
cd warehouse/metrics_mesh && uv run -C ../../ sqlmesh plan dev --start '1 month' --end now --auto-apply
if: ${{ always() && matrix.component == 'sqlmesh' }}
8 changes: 5 additions & 3 deletions .github/workflows/deploy-dbt-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ jobs:
cache: "pnpm"
node-version: "20.x"

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python and UV
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
poetry-version: 1.8.2

- name: Install dependencies
run: uv sync --all-extras --dev

- name: Login to google
uses: "google-github-actions/auth@v2"
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/deploy-hasura.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ jobs:
cache: "pnpm"
node-version: "20.x"

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python and UV
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
poetry-version: 1.8.2

- name: Install dependencies
run: uv sync --all-extras --dev

- name: Login to google
uses: 'google-github-actions/auth@v2'
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/test-deploy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ runs:

path: "ops/external-prs/pr-clone/"

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python and UV
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
poetry-version: 1.8.2

- name: Install poetry deps in the pr-clone
- name: Install dependencies
run: uv sync --all-extras --dev

- name: Install uv deps in the pr-clone
shell: bash
run: |
cd ops/external-prs/pr-clone && poetry install
cd ops/external-prs/pr-clone && uv sync --all-extras --dev
- name: Run test-deploy
shell: bash
Expand Down
8 changes: 4 additions & 4 deletions .lintstagedrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"prettier --ignore-path .gitignore --log-level warn --check"
],
"**/*.py": [
"poetry run ruff check --fix --force-exclude",
"poetry run isort",
"uv run ruff check --fix --force-exclude",
"uv run isort",
"pnpm pyright"
],
"warehouse/dbt/**/*.sql": [
"poetry run sqlfluff fix -f",
"poetry run sqlfluff lint"
"uv run sqlfluff fix -f",
"uv run sqlfluff lint"
]
}
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Before you begin you'll need the following on your system:
- Node >= 20 (we suggest installing with [nvm](https://github.com/nvm-sh/nvm))
- pnpm >= 9 (see [here](https://pnpm.io/installation))
- Python >=3.11 (see [here](https://www.python.org/downloads/))
- Python Poetry >= 1.8 (see [here](https://pypi.org/project/poetry/))
- Python uv >= 0.6 (see [here](https://pypi.org/project/uv/))
- git (see [here](https://github.com/git-guides/install-git))
- BigQuery access (see [here](https://docs.opensource.observer/docs/get-started/#login-to-bigquery) if you don't have it setup already)
- gcloud (see [here](https://cloud.google.com/sdk/docs/install))
Expand All @@ -64,13 +64,13 @@ pnpm install
Also install the python dependencies

```
poetry install
uv sync
```

You will also need to setup `dbt` to connect to Google BigQuery for running the data pipeline. The following wizard will copy a small playground dataset to your personal Google account and setup `dbt` for you.

```bash
poetry run oso lets_go
uv run oso lets_go
```

:::tip
Expand Down Expand Up @@ -114,12 +114,12 @@ pnpm dev:frontend
Our datasets are public! If you'd like to use them directly as opposed to adding to our
dbt models, checkout [our docs!](https://docs.opensource.observer/docs/get-started/)

### Using the poetry environment
### Using the virtual environment

Once installation has completed you can enter the poetry environment.
Once installation has completed you can enter the virtual environment.

```bash
$ poetry shell
$ source .venv/bin/activate
```

From here you should have dbt on your path.
Expand Down Expand Up @@ -166,24 +166,24 @@ opensource_observer:
The [Power User for dbt core](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) extension is pretty helpful.
You'll need the path to your poetry environment, which you can get by running
You'll need the path to your virtual environment, which you can get by running
```bash
poetry env info --path
echo 'import sys; print(sys.prefix)' | uv run -
```

Then in VS Code:

- Install the extension
- Open the command pallet, enter "Python: select interpreter"
- Select "Enter interpreter path..."
- Enter the path from the poetry command above
- Enter the path from the uv command above

Check that you have a little check mark next to "dbt" in the bottom bar.

### Running dbt

Once you've updated any models you can run dbt _within the poetry environment_ by simply calling:
Once you've updated any models you can run dbt _within the virtual environment_ by simply calling:

```bash
$ dbt run
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/docs/guides/dagster/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ the required dependencies.
git clone [email protected]:opensource-observer/oso.git .
```

Install the dependencies and create a virtual environment with
[poetry](https://python-poetry.org):
Install the dependencies with
[uv](https://docs.astral.sh/uv/):

```sh
poetry install && poetry shell
uv sync
```

Now, let's fill the `.env` file with the required environment variables:
Expand Down Expand Up @@ -77,7 +77,7 @@ run_queue:
Now that we have everything set up, we can run the Dagster instance:
```sh
dagster dev
uv run dagster dev
```

After a little bit of time, you should see the following message:
Expand Down
14 changes: 7 additions & 7 deletions apps/docs/docs/guides/dbt.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This guide walks you through setting up dbt (Data Build Tool) for OSO developmen
## Prerequisites

- Python >=3.11
- Python Poetry >= 1.8
- Python uv >= 0.6
- git
- A GitHub account
- BigQuery access
Expand All @@ -30,10 +30,10 @@ For other platforms, follow the [official instructions](https://cloud.google.com

1. Follow the installation instructions in our monorepo [README](https://github.com/opensource-observer/oso).

2. Enter the poetry environment:
2. Activate the virtual environment:

```bash
poetry shell
source .venv/bin/activate
```

3. Verify dbt is installed:
Expand All @@ -51,7 +51,7 @@ gcloud auth application-default login
5. Run the setup wizard:

```bash
poetry install && poetry run oso_lets_go
uv sync && uv run oso_lets_go
```

:::tip
Expand Down Expand Up @@ -92,17 +92,17 @@ opensource_observer:
1. Install the [Power User for dbt core](https://marketplace.visualstudio.com/items?itemName=innoverio.vscode-dbt-power-user) extension
2. Get your poetry environment path:
2. Get your virtual environment path:
```bash
poetry env info --path
echo 'import sys; print(sys.prefix)' | uv run -
```

3. In VS Code:
- Open command palette
- Select "Python: select interpreter"
- Choose "Enter interpreter path..."
- Enter the poetry path
- Enter the virtual path

## Running dbt

Expand Down
2 changes: 1 addition & 1 deletion docker/images/000-oso-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN apt-get update && \
apt-get install -y curl git && \
curl -o get-pip.py https://bootstrap.pypa.io/get-pip.py && \
python${PYTHON_VERSION} get-pip.py && \
pip${PYTHON_VERSION} install poetry && \
pip${PYTHON_VERSION} install uv && \
curl -o gcloud.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-${GCLOUD_VERSION}-linux-x86_64.tar.gz && \
tar xvf gcloud.tar.gz && \
bash ./google-cloud-sdk/install.sh && \
Expand Down
2 changes: 1 addition & 1 deletion docker/images/oso-debug/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd /usr/src/app
git clone https://github.com/opensource-observer/oso.git
cd oso

poetry install
uv sync
pnpm install

while true; do sleep 300; done;
7 changes: 4 additions & 3 deletions docker/images/oso/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ RUN mkdir -p /usr/src/app && \
touch /usr/src/app/ops/opsscripts/__init__.py

WORKDIR /usr/src/app
COPY pyproject.toml poetry.lock /usr/src/app/
COPY pyproject.toml uv.lock /usr/src/app/

ENV UV_PROJECT_ENVIRONMENT=/usr/local

# Install everything onto the system path
RUN poetry config virtualenvs.create false && \
poetry install
RUN uv sync

RUN rm -r /usr/src/app/warehouse && \
rm -r /usr/src/app/ops
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"build": "turbo run build --concurrency=100%",
"build:dbt:docs": "poetry run dbt docs generate",
"build:dbt:docs": "uv run dbt docs generate",
"build:docs": "turbo run build --filter=@opensource-observer/docs",
"build:frontend": "turbo run build --filter=@opensource-observer/frontend",
"build:ops": "turbo run build --filter=@opensource-observer/ops-*",
Expand All @@ -25,7 +25,7 @@
"format:staged": "lint-staged",
"lint": "turbo run lint --concurrency=100%",
"serve": "yarn serve build",
"pyright": "pyright --pythonpath $(poetry env info --path)/bin/python",
"pyright": "pyright --pythonpath $(echo 'import sys; print(sys.prefix)' | uv run -)/bin/python",
"test": "turbo run test --concurrency=1",
"test:integration": "(docker compose -f docker/compose.yaml down || true) && docker compose -f docker/compose.yaml run --rm test",
"prepare": "husky install"
Expand Down
Loading

0 comments on commit 47f914b

Please sign in to comment.