(self)
Entry point for the init task.
Entry point for the init task.
Entry point for the init task .
def run(self):
        """Entry point for the init task."""
        profiles_dir = flags.PROFILES_DIR
        self.create_profiles_dir(profiles_dir)

        try:
            move_to_nearest_project_dir(self.args)
            in_project = True
        except dbt.exceptions.RuntimeException:
            in_project = False

        if in_project:
            # When dbt init is run inside an existing project,
            # just setup the user's profile.
            fire_event(SettingUpProfile())
            profile_name = self.get_profile_name_from_current_project()
            # If a profile_template.yml exists in the project root, that effectively
            # overrides the profile_template.yml for the given target.
            profile_template_path = Path("profile_template.yml")
            if profile_template_path.exists():
                try:
                    # This relies on a valid profile_template.yml from the user,
                    # so use a try: except to fall back to the default on failure
                    self.create_profile_using_project_profile_template(profile_name)
                    return
                except Exception:
                    fire_event(InvalidProfileTemplateYAML())
            if not self.check_if_can_write_profile(profile_name=profile_name):
                return
            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.
        project_name = self.args.project_name
        if project_name is None:
            # If project name is not provided,
            # ask the user which project name they'd like to use.
            project_name = click.prompt("What is the desired project name?")
        project_path = Path(project_name)
        if project_path.exists():
            fire_event(ProjectNameAlreadyExists(name=project_name))
            return

        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
            )
            f.seek(0)
            f.write(content)
            f.truncate()

        # Ask for adapter only if skip_profile_setup flag is not provided.
        if 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
            )
            msg = self.get_addendum(project_name, profiles_dir)
            fire_event(GetAddendum(msg=msg))
def run ( self ) : profiles_dir = flags . PROFILES_DIR self . create_profiles_dir ( profiles_dir ) try : move_to_nearest_project_dir ( self . args ) in_project = True except dbt . exceptions . RuntimeException : in_project = False if in_project : # When dbt init is run inside an existing project, # just setup the user's profile. fire_event ( SettingUpProfile ( ) ) profile_name = self . get_profile_name_from_current_project ( ) # If a profile_template.yml exists in the project root, that effectively # overrides the profile_template.yml for the given target. profile_template_path = Path ( "profile_template.yml" ) if profile_template_path . exists ( ) : try : # This relies on a valid profile_template.yml from the user, # so use a try: except to fall back to the default on failure self . create_profile_using_project_profile_template ( profile_name ) return except Exception : fire_event ( InvalidProfileTemplateYAML ( ) ) if not self . check_if_can_write_profile ( profile_name = profile_name ) : return 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. project_name = self . args . project_name if project_name is None : # If project name is not provided, # ask the user which project name they'd like to use. project_name = click . prompt ( "What is the desired project name?" ) project_path = Path ( project_name ) if project_path . exists ( ) : fire_event ( ProjectNameAlreadyExists ( name = project_name ) ) return 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 ) f . seek ( 0 ) f . write ( content ) f . truncate ( ) # Ask for adapter only if skip_profile_setup flag is not provided. if 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 ) msg = self . get_addendum ( project_name , profiles_dir ) fire_event ( GetAddendum ( msg = msg ) )