def from_project_root(cls, project_root, cli_vars): """Create a project from a root directory. Reads in dbt_project.yml and packages.yml, if it exists. :param project_root str: The path to the project root to load. :raises DbtProjectError: If the project is missing or invalid, or if the packages file exists and is invalid. :returns Project: The project, with defaults populated. """ project_root = os.path.normpath(project_root) project_yaml_filepath = os.path.join(project_root, 'dbt_project.yml') # get the project.yml contents if not path_exists(project_yaml_filepath): raise DbtProjectError( 'no dbt_project.yml found at expected path {}' .format(project_yaml_filepath) ) if isinstance(cli_vars, compat.basestring): cli_vars = parse_cli_vars(cli_vars) renderer = ConfigRenderer(cli_vars) project_dict = _load_yaml(project_yaml_filepath) rendered_project = renderer.render_project(project_dict) rendered_project['project-root'] = project_root packages_dict = package_data_from_root(project_root) return cls.from_project_config(rendered_project, packages_dict)
def from_project_root(cls, project_root, cli_vars): """Create a project from a root directory. Reads in dbt_project.yml and packages.yml, if it exists. :param project_root str: The path to the project root to load. :raises DbtProjectError: If the project is missing or invalid, or if the packages file exists and is invalid. :returns Project: The project, with defaults populated. """ project_root = os.path.normpath(project_root) project_yaml_filepath = os.path.join(project_root, 'dbt_project.yml') # get the project.yml contents if not path_exists(project_yaml_filepath): raise DbtProjectError( 'no dbt_project.yml found at expected path {}'.format( project_yaml_filepath)) if isinstance(cli_vars, compat.basestring): cli_vars = parse_cli_vars(cli_vars) renderer = ConfigRenderer(cli_vars) project_dict = _load_yaml(project_yaml_filepath) rendered_project = renderer.render_project(project_dict) rendered_project['project-root'] = project_root packages_dict = package_data_from_root(project_root) return cls.from_project_config(rendered_project, packages_dict)
def package_data_from_root(project_root): package_filepath = resolve_path_from_base('packages.yml', project_root) if path_exists(package_filepath): packages_dict = _load_yaml(package_filepath) else: packages_dict = None return packages_dict
def selector_data_from_root(project_root: str) -> Dict[str, Any]: selector_filepath = resolve_path_from_base('selectors.yml', project_root) if path_exists(selector_filepath): selectors_dict = load_yaml_text(load_file_contents(selector_filepath)) else: selectors_dict = None return selectors_dict
def package_data_from_root(project_root): package_filepath = resolve_path_from_base( 'packages.yml', project_root ) if path_exists(package_filepath): packages_dict = _load_yaml(package_filepath) else: packages_dict = None return packages_dict
def _raw_project_from(project_root: str) -> Dict[str, Any]: project_root = os.path.normpath(project_root) project_yaml_filepath = os.path.join(project_root, 'dbt_project.yml') # get the project.yml contents if not path_exists(project_yaml_filepath): raise DbtProjectError( 'no dbt_project.yml found at expected path {}'.format( project_yaml_filepath)) project_dict = _load_yaml(project_yaml_filepath) if not isinstance(project_dict, dict): raise DbtProjectError('dbt_project.yml does not parse to a dictionary') return project_dict
def install(self, project): src_path = self.resolve_path(project) dest_path = self.get_installation_path(project) can_create_symlink = system.supports_symlinks() if system.path_exists(dest_path): if not system.path_is_symlink(dest_path): system.rmdir(dest_path) else: system.remove_file(dest_path) if can_create_symlink: logger.debug(' Creating symlink to local dependency.') system.make_symlink(src_path, dest_path) else: logger.debug(' Symlinks are not available on this ' 'OS, copying dependency.') shutil.copytree(src_path, dest_path)