def install_tools() -> NoReturn: """ Install the build tools. Doesn't work inside a Docker container. """ info('"course install-tools" is deprecated, because it is not possible ' 'to update a Docker container from within itself. To update the ' 'build tools, run the following command:\n\n' 'curl -L https://git.io/fhaLg | bash')
def import_dbc(dbc: str, build: bdc.BuildData) -> NoReturn: ''' Import a single DBC. Assumes (a) the working directory is the build directory, and (b) that the remote target path has already been created. ''' w = databricks.Workspace(profile=db_profile) if build.has_profiles: parent_subpath = os.path.dirname(dbc) dir_to_make = f'{remote_target}/{os.path.dirname(parent_subpath)}' w.mkdirs(dir_to_make) remote_path = f'{remote_target}/{parent_subpath}' else: remote_path = remote_target info(f'Importing "{dbc}" to "{remote_path}"...') w.import_dbc(dbc, remote_path)
def import_dbcs(cfg: Dict[str, str], build_dir: str, build_file: str) -> NoReturn: """ Find all DBC files under the build output directory for the current course, and upload them (import them) into the Databricks instance. :param cfg: The config. COURSE_NAME, COURSE_REMOTE_TARGET, and DB_PROFILE are assumed to be set. :param build_dir: The path to the build directory. :return: NOthing """ check_config(cfg) remote_target = cfg['COURSE_REMOTE_TARGET'] db_profile = cfg['DB_PROFILE'] def import_dbc(dbc: str, build: bdc.BuildData) -> NoReturn: ''' Import a single DBC. Assumes (a) the working directory is the build directory, and (b) that the remote target path has already been created. ''' w = databricks.Workspace(profile=db_profile) if build.has_profiles: parent_subpath = os.path.dirname(dbc) dir_to_make = f'{remote_target}/{os.path.dirname(parent_subpath)}' w.mkdirs(dir_to_make) remote_path = f'{remote_target}/{parent_subpath}' else: remote_path = remote_target info(f'Importing "{dbc}" to "{remote_path}"...') w.import_dbc(dbc, remote_path) # Get the build information. We'll need it later. build = bdc.bdc_load_build(build_file) print( f'Importing all DBCs under "{build_dir}" to remote "{remote_target}"') dbcs = [] with working_directory(build_dir) as pwd: for dirpath, _, filenames in os.walk('.'): for filename in filenames: _, ext = os.path.splitext(filename) if ext != '.dbc': continue dbcs.append(os.path.normpath(os.path.join(dirpath, filename))) if not dbcs: warn('No DBCs found.') else: clean(cfg) w = databricks.Workspace(profile=db_profile) # If we're doing a profile-based build, create the remote target. # The import operations will implicitly create the remote # subfolders. However, if we're not doing profile-based builds, # then creating the remote target ahead of time will cause the # import to fail, so don't do that. if build.has_profiles: w.mkdirs(remote_target) for dbc in dbcs: info(f'\nIn "{pwd}":') import_dbc(dbc, build)