src/pybel/io/line_utils.py
def parse_definitions(
    graph: BELGraph,
    enumerated_lines: Iterable[Tuple[int, str]],
    metadata_parser: MetadataParser,
    allow_failures: bool = False,
    use_tqdm: bool = False,
    tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
    """Parse the lines in the definitions section of a BEL script.

    :param graph: A BEL graph
    :param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
    :param metadata_parser: A metadata parser
    :param allow_failures: If true, allows parser to continue past strange failures
    :param use_tqdm: Use :mod:`tqdm` to show a progress bar?
    :param tqdm_kwargs: Keywords to pass to ``tqdm``
    :raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
    :raises: pybel.resources.exc.ResourceError
    :raises: sqlalchemy.exc.OperationalError
    """
    parse_definitions_start_time = time.time()

    if use_tqdm:
        _tqdm_kwargs = dict(desc='Definitions', leave=False)
        if tqdm_kwargs:
            _tqdm_kwargs.update(tqdm_kwargs)
        enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)

    for line_number, line in enumerated_lines:
        try:
            metadata_parser.parseString(line, line_number=line_number)
        except (InconsistentDefinitionError, ResourceError) as e:
            parser_logger.exception(LOG_FMT, line_number, 0, e.__class__.__name__, line)
            raise e
        except OperationalError as e:
            parser_logger.warning(
                'Need to upgrade database. See http://pybel.readthedocs.io/en/latest/installation.html#upgrading',
            )
            raise e
        except Exception as e:
            if not allow_failures:
                exc = MalformedMetadataException(line_number, line, 0)
                _log_parse_exception(graph, exc)
                raise exc from e

    graph.namespace_url.update(metadata_parser.namespace_url_dict)
    graph.namespace_pattern.update({
        keyword: pattern.pattern
        for keyword, pattern in metadata_parser.namespace_to_pattern.items()
    })

    graph.annotation_url.update(metadata_parser.annotation_url_dict)
    graph.annotation_pattern.update({
        keyword: pattern.pattern
        for keyword, pattern in metadata_parser.annotation_to_pattern.items()
    })
    graph.annotation_list.update(metadata_parser.annotation_to_local)

    logger.info('Finished parsing definitions section in %.02f seconds', time.time() - parse_definitions_start_time)

    metadata_parser.ensure_resources()
    logger.info('Finished ensuring namespaces in cache')
Parse the lines in the definitions section of a BEL script.

    :param graph: A BEL graph
    :param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
    :param metadata_parser: A metadata parser
    :param allow_failures: If true, allows parser to continue past strange failures
    :param use_tqdm: Use :mod:`tqdm` to show a progress bar?
    :param tqdm_kwargs: Keywords to pass to ``tqdm``
    :raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
    :raises: pybel.resources.exc.ResourceError
    :raises: sqlalchemy.exc.OperationalError
    
Parse the lines in the definitions section of a BEL script.
Parse the lines in the definitions section of a BEL script .
def parse_definitions(
    graph: BELGraph,
    enumerated_lines: Iterable[Tuple[int, str]],
    metadata_parser: MetadataParser,
    allow_failures: bool = False,
    use_tqdm: bool = False,
    tqdm_kwargs: Optional[Mapping[str, Any]] = None,
) -> None:
    parse_definitions_start_time = time.time()
    if use_tqdm:
        _tqdm_kwargs = dict(desc='Definitions', leave=False)
        if tqdm_kwargs:
            _tqdm_kwargs.update(tqdm_kwargs)
        enumerated_lines = tqdm(list(enumerated_lines), **_tqdm_kwargs)
    for line_number, line in enumerated_lines:
        try:
            metadata_parser.parseString(line, line_number=line_number)
        except (InconsistentDefinitionError, ResourceError) as e:
            parser_logger.exception(LOG_FMT, line_number, 0, e.__class__.__name__, line)
            raise e
        except OperationalError as e:
            parser_logger.warning(
                'Need to upgrade database. See http://pybel.readthedocs.io/en/latest/installation.html#upgrading',
            )
            raise e
        except Exception as e:
            if not allow_failures:
                exc = MalformedMetadataException(line_number, line, 0)
                _log_parse_exception(graph, exc)
                raise exc from e
    graph.namespace_url.update(metadata_parser.namespace_url_dict)
    graph.namespace_pattern.update({
        keyword: pattern.pattern
        for keyword, pattern in metadata_parser.namespace_to_pattern.items()
    })
    graph.annotation_url.update(metadata_parser.annotation_url_dict)
    graph.annotation_pattern.update({
        keyword: pattern.pattern
        for keyword, pattern in metadata_parser.annotation_to_pattern.items()
    })
    graph.annotation_list.update(metadata_parser.annotation_to_local)
    logger.info('Finished parsing definitions section in %.02f seconds', time.time() - parse_definitions_start_time)
    metadata_parser.ensure_resources()
    logger.info('Finished ensuring namespaces in cache')
def parse_definitions ( graph : BELGraph , enumerated_lines : Iterable [ Tuple [ int , str ] ] , metadata_parser : MetadataParser , allow_failures : bool = False , use_tqdm : bool = False , tqdm_kwargs : Optional [ Mapping [ str , Any ] ] = None , ) -> None : parse_definitions_start_time = time . time ( ) if use_tqdm : _tqdm_kwargs = dict ( desc = 'Definitions' , leave = False ) if tqdm_kwargs : _tqdm_kwargs . update ( tqdm_kwargs ) enumerated_lines = tqdm ( list ( enumerated_lines ) , ** _tqdm_kwargs ) for line_number , line in enumerated_lines : try : metadata_parser . parseString ( line , line_number = line_number ) except ( InconsistentDefinitionError , ResourceError ) as e : parser_logger . exception ( LOG_FMT , line_number , 0 , e . __class__ . __name__ , line ) raise e except OperationalError as e : parser_logger . warning ( 'Need to upgrade database. See http://pybel.readthedocs.io/en/latest/installation.html#upgrading' , ) raise e except Exception as e : if not allow_failures : exc = MalformedMetadataException ( line_number , line , 0 ) _log_parse_exception ( graph , exc ) raise exc from e graph . namespace_url . update ( metadata_parser . namespace_url_dict ) graph . namespace_pattern . update ( { keyword : pattern . pattern for keyword , pattern in metadata_parser . namespace_to_pattern . items ( ) } ) graph . annotation_url . update ( metadata_parser . annotation_url_dict ) graph . annotation_pattern . update ( { keyword : pattern . pattern for keyword , pattern in metadata_parser . annotation_to_pattern . items ( ) } ) graph . annotation_list . update ( metadata_parser . annotation_to_local ) logger . info ( 'Finished parsing definitions section in %.02f seconds' , time . time ( ) - parse_definitions_start_time ) metadata_parser . ensure_resources ( ) logger . info ( 'Finished ensuring namespaces in cache' )
Parse the lines in the definitions section of a BEL script.
Parse the lines in the definitions section of a BEL script .
"""Parse the lines in the definitions section of a BEL script.

    :param graph: A BEL graph
    :param enumerated_lines: An enumerated iterable over the lines in the definitions section of a BEL script
    :param metadata_parser: A metadata parser
    :param allow_failures: If true, allows parser to continue past strange failures
    :param use_tqdm: Use :mod:`tqdm` to show a progress bar?
    :param tqdm_kwargs: Keywords to pass to ``tqdm``
    :raises: pybel.parser.parse_exceptions.InconsistentDefinitionError
    :raises: pybel.resources.exc.ResourceError
    :raises: sqlalchemy.exc.OperationalError
    """
None
None
None
graph
BELGraph
A BEL graph
A BEL graph
enumerated_lines
Iterable[Tuple[int, str]]
An enumerated iterable over the lines in the definitions section of a BEL script
An enumerated iterable over the lines in the definitions section of a BEL script
metadata_parser
MetadataParser
A metadata parser
A metadata parser
allow_failures
bool
If true, allows parser to continue past strange failures
If true allows parser to continue past strange failures
use_tqdm
bool
None
tqdm_kwargs
Optional[Mapping[str, Any]]
Keywords to pass to ``tqdm``
Keywords to pass to ` ` tqdm ` `