Skip to content

Commit

Permalink
Allow the target name to be set in profile_template.yml (#5184)
Browse files Browse the repository at this point in the history
* Allow the target name to be set in profile_template.yml
  • Loading branch information
alexrosenfeld10 committed May 3, 2022
1 parent a4376b9 commit a2e040f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Features-20220428-065644.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: allow target as an option in profile_template.yml
time: 2022-04-28T06:56:44.511519-04:00
custom:
Author: alexrosenfeld10
Issue: "5179"
PR: "5184"
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
1. [About this document](#about-this-document)
2. [Getting the code](#getting-the-code)
3. [Setting up an environment](#setting-up-an-environment)
4. [Running `dbt` in development](#running-dbt-in-development)
4. [Running `dbt` in development](#running-dbt-core-in-development)
5. [Testing dbt-core](#testing)
6. [Submitting a Pull Request](#submitting-a-pull-request)

Expand Down Expand Up @@ -56,10 +56,10 @@ These are the tools used in `dbt-core` development and testing:
- [`flake8`](https://flake8.pycqa.org/en/latest/) for code linting
- [`black`](https://github.com/psf/black) for code formatting
- [`mypy`](https://mypy.readthedocs.io/en/stable/) for static type checking
- [`pre-commit`](https.pre-commit.com) to easily run those checks
- [`pre-commit`](https://pre-commit.com) to easily run those checks
- [`changie`](https://changie.dev/) to create changelog entries, without merge conflicts
- [`make`](https://users.cs.duke.edu/~ola/courses/programming/Makefiles/Makefiles.html) to run multiple setup or test steps in combination. Don't worry too much, nobody _really_ understands how `make` works, and our Makefile aims to be super simple.
- [Github Actions](https://github.com/features/actions) for automating tests and checks, once a PR is pushed to the `dbt-core` repository
- [GitHub Actions](https://github.com/features/actions) for automating tests and checks, once a PR is pushed to the `dbt-core` repository

A deep understanding of these tools in not required to effectively contribute to `dbt-core`, but we recommend checking out the attached documentation if you're interested in learning more about each one.

Expand Down Expand Up @@ -144,14 +144,14 @@ make test
# Runs postgres integration tests with py38 in "fail fast" mode.
make integration
```
> These make targets assume you have a local install of a recent version of [`tox`](https://tox.readthedocs.io/en/latest/) for unit/integration testing and pre-commit for code quality checks,
> These make targets assume you have a local installation of a recent version of [`tox`](https://tox.readthedocs.io/en/latest/) for unit/integration testing and pre-commit for code quality checks,
> unless you use choose a Docker container to run tests. Run `make help` for more info.
Check out the other targets in the Makefile to see other commonly used test
suites.

#### `pre-commit`
[`pre-commit`](https.pre-commit.com) takes care of running all code-checks for formatting and linting. Run `make dev` to install `pre-commit` in your local environment. Once this is done you can use any of the linter-based make targets as well as a git pre-commit hook that will ensure proper formatting and linting.
[`pre-commit`](https://pre-commit.com) takes care of running all code-checks for formatting and linting. Run `make dev` to install `pre-commit` in your local environment. Once this is done you can use any of the linter-based make targets as well as a git pre-commit hook that will ensure proper formatting and linting.

#### `tox`

Expand Down
3 changes: 2 additions & 1 deletion core/dbt/task/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def create_profile_from_profile_template(self, profile_template: dict, profile_n
initial_target = profile_template.get("fixed", {})
prompts = profile_template.get("prompts", {})
target = self.generate_target_from_input(prompts, initial_target)
profile = {"outputs": {"dev": target}, "target": "dev"}
target_name = target.pop("target", "dev")
profile = {"outputs": {target_name: target}, "target": target_name}
self.write_profile(profile, profile_name)

def create_profile_from_target(self, adapter: str, profile_name: str):
Expand Down
2 changes: 1 addition & 1 deletion plugins/postgres/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _dbt_psycopg2_name():

package_name = "dbt-postgres"
package_version = "1.2.0a1"
description = """The postgres adpter plugin for dbt (data build tool)"""
description = """The postgres adapter plugin for dbt (data build tool)"""

this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, "README.md")) as f:
Expand Down
10 changes: 8 additions & 2 deletions test/integration/040_init_tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ def exists_side_effect(path):
host: localhost
dbname: my_db
schema: my_schema
target: my_target
prompts:
target:
hint: 'The target name'
type: string
port:
hint: 'The port (for integer test purposes)'
type: int
Expand All @@ -220,12 +224,14 @@ def exists_side_effect(path):
manager.attach_mock(mock_prompt, 'prompt')
manager.attach_mock(mock_confirm, 'confirm')
manager.prompt.side_effect = [
'my_target',
5432,
'test_username',
'test_password'
]
self.run_dbt(['init'])
manager.assert_has_calls([
call.prompt('target (The target name)', default=None, hide_input=False, type=click.STRING),
call.prompt('port (The port (for integer test purposes))', default=5432, hide_input=False, type=click.INT),
call.prompt('user (Your username)', default=None, hide_input=False, type=None),
call.prompt('pass (Your password)', default=None, hide_input=True, type=None)
Expand All @@ -234,7 +240,7 @@ def exists_side_effect(path):
with open(os.path.join(self.test_root_dir, 'profiles.yml'), 'r') as f:
assert f.read() == """test:
outputs:
dev:
my_target:
dbname: my_db
host: localhost
pass: test_password
Expand All @@ -243,7 +249,7 @@ def exists_side_effect(path):
threads: 4
type: postgres
user: test_username
target: dev
target: my_target
"""

@use_profile('postgres')
Expand Down

0 comments on commit a2e040f

Please sign in to comment.