Skip to content
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
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The project is configured using `pyproject.toml` (Python specifics) and `databri
| Directory | Description |
|-----------|-------------|
| `.github/workflows` | CI/CD jobs to test and deploy bundle |
| `dab_project` | Python project (Used in Databricks Workflow as Python-Wheel-Task) |
| `src/dab_project` | Python project (Used in Databricks Workflow as Python-Wheel-Task) |
| `dbt` | [dbt](https://github.com/dbt-labs/dbt-core) project<br/>* Used in Databricks Workflow as dbt-Task<br/>* dbt-Models used from https://github.com/dbt-labs/jaffle_shop_duckdb |
| `resources` | Resources such as Databricks Workflows or Databricks Volumes/Schemas<br/>* Python-based workflow: https://docs.databricks.com/aws/en/dev-tools/bundles/python<br/>* YAML-based Workflow: https://docs.databricks.com/aws/en/dev-tools/bundles/resources#job |
| `scripts` | Python script to setup groups, service principals and catalogs used in a Databricks (Free Edition) workspace |
Expand Down Expand Up @@ -131,19 +131,6 @@ uv run ./scripts/setup_workspace.py

## FAQ

* Why no `src` directory?

Working in Databricks Git Repos automatically adds the root of the Git Repo to Python `sys.path`.

This way Notebooks in the Git Repo can run `import dab_project` to import the local Python package during development without explicitly installing the package on the Cluster.

A Notebook outside the Git Repo can do `import os; os.chdir("/Workspace/Users/...")` to act like it is within the Git Repo.

Using a `src` directory requires changing the `sys.path` during development (without package installed) in a Databricks Git Repo.
```python
import sys
sys.path.append("../src")
```
* Service Principals

For this example, the targets `test` and `prod` use a group and service principals.
Expand Down
2 changes: 1 addition & 1 deletion databricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ include:

sync:
paths:
- dab_project/
- dbt/
- resources/
- src/
- typings/
- databricks.yml
- pyproject.toml
Expand Down
15 changes: 9 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,30 @@ dev = [
[project.scripts]
dab-project = "dab_project.cli:main"

[tool.uv.build-backend]
module-name = "dab_project"
module-root = ""

[[tool.mypy.overrides]]
ignore_missing_imports = true

[tool.ruff]
line-length = 100
include = [
"pyproject.toml",
"dab_project/**/*.py",
"src/**/*.py",
"resources/**/*.py",
"scripts/**/*.py",
"tests/**/*.py",
]
exclude = [
"tests/notebook_run_pytest.py"
]

[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint]
exclude = ["scratch/**/*.py"]
exclude = [
"scratch/**/*.py",
"tests/notebook_run_pytest.py"
]
select = [
"E", # pycodestyle
"W", # pycodestyle
Expand All @@ -82,6 +84,7 @@ line-length = 100
target-version = ['py312']

[tool.pytest.ini_options]
pythonpath = "src"
addopts = "-ra -q"
testpaths = [
"tests",
Expand Down
14 changes: 9 additions & 5 deletions scratch/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Notebooks
# Scratch

This folder contains Databricks Notebook style files (as `.py`).
This folder is reserved for personal, exploratory notebooks.
By default these are not committed to Git, as 'scratch' is listed in .gitignore.

They access `dab_project` Python project, so it can be used as:
* Databricks Git Repo
* Local IDE (Project installed as 'editable')
Using the `src` directory requires appending to the `sys.path`:

```python
import sys
sys.path.append("../src")
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 15 additions & 3 deletions tests/notebook_run_pytest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import sys
# Databricks notebook source
# MAGIC %pip install pytest

# COMMAND ----------

dbutils.library.restartPython()

# COMMAND ----------

import sys
import pytest

sys.dont_write_bytecode = True # Prevent writing .pyc files
# Prevent writing .pyc files
sys.dont_write_bytecode = True
# Add src to python path
sys.path.append("../src")

# COMMAND ----------

pytest_result = pytest.main(
[
".",
"-v",
"-x",
]
)

Expand Down