Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/dbt-labs/dbt-adapters into …
Browse files Browse the repository at this point in the history
…mcknight/ct-2819
  • Loading branch information
McKnight-42 committed Jul 17, 2024
2 parents f70650b + 43ea32d commit 098fcf5
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 185 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240625-110833.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Rework record/replay to record at the database connection level.
time: 2024-06-25T11:08:33.264457-04:00
custom:
Author: peteralllenwebb
Issue: "244"
3 changes: 2 additions & 1 deletion .github/actions/build-hatch/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ inputs:
default: "./"
archive-name:
description: Where to upload the artifacts
required: true
default: ""

runs:
using: composite
Expand All @@ -30,6 +30,7 @@ runs:
working-directory: ${{ inputs.working-dir }}

- name: Upload artifacts
if: ${{ inputs.archive-name != '' }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.archive-name }}
Expand Down
31 changes: 0 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ on:
types: [checks_requested]
workflow_dispatch:
workflow_call:
inputs:
changelog_path:
description: "Path to changelog file"
required: true
type: string

permissions: read-all

Expand All @@ -51,35 +46,9 @@ jobs:
uses: ./.github/actions/setup-hatch

- name: Build `dbt-adapters`
if: ${{ inputs.package == 'dbt-adapters' }}
uses: ./.github/actions/build-hatch

- name: Build `dbt-tests-adapter`
if: ${{ inputs.package == 'dbt-tests-adapter' }}
uses: ./.github/actions/build-hatch
with:
working-dir: "./dbt-tests-adapter/"

- name: Setup `hatch`
uses: ./.github/actions/setup-hatch

- name: Build `dbt-adapters`
if: ${{ inputs.package == 'dbt-adapters' }}
uses: ./.github/actions/build-hatch

- name: Build `dbt-tests-adapter`
if: ${{ inputs.package == 'dbt-tests-adapter' }}
uses: ./.github/actions/build-hatch
with:
working-dir: "./dbt-tests-adapter/"

# this step is only needed for the release process
- name: "Upload Build Artifact"
if: ${{ github.event_name == 'workflow_call' }}
uses: actions/upload-artifact@v3
with:
name: ${{ steps.version.outputs.version_number }}
path: |
${{ inputs.changelog_path }}
./dist/
retention-days: 3
6 changes: 3 additions & 3 deletions .github/workflows/release_prep_hatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#

name: Version Bump and Changelog Generation
run-name: Bump ${{ inputs.package }}==${{ inputs.version_number }} for release to ${{ inputs.deploy_to }} and generate changelog
run-name: Bump to ${{ inputs.version_number }} for release to ${{ inputs.deploy_to }} and generate changelog
on:
workflow_call:
inputs:
Expand Down Expand Up @@ -398,7 +398,7 @@ jobs:
- name: "Setup `hatch`"
uses: ./.github/actions/setup-hatch
- name: "Run Unit Tests"
run: hatch run unit-tests:all
run: hatch run unit-tests

run-integration-tests:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -447,7 +447,7 @@ jobs:
python-version: ${{ env.PYTHON_TARGET_VERSION }}

- name: Run tests
run: hatch run integration-tests:all
run: hatch run integration-tests

merge-changes-into-target-branch:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Run unit tests
run: hatch run unit-tests:all
run: hatch run unit-tests
shell: bash

- name: Publish results
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ cython_debug/
# MacOS
.DS_Store

# vscode
# VSCode
.vscode/
.venv/

Expand Down
88 changes: 47 additions & 41 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ This guide assumes users are developing on a Linux or MacOS system.
The following utilities are needed or will be installed in this guide:

- `pip`
- `virturalenv`
- `hatch`
- `git`
- `changie`

If local functional testing is required, then a database instance
and appropriate credentials are also required.

In addition to this guide, users are highly encouraged to read the `dbt-core`
[CONTRIBUTING.md](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md).
Almost all information there is applicable here.
Expand Down Expand Up @@ -66,25 +63,39 @@ Rather than forking `dbt-labs/dbt-adapters`, use `dbt-labs/dbt-adapters` directl

### Installation

1. Ensure the latest version of `pip` is installed:
1. Ensure the latest versions of `pip` and `hatch` are installed:
```shell
pip install --upgrade pip
pip install --user --upgrade pip hatch
```
2. This step is optional, but it's recommended. Configure `hatch` to create its virtual environments in the project. Add this block to your `hatch` `config.toml` file:
```toml
# MacOS: ~/Library/Application Support/hatch/config.toml
[dirs.env]
virtual = ".hatch"
```
2. Configure and activate a virtual environment using `virtualenv` as described in
[Setting up an environment](https://github.com/dbt-labs/dbt-core/blob/HEAD/CONTRIBUTING.md#setting-up-an-environment)
3. Install `dbt-adapters` and development dependencies in the virtual environment
This makes `hatch` create all virtual environments in the project root inside of the directory `/.hatch`, similar to `/.tox` for `tox`.
It also makes it easier to add this environment as a runner in common IDEs like VSCode and PyCharm.
3. Create a `hatch` environment with all of the development dependencies and activate it:
```shell
pip install -e .[dev]
hatch run setup
hatch shell
```
4. Run any commands within the virtual environment by prefixing the command with `hatch run`:
```shell
hatch run <command>
```

When `dbt-adapters` is installed this way, any changes made to the `dbt-adapters` source code
will be reflected in the virtual environment immediately.
## Testing

`dbt-adapters` contains [code quality checks](https://github.com/dbt-labs/dbt-adapters/tree/main/.pre-commit-config.yaml) and [unit tests](https://github.com/dbt-labs/dbt-adapters/tree/main/tests/unit).
While `dbt-tests-adapter` is also hosted in this repo, it requires a concrete adapter to run.

## Testing
### Code quality

`dbt-adapters` contains [unit](https://github.com/dbt-labs/dbt-adapters/tree/main/tests/unit)
and [functional](https://github.com/dbt-labs/dbt-adapters/tree/main/tests/functional) tests.
Code quality checks can run with a single command:
```shell
hatch run code-quality
```

### Unit tests

Expand All @@ -93,43 +104,38 @@ Unit tests can be run locally without setting up a database connection:
```shell
# Note: replace $strings with valid names

# run all unit tests
hatch run unit-test

# run all unit tests in a module
python -m pytest tests/unit/$test_file_name.py
hatch run unit-test tests/unit/$test_file_name.py

# run a specific unit test
python -m pytest tests/unit/$test_file_name.py::$test_class_name::$test_method_name
hatch run unit-test tests/unit/$test_file_name.py::$test_class_name::$test_method_name
```

### Functional tests

Functional tests require a database to test against. There are two primary ways to run functional tests:
### Testing against a development branch

- Tests will run automatically against a dbt Labs owned database during PR checks
- Tests can be run locally by configuring a `test.env` file with appropriate `ENV` variables:
```shell
cp test.env.example test.env
$EDITOR test.env
```
Some changes require a change in `dbt-common` and `dbt-adapters`.
In that case, the dependency on `dbt-common` must be updated to point to the development branch. For example:

> **_WARNING:_** The parameters in `test.env` must link to a valid database.
> `test.env` is git-ignored, but be _extra_ careful to never check in credentials
> or other sensitive information when developing.
```toml
[tool.hatch.envs.default]
dependencies = [
"dbt-common @ git+https://github.com/dbt-labs/dbt-common.git@my-dev-branch",
...,
]
```

Functional tests can be run locally with a valid database connection configured in `test.env`:
This will install `dbt-common` as a snapshot. In other words, if `my-dev-branch` is updated on GitHub, those updates will not be reflected locally.
In order to pick up those updates, the `hatch` environment(s) will need to be rebuilt:

```shell
# Note: replace $strings with valid names

# run all functional tests in a directory
python -m pytest tests/functional/$test_directory
# run all functional tests in a module
python -m pytest tests/functional/$test_dir_and_filename.py
# run all functional tests in a class
python -m pytest tests/functional/$test_dir_and_filename.py::$test_class_name
# run a specific functional test
python -m pytest tests/functional/$test_dir_and_filename.py::$test_class_name::$test__method_name
exit
hatch env prune
hatch shell
```


## Documentation

### User documentation
Expand Down
14 changes: 5 additions & 9 deletions dbt-tests-adapter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ dependencies = [
"dbt-adapters",
"pyyaml",
]

[project.optional-dependencies]
build = [
"wheel",
"twine",
"check-wheel-contents",
]

[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-adapters"
Documentation = "https://docs.getdbt.com"
Expand All @@ -62,7 +54,11 @@ include = ["dbt/tests", "dbt/__init__.py"]

[tool.hatch.envs.build]
detached = true
features = ["build"]
dependencies = [
"wheel",
"twine",
"check-wheel-contents",
]
[tool.hatch.envs.build.scripts]
check-all = [
"- check-wheel",
Expand Down
67 changes: 0 additions & 67 deletions dbt/adapters/record.py

This file was deleted.

2 changes: 2 additions & 0 deletions dbt/adapters/record/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from dbt.adapters.record.handle import RecordReplayHandle
from dbt.adapters.record.cursor.cursor import RecordReplayCursor
Loading

0 comments on commit 098fcf5

Please sign in to comment.