Skip to content

Commit

Permalink
Halt on KeyboardInterrupt (#56)
Browse files Browse the repository at this point in the history
Closes #53
  • Loading branch information
kokorin authored Sep 10, 2024
1 parent 6fac6df commit 46d5f40
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ __pycache__

#auto-generated
/dbt_pumpkin/version.py
/.dbt_project
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ hatch config set dirs.env.virtual .hatch
hatch test
# test across different python & dbt versions
hatch test --all
# sometimes working DBT project is required to verify user experience
hatch run scripts/generate.py
hatch run dbt build
```

## Troubleshooting
Expand Down
2 changes: 2 additions & 0 deletions dbt_pumpkin/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def event_callback(event: EventMsg):
result_callback(potential_result[operation_name])
else:
logger.debug("Ignoring potential result: no '%s' key: %s", operation_name, potential_result)
except KeyboardInterrupt as e:
raise e # noqa: TRY201
except Exception: # noqa: BLE001
# We DO need to catch any exceptions while handling events
# otherwise dbtRunner will exit with exception
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ source = "versioningit"
[tool.hatch.build]
exclude = [
"/.github",
"/.dbt_project",
"/tests",
"/.pre-commit-config.yaml",
"/.gitignore"
Expand All @@ -46,6 +47,8 @@ dependencies = [
[tool.hatch.envs.default.env-vars]
EXPECTED_PYTHON_VERSION = "3.12"
EXPECTED_DBT_VERSION = "1.8"
DBT_PROJECT_DIR = ".dbt_project"
DBT_PROFILES_DIR = ".dbt_project"

[tool.hatch.envs.hatch-test]
extra-dependencies = [
Expand Down
42 changes: 42 additions & 0 deletions scripts/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# /// script
# requires-python = ">=3.9"
# ///

from pathlib import Path

project_dir: Path = Path(__file__, "../../.dbt_project").resolve()

print(f"Will generate DBT project at {project_dir}")

project_dir.mkdir(parents=True, exist_ok=True)

(project_dir / "dbt_project.yml").write_text("""\
name: my_pumpkin
version: 1.0.0
profile: test_pumpkin
models:
my_pumpkin:
+dbt-pumpkin-path: "_schema/{name}.yml"
""")

(project_dir / "profiles.yml").write_text(f"""\
test_pumpkin:
target: test
outputs:
test:
# Comment to stop formatting in 1 line
type: duckdb
path: {project_dir}/test.duckdb
threads: 8
""")

models_dir = project_dir / "models"
models_dir.mkdir(parents=True, exist_ok=True)

for i in range(1, 1000):
model_path = models_dir / f"model_{i}.sql"
model_path.write_text("""\
select 1 as id
""")

print("Generated")

0 comments on commit 46d5f40

Please sign in to comment.