-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Use profile specified in --profile with dbt init #7450
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
Changes from 1 commit
9179070
2755820
f8d66f8
7e921ce
9a58a15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| from pathlib import Path | ||
| import re | ||
| import shutil | ||
| import sys | ||
| from typing import Optional | ||
|
|
||
| import yaml | ||
|
|
@@ -248,11 +249,11 @@ def get_valid_project_name(self) -> str: | |
|
|
||
| return name | ||
|
|
||
| def create_new_project(self, project_name: str): | ||
| def create_new_project(self, project_name: str, profile_name: str): | ||
| self.copy_starter_repo(project_name) | ||
| os.chdir(project_name) | ||
| with open("dbt_project.yml", "r") as f: | ||
| content = f"{f.read()}".format(project_name=project_name, profile_name=project_name) | ||
| content = f"{f.read()}".format(project_name=project_name, profile_name=profile_name) | ||
| with open("dbt_project.yml", "w") as f: | ||
| f.write(content) | ||
| fire_event( | ||
|
|
@@ -286,6 +287,7 @@ def run(self): | |
| # When dbt init is run inside an existing project, | ||
| # just setup the user's profile. | ||
| profile_name = self.get_profile_name_from_current_project() | ||
| profile_specified = False | ||
| else: | ||
| # When dbt init is run outside of an existing project, | ||
| # create a new project and set up the user's profile. | ||
|
|
@@ -294,11 +296,25 @@ def run(self): | |
| if project_path.exists(): | ||
| fire_event(ProjectNameAlreadyExists(name=project_name)) | ||
| return | ||
| self.create_new_project(project_name) | ||
| profile_name = project_name | ||
|
|
||
| # Ask for adapter only if skip_profile_setup flag is not provided. | ||
| if not self.args.skip_profile_setup: | ||
| # If the user specified an existing profile to use, use it instead of generating a new one | ||
| user_profile_name = getattr(get_flags(), "PROFILE", None) | ||
| if user_profile_name: | ||
| # Verify it exists. Can't use the regular profile validation routine because it assumes | ||
| # the project file exists | ||
| raw_profiles = read_profile(profiles_dir) | ||
| if user_profile_name not in raw_profiles: | ||
ezraerb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| print("Could not find profile named '{}'".format(user_profile_name)) | ||
| sys.exit(1) | ||
| profile_name = user_profile_name | ||
| profile_specified = True | ||
| else: | ||
| profile_name = project_name | ||
| profile_specified = False | ||
| self.create_new_project(project_name, profile_name) | ||
|
|
||
| # Ask for adapter only if skip_profile_setup flag is not provided and no profile to use was specified. | ||
| if not self.args.skip_profile_setup and not profile_specified: | ||
|
||
| fire_event(SettingUpProfile()) | ||
| if not self.check_if_can_write_profile(profile_name=profile_name): | ||
| return | ||
|
|
@@ -315,52 +331,3 @@ def run(self): | |
| fire_event(InvalidProfileTemplateYAML()) | ||
| adapter = self.ask_for_adapter_choice() | ||
| self.create_profile_from_target(adapter, profile_name=profile_name) | ||
| return | ||
|
|
||
| # When dbt init is run outside of an existing project, | ||
| # create a new project and set up the user's profile. | ||
| available_adapters = list(_get_adapter_plugin_names()) | ||
| if not len(available_adapters): | ||
| print("No adapters available. Go to https://docs.getdbt.com/docs/available-adapters") | ||
| sys.exit(1) | ||
| project_name = self.get_valid_project_name() | ||
| project_path = Path(project_name) | ||
| if project_path.exists(): | ||
| fire_event(ProjectNameAlreadyExists(name=project_name)) | ||
| return | ||
|
|
||
| # If the user specified an existing profile to use, use it instead of generating a new one | ||
| user_profile_name = getattr(get_flags(), "PROFILE", None) | ||
| if user_profile_name: | ||
| # Verify it exists. Can't use the regular profile validation routine because it assumes | ||
| # the project file exists | ||
| raw_profiles = read_profile(profiles_dir) | ||
| if user_profile_name not in raw_profiles: | ||
| print("Could not find profile named '{}'".format(user_profile_name)) | ||
| sys.exit(1) | ||
|
|
||
| self.copy_starter_repo(project_name) | ||
| os.chdir(project_name) | ||
| with open("dbt_project.yml", "r+") as f: | ||
| content = f"{f.read()}".format( | ||
| project_name=project_name, | ||
| profile_name=user_profile_name if user_profile_name else project_name, | ||
| ) | ||
| f.seek(0) | ||
| f.write(content) | ||
| f.truncate() | ||
|
|
||
| # If an existing profile to use was not provided, generate a profile | ||
| # Ask for adapter only if skip_profile_setup flag is not provided. | ||
| if not user_profile_name and not self.args.skip_profile_setup: | ||
| if not self.check_if_can_write_profile(profile_name=project_name): | ||
| return | ||
| adapter = self.ask_for_adapter_choice() | ||
| self.create_profile_from_target(adapter, profile_name=project_name) | ||
| fire_event( | ||
| ProjectCreated( | ||
| project_name=project_name, | ||
| docs_url=DOCS_URL, | ||
| slack_url=SLACK_URL, | ||
| ) | ||
| ) | ||

Uh oh!
There was an error while loading. Please reload this page.