def _load_supporting_docs(cfg, build_unit, build_monitor): """ Context manager to load supporting documents into a build unit. --- type: context_manager args: cfg: A mapping holding the build configuration. build_unit: A mapping with information about a single detailed design document (source file) together with it's supporting specifications and tests. build_monitor: A reference to the build monitoring and progress reporting coroutine. yields: build_unit: A mapping with information about a single detailed design document (source file) together with it's supporting specifications and tests. ... """ filepath = build_unit['filepath'] filepath_spec = da.lwc.file.specification_filepath_for(filepath) has_supporting_docs = ( da.lwc.file.is_design_file(filepath) and os.path.isfile(filepath_spec)) if has_supporting_docs: with open(filepath_spec, 'rb') as file: content = file.read().decode('utf-8') build_unit['spec'] = { 'filepath': filepath_spec, 'relpath': os.path.relpath( filepath_spec, cfg['paths']['dirpath_isolated_src']), 'file': file, 'content': content } # Add build_unit['spec']['ast'] if file parses OK... build_unit['spec'] = _try_parse(build_unit['spec'], build_monitor) # Yield with open filepath_spec... yield build_unit else: yield build_unit return
def _load_design_doc(cfg, filepath, build_monitor): """ Context manager to load the design document into a build unit. --- type: context_manager args: cfg: A mapping holding the build configuration. filepath: A design document filepath. build_monitor: A reference to the build monitoring and progress reporting coroutine. yields: build_unit: A mapping with information about a single detailed design document (source file) together with it's supporting specifications and tests. ... """ rootpath_log = cfg['paths']['dirpath_branch_log'] # TODO: If possible (python >= 3.2) use tokenize.open to open # files, so PEP 263 encoding markers are interpreted. # We will need to go through and update all the processes # that make use of the file handle though ... # with open(filepath, 'rb') as file: content = file.read().decode('utf-8') relpath = os.path.relpath(filepath, cfg['paths']['dirpath_isolated_src']) (relpath_dir, filename) = os.path.split(relpath) dirpath_log = os.path.join( rootpath_log, relpath_dir, filename.replace('.', '_')) build_unit = { 'filepath': filepath, 'relpath': relpath, 'file': file, 'content': content, 'dirpath_log': dirpath_log } # Add build_unit['ast'] if file parses OK... build_unit = _try_parse(build_unit, build_monitor) # Yield with open filepath... yield build_unit return