Skip to content
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

Add src directory structure for dbt-adapters #357

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:

- name: Build `dbt-adapters`
uses: ./.github/actions/build-hatch
with:
working-dir: "./dbt-adapters/"

- name: Build `dbt-tests-adapter`
uses: ./.github/actions/build-hatch
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ jobs:
- name: Setup `hatch`
uses: ./.github/actions/setup-hatch

- name: Run code quality
- name: Run code quality for dbt-adapters
shell: bash
run: hatch run code-quality
working-directory: "./dbt-adapters/"

- name: Run code quality for dbt-tests-adapter
shell: bash
run: hatch run code-quality
working-directory: "./dbt-tests-adapter/"
9 changes: 2 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,26 @@ jobs:
name: "Release inputs"
runs-on: ubuntu-latest
outputs:
working-dir: ${{ steps.release-inputs.outputs.working-dir }}
run-unit-tests: ${{ steps.release-inputs.outputs.run-unit-tests }}
archive-name: ${{ steps.release-inputs.outputs.archive-name }}
steps:
- name: "Inputs"
id: release-inputs
run: |
working_dir="./"
run_unit_tests=true
archive_name=${{ inputs.package }}-${{ inputs.version_number }}-${{ inputs.deploy-to }}

if test "${{ inputs.package }}" = "dbt-tests-adapter"
then
working_dir="./dbt-tests-adapter/"
run_unit_tests=false
fi

echo "working-dir=$working_dir" >> $GITHUB_OUTPUT
echo "run-unit-tests=$run_unit_tests" >> $GITHUB_OUTPUT
echo "archive-name=$archive_name" >> $GITHUB_OUTPUT

- name: "[DEBUG]"
run: |
echo package : ${{ inputs.package }}
echo working-dir : ${{ steps.release-inputs.outputs.working-dir }}
echo run-unit-tests : ${{ steps.release-inputs.outputs.run-unit-tests }}
echo archive-name : ${{ steps.release-inputs.outputs.archive-name }}

Expand All @@ -113,7 +108,7 @@ jobs:
deploy_to: ${{ inputs.deploy-to }}
nightly_release: ${{ inputs.nightly_release }}
target_branch: ${{ inputs.target_branch }}
working-dir: ${{ needs.release-inputs.outputs.working-dir }}
working-dir: ./${{ inputs.package }}/
run-unit-tests: ${{ fromJSON(needs.release-inputs.outputs.run-unit-tests) }}
secrets: inherit

Expand Down Expand Up @@ -146,7 +141,7 @@ jobs:
- name: "Build ${{ inputs.package }}"
uses: dbt-labs/dbt-adapters/.github/actions/build-hatch@main
with:
working-dir: ${{ needs.release-inputs.outputs.working-dir }}
working-dir: ./${{ inputs.package }}/
archive-name: ${{ needs.release-inputs.outputs.archive-name }}

github-release:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_prep_hatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ jobs:
- name: "Remove Trailing Whitespace Via Pre-commit"
continue-on-error: true
run: |
pre-commit run trailing-whitespace --files dbt/adapters/__about__.py CHANGELOG.md .changes/*
pre-commit run trailing-whitespace --files dbt/adapters/__version__.py CHANGELOG.md .changes/*
git status
# this step will fail on newline errors but also correct them
- name: "Removing Extra Newlines Via Pre-commit"
continue-on-error: true
run: |
pre-commit run end-of-file-fixer --files dbt/adapters/__about__.py CHANGELOG.md .changes/*
pre-commit run end-of-file-fixer --files dbt/adapters/__version__.py CHANGELOG.md .changes/*
git status
- name: "Commit & Push Changes"
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
- name: Run unit tests
run: hatch run unit-tests
shell: bash
working-directory: ./dbt-adapters/

- name: Publish results
uses: ./.github/actions/publish-results
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ repos:
- --target-version=py310
- --target-version=py311
- --target-version=py312
- --force-exclude=dbt/adapters/events/adapter_types_pb2.py
- --force-exclude=dbt-adapters/src/dbt/adapters/events/adapter_types_pb2.py

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
exclude: dbt/adapters/events/adapter_types_pb2.py|tests/functional/
exclude: dbt-adapters/src/dbt/adapters/events/adapter_types_pb2.py|tests/functional/
args:
- --max-line-length=99
- --select=E,F,W
Expand All @@ -44,7 +44,7 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
exclude: dbt/adapters/events/adapter_types_pb2.py|dbt-tests-adapter/dbt/__init__.py
exclude: dbt-adapters/src/dbt/adapters/events/adapter_types_pb2.py|dbt-tests-adapter/dbt/__init__.py
args:
- --explicit-package-bases
- --ignore-missing-imports
Expand Down
45 changes: 32 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to `dbt-adapters`
# Contributing

- [About this document](#about-this-document)
- [Getting the code](#getting-the-code)
Expand All @@ -7,11 +7,15 @@
- [Documentation](#documentation)
- [Submitting a pull request](#submitting-a-pull-request)


## About this document

This document is a guide for anyone interested in contributing to `dbt-adapters`.
It outlines how to install `dbt-adapters` for development,
This document is a guide for anyone interested in contributing to this repository.
This repository is a collection of packages, each with their own nuances;
however, all package share significant overlap, which is covered here.
For more information on how to contribute to a specific package,
please refer to that package's `CONTRIBUTING.md`.

This document outlines how to install a package for development,
run tests locally, update documentation, and submit pull requests.
This guide assumes users are developing on a Linux or MacOS system.
The following utilities are needed or will be installed in this guide:
Expand All @@ -25,18 +29,17 @@ 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.


## Getting the code

`git` is required to download, modify, and sync the `dbt-adapters` code.
`git` is required to download, modify, and sync code.
There are several ways to install Git. For MacOS:

- Install [Xcode](https://developer.apple.com/support/xcode/)
- Install [Xcode Command Line Tools](https://mac.install.guide/commandlinetools/index.html)

### External contributors

Contributors external to the `dbt-labs` GitHub organization can contribute to `dbt-adapters`
Contributors external to the `dbt-labs` GitHub organization can contribute to this repository
by forking the `dbt-adapters` repository. For more on forking, check out the
[GitHub docs on forking](https://help.github.com/en/articles/fork-a-repo). To contribute:

Expand All @@ -58,7 +61,6 @@ Rather than forking `dbt-labs/dbt-adapters`, use `dbt-labs/dbt-adapters` directl
4. Push the new branch to `dbt-labs/dbt-adapters`
5. Open a pull request in `dbt-labs/dbt-adapters` to merge `{new-branch}` into `main`


## Developing

### Installation
Expand All @@ -67,15 +69,27 @@ Rather than forking `dbt-labs/dbt-adapters`, use `dbt-labs/dbt-adapters` directl
```shell
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:
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"
```
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:
3. Navigate to the package that you are working on. Note that because this repository is a monorepo,
you will have multiple packages, each with their own set of virtual environments.
```shell
ls
> .github dbt-adapters dbt-tests-adapter docs third-party-stubs .changie.yml .gitignore ...

cd dbt-adapters

ls
> .changes src tests CHANGELOG.md CONTRIBUTING.md pyproject.toml README.md
```
4. Create a `hatch` environment with all of the development dependencies and activate it:
```shell
hatch run setup
hatch shell
Expand All @@ -87,8 +101,11 @@ Rather than forking `dbt-labs/dbt-adapters`, use `dbt-labs/dbt-adapters` directl

## 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.
The `dbt-adapters` repo contains
[code quality checks](https://github.com/dbt-labs/dbt-adapters/tree/main/.pre-commit-config.yaml)
that will run across the entire repo.
Additionally, each package has their own unit tests and functional tests. See your particular
package's `CONTRIBUTING.md` for more information regarding these tests.

### Code quality

Expand All @@ -102,7 +119,9 @@ hatch run code-quality
Unit tests can be run locally without setting up a database connection:

```shell
# Note: replace $strings with valid names
# Note:
# - replace $strings with valid names
# - ensure that you are in the project directory, and not the repo root

# run all unit tests
hatch run unit-test
Expand Down
42 changes: 5 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,10 @@
<img src="https://raw.githubusercontent.com/dbt-labs/dbt/ec7dee39f793aa4f7dd3dae37282cc87664813e4/etc/dbt-logo-full.svg" alt="dbt logo" width="500"/>
</p>

# dbt-tests-adapter
# dbt Adapters

This package is responsible for:
This repository contains the base adapter protocols, a collection of adapter implementations, and a testing suite.
For more information about a specific package, please navigate to the appropriate page:

- defining database connection methods
- caching information from databases
- determining how relations are defined

There are two major adapter types: base and sql

# Directories

## `base`

Defines the base implementation Adapters can use to build out full functionality.

## `sql`

Defines a sql implementation for adapters that initially inherits the base implementation
and comes with some pre-made methods and macros that can be overwritten as needed per adapter.
(most common type of adapter.)

# Files

## `cache.py`

Cached information from the database.

## `factory.py`

Defines how we generate adapter objects

## `protocol.py`

Defines various interfaces for various adapter objects. Helps mypy correctly resolve methods.

## `reference_keys.py`

Configures naming scheme for cache elements to be universal.
- `dbt-adapters` ([link](https://github.com/dbt-labs/dbt-adapters/dbt-adapters))
- `dbt-tests-adapter` ([link](https://github.com/dbt-labs/dbt-adapters/dbt-tests-adapter))
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.
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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Migrate dbt-adapters to be a subpackage within the dbt-adapters repo
time: 2024-11-16T18:10:28.184962-05:00
custom:
Author: mikealfare
Issue: "357"
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions dbt-adapters/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing to `dbt-adapters`

- [About this document](#about-this-document)
- [Developing](#developing)
- [Testing](#testing)

## About this document

This document covers contribution topics that specifically pertain to `dbt-adapters` (the package, not the repo).
Most topics are covered in the primary `CONTRIBUTING.md` doc; we expect this to develop over time.

## Developing

Make sure to always navigate to the `dbt-adapters` package subdirectory when working on this package.
Once you are in this directory, then things will behave as if this were not a monorepo.
For example, to initially create this package's virtual environment, run these commands:

```shell
cd dbt-adapters
hatch run setup
hatch shell
```

You will not need to run `cd dbt-adapters` every time you run a command.
But if you use an IDE such as PyCharm, you will likely need to run it each time you open a fresh terminal.

## Testing

The `dbt-adapters` package is subject to the general
[code quality checks](https://github.com/dbt-labs/dbt-adapters/tree/main/.pre-commit-config.yaml).
Additionally, there are [unit tests](https://github.com/dbt-labs/dbt-adapters/tree/main/tests/unit)
that are specific to `dbt-adapters`. There are no functional tests as these would require a database.
43 changes: 43 additions & 0 deletions dbt-adapters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<p align="center">
<img src="https://raw.githubusercontent.com/dbt-labs/dbt/ec7dee39f793aa4f7dd3dae37282cc87664813e4/etc/dbt-logo-full.svg" alt="dbt logo" width="500"/>
</p>

# dbt-adapters

This package is responsible for:

- defining database connection methods
- caching information from databases
- determining how relations are defined

There are two major adapter types: base and sql

# Directories

## `base`

Defines the base implementation Adapters can use to build out full functionality.

## `sql`

Defines a sql implementation for adapters that initially inherits the base implementation
and comes with some pre-made methods and macros that can be overwritten as needed per adapter.
(most common type of adapter.)

# Files

## `cache.py`

Cached information from the database.

## `factory.py`

Defines how we generate adapter objects

## `protocol.py`

Defines various interfaces for various adapter objects. Helps mypy correctly resolve methods.

## `reference_keys.py`

Configures naming scheme for cache elements to be universal.
14 changes: 8 additions & 6 deletions pyproject.toml → dbt-adapters/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ dependencies = [
"typing-extensions>=4.0,<5.0",
]
[project.urls]
Homepage = "https://github.com/dbt-labs/dbt-adapters"
Homepage = "https://github.com/dbt-labs/dbt-adapters/dbt-adapters"
Documentation = "https://docs.getdbt.com"
Repository = "https://github.com/dbt-labs/dbt-adapters.git"
Repository = "https://github.com/dbt-labs/dbt-adapters.git#subdirectory=dbt-adapters"
Issues = "https://github.com/dbt-labs/dbt-adapters/issues"
Changelog = "https://github.com/dbt-labs/dbt-adapters/blob/main/CHANGELOG.md"
Changelog = "https://github.com/dbt-labs/dbt-adapters/blob/main/dbt-adapters/CHANGELOG.md"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.version]
path = "dbt/adapters/__about__.py"
path = "src/dbt/adapters/__version__.py"

[tool.hatch.build.targets.sdist]
include = ["dbt/adapters", "dbt/include", "dbt/__init__.py"]
packages = ["src/dbt/adapters", "src/dbt/include", "dbt/__init__.py"]
sources = ["src"]

[tool.hatch.build.targets.wheel]
include = ["dbt/adapters", "dbt/include", "dbt/__init__.py"]
packages = ["src/dbt/adapters", "src/dbt/include", "dbt/__init__.py"]
sources = ["src"]

[tool.hatch.envs.default]
dependencies = [
Expand Down
File renamed without changes.
File renamed without changes.
Loading
Loading