|
1 | | -** replace `dbt-oss-template` with your repository name in all docs |
2 | | - |
3 | | - |
4 | | -# Contributing to `dbt-oss-template` |
5 | | - |
6 | | -`dbt-oss-template` is a template for open source software projects at dbt Labs. |
| 1 | +# Contributing to `dbtp` |
7 | 2 |
|
| 3 | +`dbtp` is a Rust CLI for the dbt Cloud Platform APIs. |
8 | 4 |
|
9 | 5 | 1. [About this document](#about-this-document) |
10 | 6 | 2. [Getting the code](#getting-the-code) |
11 | 7 | 3. [Setting up an environment](#setting-up-an-environment) |
12 | | -4. [Running in development](#running-dbt-oss-template-in-development) |
| 8 | +4. [Running in development](#running-in-development) |
13 | 9 | 5. [Testing](#testing) |
14 | | -6. [Debugging](#debugging) |
15 | | -7. [Adding or modifying a changelog entry](#adding-or-modifying-a-changelog-entry) |
16 | | -8. [Submitting a Pull Request](#submitting-a-pull-request) |
17 | | -9. [Troubleshooting Tips](#troubleshooting-tips) |
| 10 | +6. [Adding a changelog entry](#adding-a-changelog-entry) |
| 11 | +7. [Submitting a Pull Request](#submitting-a-pull-request) |
18 | 12 |
|
19 | 13 | ## About this document |
20 | 14 |
|
21 | | -There are many ways to contribute to the ongoing development of `dbt-oss-template`, such as by participating in discussions and issues. We encourage you to first read our higher-level document: ["Expectations for Open Source Contributors"](https://docs.getdbt.com/docs/contributing/oss-expectations). |
22 | | - |
23 | | -The rest of this document serves as a more granular guide for contributing code changes to `dbt-oss-template` (this repository). It is not intended as a guide for using `dbt-oss-template`, and some pieces assume a level of familiarity with Python development (virtualenvs, `pip`, etc). Specific code snippets in this guide assume you are using macOS or Linux and are comfortable with the command line. |
| 15 | +There are many ways to contribute — opening issues, joining discussions, or submitting code changes. This document focuses on the latter. It assumes familiarity with Rust and the command line. |
24 | 16 |
|
25 | | -If you get stuck, we're happy to help! Drop us a line in the `#dbt-oss-template-development` channel in the [dbt Community Slack](https://community.getdbt.com). |
| 17 | +If you get stuck, open a [GitHub Discussion](https://github.com/trouze/dbtp/discussions) or file an issue. |
26 | 18 |
|
27 | 19 | ### Notes |
28 | 20 |
|
29 | | -- **CLA:** Please note that anyone contributing code to `dbt-oss-template` must sign the [Contributor License Agreement](https://docs.getdbt.com/docs/contributor-license-agreements). If you are unable to sign the CLA, the `dbt-oss-template` maintainers will unfortunately be unable to merge any of your Pull Requests. We welcome you to participate in discussions, open issues, and comment on existing ones. |
30 | | -- **Branches:** All pull requests from community contributors should target the `main` branch (default). |
31 | | -- **Releases**: This repository is never released. |
| 21 | +- **Branches:** All pull requests should target the `main` branch. |
| 22 | +- **CLA:** Contributions are accepted under the [Apache-2.0](LICENSE) license. |
32 | 23 |
|
33 | 24 | ## Getting the code |
34 | 25 |
|
35 | | -### Installing git |
| 26 | +### Prerequisites |
36 | 27 |
|
37 | | -You will need `git` in order to download and modify the source code. |
| 28 | +- [Rust](https://rustup.rs/) (stable toolchain) |
| 29 | +- `git` |
38 | 30 |
|
39 | | -### External contributors |
| 31 | +### Fork and clone |
40 | 32 |
|
41 | | -If you are not a member of the `dbt-labs` GitHub organization, you can contribute to `dbt-oss-template` by forking the `dbt-oss-template` repository. For a detailed overview on forking, check out the [GitHub docs on forking](https://help.github.com/en/articles/fork-a-repo). In short, you will need to: |
| 33 | +External contributors should fork the repository, then clone their fork: |
42 | 34 |
|
43 | | -1. Fork the `dbt-oss-template` repository |
44 | | -2. Clone your fork locally |
45 | | -3. Check out a new branch for your proposed changes |
46 | | -4. Push changes to your fork |
47 | | -5. Open a pull request against `dbt-labs/dbt-oss-template` from your forked repository |
48 | | - |
49 | | -### dbt Labs contributors |
| 35 | +```sh |
| 36 | +git clone https://github.com/<your-username>/dbtp.git |
| 37 | +cd dbtp |
| 38 | +``` |
50 | 39 |
|
51 | | -If you are a member of the `dbt-labs` GitHub organization, you will have push access to the `dbt-oss-template` repo. Rather than forking `dbt-oss-template` to make your changes, just clone the repository, check out a new branch, and push directly to that branch. |
| 40 | +dbt Labs contributors can clone directly and push to a feature branch. |
52 | 41 |
|
53 | 42 | ## Setting up an environment |
54 | 43 |
|
55 | | -There are some tools that will be helpful to you in developing locally. While this is the list relevant for `dbt-oss-template` development, many of these tools are used commonly across open-source python projects. |
56 | | - |
57 | | -### Tools |
| 44 | +No additional setup is required beyond a working Rust toolchain. Install or update via: |
58 | 45 |
|
59 | | -These are the tools used in `dbt-oss-template` development and testing: |
60 | | - |
61 | | -- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting |
62 | | -- [`black`](https://github.com/psf/black) for code formatting |
63 | | -- [`mypy`](https://mypy.readthedocs.io/en/stable/) for static type checking |
64 | | -- [`pre-commit`](https://pre-commit.com) to easily run those checks |
65 | | -- [`changie`](https://changie.dev/) to create changelog entries, without merge conflicts |
66 | | - |
67 | | -A deep understanding of these tools in not required to effectively contribute to `dbt-oss-template`, but we recommend checking out the attached documentation if you're interested in learning more about each one. |
68 | | - |
69 | | -#### Virtual environments |
70 | | - |
71 | | -We strongly recommend using virtual environments when developing code in `dbt-oss-template`. We recommend creating this virtualenv |
72 | | -in the root of the `dbt-oss-template` repository. To create a new virtualenv, run: |
73 | 46 | ```sh |
74 | | -python3 -m venv env |
75 | | -source env/bin/activate |
| 47 | +rustup update stable |
76 | 48 | ``` |
77 | 49 |
|
78 | | -This will create and activate a new Python virtual environment. |
| 50 | +## Running in development |
79 | 51 |
|
80 | | -## Running `dbt-oss-template` in development |
81 | | - |
82 | | -### Installation |
83 | | - |
84 | | -First make sure that you set up your `virtualenv` as described in [Setting up an environment](#setting-up-an-environment). Also ensure you have the latest version of pip installed with `pip install --upgrade pip`. Next, install `dbt-oss-template` (and its dependencies): |
| 52 | +Build and run directly with `cargo`: |
85 | 53 |
|
86 | 54 | ```sh |
87 | | -git |
88 | | -pre-commit install |
| 55 | +cargo build # debug build |
| 56 | +cargo run -- projects list # run a command |
| 57 | +cargo run -- --help # top-level help |
89 | 58 | ``` |
90 | 59 |
|
91 | | -### Running `dbt-oss-template` |
| 60 | +Set environment variables to avoid passing flags every run: |
92 | 61 |
|
93 | | -This repository is just a template and cannot be run. |
| 62 | +```sh |
| 63 | +export DBTP_TOKEN=<your-token> |
| 64 | +export DBTP_ACCOUNT_ID=<your-account-id> |
| 65 | +``` |
94 | 66 |
|
95 | 67 | ## Testing |
96 | 68 |
|
97 | | -Once you're able to manually test that your code change is working as expected, it's important to run existing automated tests, as well as adding some new ones. These tests will ensure that: |
98 | | -- Your code changes do not unexpectedly break other established functionality |
99 | | -- Your code changes can handle all known edge cases |
100 | | -- The functionality you're adding will _keep_ working in the future |
| 69 | +Currently there is no automated test suite — commands are tested manually against a live dbt Cloud instance with the environment variables above. |
101 | 70 |
|
| 71 | +When adding tests in the future, prefer unit tests for pure logic (URL construction, argument parsing, response formatting) that do not require network access. |
102 | 72 |
|
103 | | -### Initial setup |
104 | | - |
105 | | -None needed. |
106 | | - |
107 | | -### Test commands |
108 | | - |
109 | | -No tests included. |
110 | | - |
111 | | - |
112 | | -### Unit, Integration, Functional? |
113 | | - |
114 | | -Here are some general rules for adding tests: |
115 | | -* unit tests (`tests/unit`) don’t need to access a database; "pure Python" tests should be written as unit tests |
116 | | -* functional tests (`tests/functional`) cover anything that interacts with a database, namely adapter |
117 | | - |
118 | | -## Debugging |
| 73 | +```sh |
| 74 | +cargo test # runs any tests in the repo |
| 75 | +``` |
119 | 76 |
|
120 | | -1. The logs for a `dbt run` have stack traces and other information for debugging errors (in `logs/dbt.log` in your project directory). |
121 | | -2. Try using a debugger, like `ipdb`. For pytest: `--pdb --pdbcls=IPython.terminal.debugger:pdb` |
122 | | -3. |
| 77 | +## Code quality |
123 | 78 |
|
124 | | -### Assorted development tips |
125 | | -* Append `# type: ignore` to the end of a line if you need to disable `mypy` on that line. |
126 | | -* Sometimes flake8 complains about lines that are actually fine, in which case you can put a comment on the line such as: # noqa or # noqa: ANNN, where ANNN is the error code that flake8 issues. |
127 | | -* To collect output for `CProfile`, run dbt with the `-r` option and the name of an output file, i.e. `dbt -r dbt.cprof run`. If you just want to profile parsing, you can do: `dbt -r dbt.cprof parse`. `pip` install `snakeviz` to view the output. Run `snakeviz dbt.cprof` and output will be rendered in a browser window. |
| 79 | +CI enforces formatting and lints. Run these locally before pushing: |
128 | 80 |
|
129 | | -## Adding or modifying a CHANGELOG Entry |
| 81 | +```sh |
| 82 | +cargo fmt --check # check formatting (run `cargo fmt` to fix) |
| 83 | +cargo clippy -- -D warnings # lints |
| 84 | +``` |
130 | 85 |
|
131 | | -We use [changie](https://changie.dev) to generate `CHANGELOG` entries. **Note:** Do not edit the `CHANGELOG.md` directly. Your modifications will be lost. |
| 86 | +## Adding a changelog entry |
132 | 87 |
|
133 | | -Follow the steps to [install `changie`](https://changie.dev/guide/installation/) for your system. |
| 88 | +We use [changie](https://changie.dev) to manage the `CHANGELOG.md`. Do not edit `CHANGELOG.md` directly. |
134 | 89 |
|
135 | | -Once changie is installed and your PR is created for a new feature, simply run the following command and changie will walk you through the process of creating a changelog entry: |
| 90 | +Install changie, then run: |
136 | 91 |
|
137 | | -```shell |
| 92 | +```sh |
138 | 93 | changie new |
139 | 94 | ``` |
140 | 95 |
|
141 | | -Commit the file that's created and your changelog entry is complete! |
142 | | - |
143 | | -If you are contributing to a feature already in progress, you will modify the changie yaml file in dbt/.changes/unreleased/ related to your change. If you need help finding this file, please ask within the discussion for the pull request! |
144 | | - |
145 | | -You don't need to worry about which `dbt-oss-template` version your change will go into. Just create the changelog entry with `changie`, and open your PR against the `main` branch. All merged changes will be included in the next minor version of `dbt-oss-template`. The Core maintainers _may_ choose to "backport" specific changes in order to patch older minor versions. In that case, a maintainer will take care of that backport after merging your PR, before releasing the new version of `dbt-oss-template`. |
| 96 | +Commit the generated file in `.changes/unreleased/` alongside your PR. |
146 | 97 |
|
147 | 98 | ## Submitting a Pull Request |
148 | 99 |
|
149 | | -Code can be merged into the current development branch `main` by opening a pull request. A `dbt-oss-template` maintainer will review your PR. They may suggest code revision for style or clarity, or request that you add unit or integration test(s). These are good things! We believe that, with a little bit of help, anyone can contribute high-quality code. |
150 | | - |
151 | | -Automated tests run via GitHub Actions. If you're a first-time contributor, all tests (including code checks and unit tests) will require a maintainer to approve. Changes in the `dbt-oss-template` repository trigger integration tests against Postgres. dbt Labs also provides CI environments in which to test changes to other adapters, triggered by PRs in those adapters' repositories, as well as periodic maintenance checks of each adapter in concert with the latest `dbt-oss-template` code changes. |
152 | | - |
153 | | -Once all tests are passing and your PR has been approved, a `dbt-oss-template` maintainer will merge your changes into the active development branch. And that's it! Happy developing :tada: |
| 100 | +1. Create a branch off `main`. |
| 101 | +2. Make your changes and ensure `cargo build`, `cargo fmt --check`, and `cargo clippy -- -D warnings` all pass. |
| 102 | +3. Add a changelog entry with `changie new`. |
| 103 | +4. Open a PR against `main`. A maintainer will review and merge. |
154 | 104 |
|
155 | | -## Troubleshooting Tips |
156 | | -- Sometimes, the content license agreement auto-check bot doesn't find a user's entry in its roster. If you need to force a rerun, add `@cla-bot check` in a comment on the pull request. |
| 105 | +CI runs automatically on all PRs. Once checks pass and the PR is approved, a maintainer will merge it. |
0 commit comments