Beispiel #1
0
def create_dependency_descriptor(requirement_string):
    """
    Create a DependencyDescriptor from a PEP440 compliant string.

    See https://www.python.org/dev/peps/pep-0440/#version-specifiers

    :param str requirement_string: a PEP440 compliant requirement string
    :return: A descriptor with version constraints from the requirement string
    :rtype: DependencyDescriptor
    """
    symbol_mapping = {
        '==': 'version_eq',
        '!=': 'version_neq',
        '<=': 'version_lte',
        '>=': 'version_gte',
        '>': 'version_gt',
        '<': 'version_lt',
    }

    requirement = parse_requirement(requirement_string)
    metadata = {}
    for symbol, version in (requirement.constraints or []):
        if symbol in symbol_mapping:
            metadata[symbol_mapping[symbol]] = version
        elif symbol == '~=':
            metadata['version_gte'] = version
            metadata['version_lt'] = _next_incompatible_version(version)
        else:
            logger.warning(
                "Ignoring unknown symbol '{symbol}' in '{requirement}'".
                format_map(locals()))
    return DependencyDescriptor(requirement.name, metadata=metadata)
Beispiel #2
0
def parse_config(content):
    """
    Parse the Bazel project BUILD file content.

    :param str content: The Bazel BUILD file content.
    :returns: Dictionary of config.
    :rtype: dict
    """
    quoted = QuotedString(quoteChar='"') | QuotedString(quoteChar='\'')
    item_name = pyparsing_common.identifier.setName('id')
    item_value = (
        Group(  # Array values.
            Literal('[').suppress() + delimitedList(quoted) +
            Literal(']').suppress()) | Group(  # Glob case.
                Word('glob([').suppress() + delimitedList(quoted) +
                Word('])').suppress()) | quoted).setName(
                    'value')  # Quoted string value.
    rule_item = Group(item_name + Literal('=').suppress() + item_value +
                      Optional(',').suppress())
    rule_items = Dict(delimitedList(rule_item))
    rule_values = nestedExpr(content=rule_items)
    rule_taret = item_name
    rule = Group(rule_taret + rule_values)
    parser = Dict(OneOrMore(rule))

    try:
        config = parser.parseString(content)
    except Exception as e:
        logger.warning('No valid Build content')
        return {}

    return config.asDict()
Beispiel #3
0
def _get_build_type(pkg):
    """Get the build type of the ROS package."""
    from catkin_pkg.package import InvalidPackage
    try:
        return pkg.get_build_type()
    except InvalidPackage:
        logger.warning(
            "ROS package '{pkg.name}' in '{path}' has more than one "
            'build type'.format_map(locals()))
        return None
Beispiel #4
0
def _extra_deps(value, entry, depends_target, exclude=None):
    if entry in value:
        pattern = Group(
            Optional(Group(Literal('@') + Word(alphanums + '_-')).suppress()) +
            Optional(Literal('//').suppress()) +
            Optional(Word(alphanums + '_-/').suppress()) +
            Optional(Literal(':').suppress()) + Word(alphanums + '_-'))

        for dep in value.get(entry):
            try:
                extract_name = pattern.parseString(dep)[0][0]
                if extract_name != exclude:  # exclude self references
                    depends_target.update({extract_name})
            except Exception as e:
                logger.warning('No valid Build content %s' % dep)
Beispiel #5
0
    def identify(self, desc):  # noqa: D102
        if os.path.realpath(str(desc.path)) in metadata_by_path:
            metadata2 = metadata_by_path[os.path.realpath(str(desc.path))]
            if metadata2.get('type'):
                if desc.type is None:
                    desc.type = metadata2.get('type')
                    logger.info("Package '{desc.path}' has configured type "
                                "'{desc.type}'".format_map(locals()))
                elif desc.type != metadata2.get('type'):
                    logger.warning(
                        "type '%s' of package '%s' does not match configured "
                        "type '%s'", desc.type, desc.path,
                        metadata2.get('type'))
            if metadata2.get('name'):
                if desc.name is None:
                    desc.name = metadata2.get('name')
                    logger.info("Package '{desc.path}' has configured name "
                                "'{desc.name}'".format_map(locals()))
                elif desc.name != metadata2.get('name'):
                    logger.warning(
                        "name '%s' of package '%s' does not match configured "
                        "name '%s'", desc.name, desc.path,
                        metadata2.get('name'))

        if desc.name in metadata_by_name:
            data = metadata_by_name[desc.name]
            if 'type' in data:
                # if the package name was defined based on the path
                # then ignore the type defined for the package name
                if desc.type is not None and desc.type != data['type']:
                    logger.warning(
                        "type '{desc.type}' of package '{desc.name}' "
                        "does not match configured type '{data[type]}'".
                        format_map(locals()))
                else:
                    desc.type = data['type']