Skip to content

Poetry --> UV (+ Makefile Added) #22

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

Merged
merged 9 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,31 @@ jobs:
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}
poetry-version: 1.8.2

- name: Install uv
uses: astral-sh/setup-uv@v3

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

- name: Type Check (Python)
run: |
pnpm pyright

- name: Lint (Python)
run: |
poetry run ruff check
uv run ruff check

- name: Test (Python)
run: |
poetry run pytest
uv run pytest

- name: Run the sample dagster project
run: |
poetry run dagster job execute -f sample/dagster_project/definitions.py -j all_assets_job
uv run dagster job execute -f sample/dagster_project/definitions.py -j all_assets_job

2 changes: 1 addition & 1 deletion .lintstagedrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"**/*.py": [
"poetry run ruff check --fix --force-exclude",
"uv run ruff check --fix --force-exclude",
"pnpm pyright"
]
}
57 changes: 57 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# System detection
UNAME := "$(shell uname)"
PYTHON_VENV_NAME := ".venv"

# Python virtual environment settings
VENV_NAME := .venv
PYTHON := python

PYTHON_CMD := $(CURDIR)/$(VENV_NAME)/bin/python
SQLMESH_CMD := $(CURDIR)/$(VENV_NAME)/bin/sqlmesh
UV_CMD := uv
ACTIVATE := source $(CURDIR)/$(VENV_NAME)/bin/activate
DEACTIVATE := deactivate

init-python:
@if [ ! -d "$(PYTHON_VENV_NAME)" ]; then \
echo "Creating virtual environment with Python 3.12..."; \
uv venv --python 3.12 $(PYTHON_VENV_NAME); \
fi

install-python-deps:
uv sync --all-extras

upgrade-python-deps:
uv lock --upgrade
make install-python-deps

install-node-deps:
pnpm install

upgrade-node-deps:
pnpm update

# Base commands
init: init-python install-python-deps check-pnpm install-node-deps

clean:
find . \( -type d -name "__pycache__" -o -type f -name "*.pyc" -o -type d -name ".pytest_cache" -o -type d -name "*.egg-info" \) -print0 | xargs -0 rm -rf

# Testing commands
test:
$(PYTHON_CMD) -m pytest -vv --log-cli-level=INFO $(filter-out $@,$(MAKECMDGOALS))

pyright:
pnpm pyright

# Sample project commands

dagster-dev: clean-dagster
DAGSTER_HOME=$(CURDIR)/sample/dagster_project $(PYTHON_CMD) -m dagster dev -h 0.0.0.0 -w

dev: dagster-dev # Alias for dagster-dev

dagster-materialize:
$(PYTHON_CMD) -m dagster asset materialize -f sample/dagster_project/definitions.py --select '*'

.PHONY: init init-python install-python-deps upgrade-python-deps clean test mypy check-pnpm install-node-deps upgrade-node-deps sample-dev dagster-dev dagster-materialize clean-dagster
30 changes: 23 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,33 @@ _Note: this is a python project but some of our dependent tools are in typescrip

### Installing

To install everything you need for development just do the following:
The project uses Make commands to simplify the development setup process. To get started:

```bash
poetry install
pnpm install
make init
```

This will:
- Set up a Python virtual environment with Python 3.12
- Install all Python dependencies
- Install Node.js dependencies via pnpm

_Note: All Make commands automatically use the correct virtual environment - you don't need to activate it manually._

To upgrade dependencies:
```bash
make upgrade-python-deps # Upgrade Python dependencies
make upgrade-node-deps # Upgrade Node.js dependencies
```

### Running tests

We have tests that should work entirely locally. You may see a `db.db` file appear in the root of the repository when these tests are run. It can be safely ignored or deleted.

We run tests with `pytest` like so:
To run tests:

```bash
poetry run pytest
make test
```

### Running the "sample" dagster project
Expand All @@ -79,13 +91,17 @@ accompanying sqlmesh project from `sample/sqlmesh_project` configured as an
asset. To run the sample dagster project deployment with a UI:

```bash
poetry run dagster dev -h 0.0.0.0 -f sample/dagster_project/definitions.py
make dagster-dev
```
or
```bash
make dev
```

If you'd like to materialize the dagster assets quickly on the CLI:

```bash
dagster asset materialize -f sample/dagster_project/definitions.py --select '*'
make dagster-materialize
```

_Note: The sqlmesh project that is in the sample folder has a dependency on a
Expand Down
20 changes: 13 additions & 7 deletions dagster_sqlmesh/console.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import logging
import typing as t
from typing import Dict, Union, Callable
from dataclasses import dataclass
import uuid
import unittest
import logging
import uuid
from dataclasses import dataclass
from typing import Callable, Dict, Union

from sqlglot.expressions import Alter
from sqlmesh.core.console import Console
from sqlmesh.core.plan import EvaluatablePlan
from sqlmesh.core.context_diff import ContextDiff
from sqlmesh.core.plan import PlanBuilder
from sqlmesh.core.table_diff import RowDiff, SchemaDiff, TableDiff
from sqlmesh.core.environment import EnvironmentNamingInfo
from sqlmesh.core.linter.rule import RuleViolation
from sqlmesh.core.plan import EvaluatablePlan, PlanBuilder
from sqlmesh.core.snapshot import (
Snapshot,
SnapshotChangeCategory,
SnapshotInfoLike,
)
from sqlmesh.core.table_diff import RowDiff, SchemaDiff, TableDiff
from sqlmesh.utils.concurrency import NodeExecutionFailedError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -559,6 +559,12 @@ def print_environments(self, environments_summary: t.Dict[str, int]) -> None:
def show_table_diff_summary(self, table_diff: TableDiff) -> None:
self.publish(ShowTableDiffSummary(table_diff))

def show_linter_violations(
self,
violations: list[RuleViolation],
) -> None:
self.publish(LogWarning("Linting violations found", str(violations)))


class DebugEventConsole(EventConsole):
"""A console that wraps an existing console and logs all events to a logger"""
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"build": "turbo run build --concurrency=100%",
"format:staged": "lint-staged",
"pyright": "pyright --pythonpath $(poetry env info --path)/bin/python",
"pyright": "uv run -q -c \"import sys; print(sys.executable)\" | xargs -r pyright --pythonpath",
"prepare": "husky install"
},
"devDependencies": {
Expand Down
Loading