Ejemplo n.º 1
0
def test_parse_anonymous_specs(spec, anon_spec, spec_name):

    expected = parse(spec)
    spec = parse_anonymous_spec(anon_spec, spec_name)

    assert len(expected) == 1
    assert spec in expected
Ejemplo n.º 2
0
    def _execute(pkg):
        # If when is not specified the conflict always holds
        condition = pkg.name if when is None else when
        when_spec = parse_anonymous_spec(condition, pkg.name)

        when_spec_list = pkg.conflicts.setdefault(conflict_spec, [])
        when_spec_list.append(when_spec)
Ejemplo n.º 3
0
def argument_factory(argument_spec, left):
    try:
        # If it's not anonymous, allow it
        right = target_factory(argument_spec, False)
    except Exception:
        right = parse_anonymous_spec(argument_spec, left.name)
    return right
Ejemplo n.º 4
0
 def _execute(pkg):
     constraint = pkg.name if when is None else when
     when_spec = parse_anonymous_spec(constraint, pkg.name)
     cur_patches = pkg.patches.setdefault(when_spec, [])
     # if this spec is identical to some other, then append this
     # patch to the existing list.
     cur_patches.append(Patch.create(pkg, url_or_filename, level, **kwargs))
Ejemplo n.º 5
0
 def _execute(pkg):
     constraint = pkg.name if when is None else when
     when_spec = parse_anonymous_spec(constraint, pkg.name)
     cur_patches = pkg.patches.setdefault(when_spec, [])
     # if this spec is identical to some other, then append this
     # patch to the existing list.
     cur_patches.append(Patch.create(pkg, url_or_filename, level, **kwargs))
Ejemplo n.º 6
0
    def _execute(pkg):
        when = kwargs.get('when', pkg.name)
        destination = kwargs.get('destination', "")
        placement = kwargs.get('placement', None)

        # Check if the path is relative
        if os.path.isabs(destination):
            message = 'The destination keyword of a resource directive '
            'can\'t be an absolute path.\n'
            message += "\tdestination : '{dest}\n'".format(dest=destination)
            raise RuntimeError(message)

        # Check if the path falls within the main package stage area
        test_path = 'stage_folder_root'
        normalized_destination = os.path.normpath(
            join_path(test_path, destination)
        )  # Normalized absolute path

        if test_path not in normalized_destination:
            message = "The destination folder of a resource must fall "
            "within the main package stage directory.\n"
            message += "\tdestination : '{dest}'\n".format(dest=destination)
            raise RuntimeError(message)

        when_spec = parse_anonymous_spec(when, pkg.name)
        resources = pkg.resources.setdefault(when_spec, [])
        name = kwargs.get('name')
        fetcher = from_kwargs(**kwargs)
        resources.append(Resource(name, fetcher, destination, placement))
Ejemplo n.º 7
0
    def _execute(pkg):
        # If when is not specified the conflict always holds
        condition = pkg.name if when is None else when
        when_spec = parse_anonymous_spec(condition, pkg.name)

        when_spec_list = pkg.conflicts.setdefault(conflict_spec, [])
        when_spec_list.append(when_spec)
Ejemplo n.º 8
0
def resource(pkg, **kwargs):
    """
    Define an external resource to be fetched and staged when building the package. Based on the keywords present in the
    dictionary the appropriate FetchStrategy will be used for the resource. Resources are fetched and staged in their
    own folder inside spack stage area, and then linked into the stage area of the package that needs them.

    List of recognized keywords:

    * 'when' : (optional) represents the condition upon which the resource is needed
    * 'destination' : (optional) path where to link the resource. This path must be relative to the main package stage
    area.
    * 'placement' : (optional) gives the possibility to fine tune how the resource is linked into the main package stage
    area.
    """
    when = kwargs.get('when', pkg.name)
    destination = kwargs.get('destination', "")
    placement = kwargs.get('placement', None)
    # Check if the path is relative
    if os.path.isabs(destination):
        message = "The destination keyword of a resource directive can't be an absolute path.\n"
        message += "\tdestination : '{dest}\n'".format(dest=destination)
        raise RuntimeError(message)
    # Check if the path falls within the main package stage area
    test_path = 'stage_folder_root/'
    normalized_destination = os.path.normpath(join_path(test_path, destination))  # Normalized absolute path
    if test_path not in normalized_destination:
        message = "The destination folder of a resource must fall within the main package stage directory.\n"
        message += "\tdestination : '{dest}'\n".format(dest=destination)
        raise RuntimeError(message)
    when_spec = parse_anonymous_spec(when, pkg.name)
    resources = pkg.resources.setdefault(when_spec, [])
    name = kwargs.get('name')
    fetcher = from_kwargs(**kwargs)
    resources.append(Resource(name, fetcher, destination, placement))
Ejemplo n.º 9
0
    def _execute(pkg):
        when = kwargs.get('when', pkg.name)
        destination = kwargs.get('destination', "")
        placement = kwargs.get('placement', None)

        # Check if the path is relative
        if os.path.isabs(destination):
            message = 'The destination keyword of a resource directive '
            'can\'t be an absolute path.\n'
            message += "\tdestination : '{dest}\n'".format(dest=destination)
            raise RuntimeError(message)

        # Check if the path falls within the main package stage area
        test_path = 'stage_folder_root'
        normalized_destination = os.path.normpath(
            join_path(test_path, destination))  # Normalized absolute path

        if test_path not in normalized_destination:
            message = "The destination folder of a resource must fall "
            "within the main package stage directory.\n"
            message += "\tdestination : '{dest}'\n".format(dest=destination)
            raise RuntimeError(message)

        when_spec = parse_anonymous_spec(when, pkg.name)
        resources = pkg.resources.setdefault(when_spec, [])
        name = kwargs.get('name')
        fetcher = from_kwargs(**kwargs)
        resources.append(Resource(name, fetcher, destination, placement))
Ejemplo n.º 10
0
def argument_factory(argument_spec, left):
    try:
        # If it's not anonymous, allow it
        right = target_factory(argument_spec, False)
    except Exception:
        right = parse_anonymous_spec(argument_spec, left.name)
    return right
Ejemplo n.º 11
0
    def _execute_conflicts(pkg):
        # If when is not specified the conflict always holds
        condition = pkg.name if when is None else when
        when_spec = parse_anonymous_spec(condition, pkg.name)

        # Save in a list the conflicts and the associated custom messages
        when_spec_list = pkg.conflicts.setdefault(conflict_spec, [])
        when_spec_list.append((when_spec, msg))
Ejemplo n.º 12
0
    def _execute(pkg):
        spec_string = kwargs.get('when', pkg.name)
        provider_spec = parse_anonymous_spec(spec_string, pkg.name)

        for string in specs:
            for provided_spec in spack.spec.parse(string):
                if pkg.name == provided_spec.name:
                    raise CircularReferenceError('depends_on', pkg.name)
                if provided_spec not in pkg.provided:
                    pkg.provided[provided_spec] = set()
                pkg.provided[provided_spec].add(provider_spec)
Ejemplo n.º 13
0
    def _execute(pkg):
        spec_string = kwargs.get('when', pkg.name)
        provider_spec = parse_anonymous_spec(spec_string, pkg.name)

        for string in specs:
            for provided_spec in spack.spec.parse(string):
                if pkg.name == provided_spec.name:
                    raise CircularReferenceError('depends_on', pkg.name)
                if provided_spec not in pkg.provided:
                    pkg.provided[provided_spec] = set()
                pkg.provided[provided_spec].add(provider_spec)
Ejemplo n.º 14
0
def provides(pkg, *specs, **kwargs):
    """Allows packages to provide a virtual dependency.  If a package provides
       'mpi', other packages can declare that they depend on "mpi", and spack
       can use the providing package to satisfy the dependency.
    """
    spec_string = kwargs.get("when", pkg.name)
    provider_spec = parse_anonymous_spec(spec_string, pkg.name)

    for string in specs:
        for provided_spec in spack.spec.parse(string):
            if pkg.name == provided_spec.name:
                raise CircularReferenceError("depends_on", pkg.name)
            pkg.provided[provided_spec] = provider_spec
Ejemplo n.º 15
0
def patch(pkg, url_or_filename, level=1, when=None):
    """Packages can declare patches to apply to source.  You can
       optionally provide a when spec to indicate that a particular
       patch should only be applied when the package's spec meets
       certain conditions (e.g. a particular version).
    """
    if when is None:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)
    cur_patches = pkg.patches.setdefault(when_spec, [])
    # if this spec is identical to some other, then append this
    # patch to the existing list.
    cur_patches.append(Patch(pkg, url_or_filename, level))
Ejemplo n.º 16
0
def patch(pkg, url_or_filename, level=1, when=None):
    """Packages can declare patches to apply to source.  You can
       optionally provide a when spec to indicate that a particular
       patch should only be applied when the package's spec meets
       certain conditions (e.g. a particular version).
    """
    if when is None:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)
    cur_patches = pkg.patches.setdefault(when_spec, [])
    # if this spec is identical to some other, then append this
    # patch to the existing list.
    cur_patches.append(Patch(pkg, url_or_filename, level))
Ejemplo n.º 17
0
def provides(pkg, *specs, **kwargs):
    """Allows packages to provide a virtual dependency.  If a package provides
       'mpi', other packages can declare that they depend on "mpi", and spack
       can use the providing package to satisfy the dependency.
    """
    spec_string = kwargs.get('when', pkg.name)
    provider_spec = parse_anonymous_spec(spec_string, pkg.name)

    for string in specs:
        for provided_spec in spack.spec.parse(string):
            if pkg.name == provided_spec.name:
                raise CircularReferenceError('depends_on', pkg.name)
            pkg.provided[provided_spec] = provider_spec
Ejemplo n.º 18
0
    def _execute_provides(pkg):
        spec_string = kwargs.get('when', pkg.name)
        provider_spec = parse_anonymous_spec(spec_string, pkg.name)

        for string in specs:
            for provided_spec in spack.spec.parse(string):
                if pkg.name == provided_spec.name:
                    raise CircularReferenceError(
                        "Package '%s' cannot provide itself.")

                if provided_spec not in pkg.provided:
                    pkg.provided[provided_spec] = set()
                pkg.provided[provided_spec].add(provider_spec)
Ejemplo n.º 19
0
def _depends_on(pkg, spec, when=None):
    if when is None:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError('depends_on', pkg.name)

    conditions = pkg.dependencies.setdefault(dep_spec.name, {})
    if when_spec in conditions:
        conditions[when_spec].constrain(dep_spec, deps=False)
    else:
        conditions[when_spec] = dep_spec
Ejemplo n.º 20
0
def provides(*specs, **kwargs):
    """Allows packages to provide a virtual dependency.  If a package provides
       'mpi', other packages can declare that they depend on "mpi", and spack
       can use the providing package to satisfy the dependency.
    """
    pkg = get_calling_package_name()
    spec_string = kwargs.get('when', pkg)
    provider_spec = parse_anonymous_spec(spec_string, pkg)

    provided = caller_locals().setdefault("provided", {})
    for string in specs:
        for provided_spec in spack.spec.parse(string):
            if pkg == provided_spec.name:
                raise CircularReferenceError('depends_on', pkg)
            provided[provided_spec] = provider_spec
Ejemplo n.º 21
0
def provides(*specs, **kwargs):
    """Allows packages to provide a virtual dependency.  If a package provides
       'mpi', other packages can declare that they depend on "mpi", and spack
       can use the providing package to satisfy the dependency.
    """
    pkg = get_calling_package_name()
    spec_string = kwargs.get('when', pkg)
    provider_spec = parse_anonymous_spec(spec_string, pkg)

    provided = caller_locals().setdefault("provided", {})
    for string in specs:
        for provided_spec in spack.spec.parse(string):
            if pkg == provided_spec.name:
                raise CircularReferenceError('depends_on', pkg)
            provided[provided_spec] = provider_spec
Ejemplo n.º 22
0
def patch(url_or_filename, **kwargs):
    """Packages can declare patches to apply to source.  You can
       optionally provide a when spec to indicate that a particular
       patch should only be applied when the package's spec meets
       certain conditions (e.g. a particular version).
    """
    pkg = get_calling_package_name()
    level = kwargs.get('level', 1)
    when_spec = parse_anonymous_spec(kwargs.get('when', pkg), pkg)

    patches = caller_locals().setdefault('patches', {})
    if when_spec not in patches:
        patches[when_spec] = [Patch(pkg, url_or_filename, level)]
    else:
        # if this spec is identical to some other, then append this
        # patch to the existing list.
        patches[when_spec].append(Patch(pkg, url_or_filename, level))
Ejemplo n.º 23
0
def patch(url_or_filename, **kwargs):
    """Packages can declare patches to apply to source.  You can
       optionally provide a when spec to indicate that a particular
       patch should only be applied when the package's spec meets
       certain conditions (e.g. a particular version).
    """
    pkg = get_calling_package_name()
    level = kwargs.get('level', 1)
    when_spec = parse_anonymous_spec(kwargs.get('when', pkg), pkg)

    patches = caller_locals().setdefault('patches', {})
    if when_spec not in patches:
        patches[when_spec] = [Patch(pkg, url_or_filename, level)]
    else:
        # if this spec is identical to some other, then append this
        # patch to the existing list.
        patches[when_spec].append(Patch(pkg, url_or_filename, level))
Ejemplo n.º 24
0
def _depends_on(pkg, spec, when=None):
    # If when is False do nothing
    if when is False:
        return
    # If when is None or True make sure the condition is always satisfied
    if when is None or when is True:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError('depends_on', pkg.name)

    conditions = pkg.dependencies.setdefault(dep_spec.name, {})
    if when_spec in conditions:
        conditions[when_spec].constrain(dep_spec, deps=False)
    else:
        conditions[when_spec] = dep_spec
Ejemplo n.º 25
0
def _depends_on(pkg, spec, when=None):
    # If when is False do nothing
    if when is False:
        return
    # If when is None or True make sure the condition is always satisfied
    if when is None or when is True:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError("depends_on", pkg.name)

    conditions = pkg.dependencies.setdefault(dep_spec.name, {})
    if when_spec in conditions:
        conditions[when_spec].constrain(dep_spec, deps=False)
    else:
        conditions[when_spec] = dep_spec
Ejemplo n.º 26
0
def _depends_on(pkg, spec, when=None, type=default_deptype, patches=None):
    # If when is False do nothing
    if when is False:
        return
    # If when is None or True make sure the condition is always satisfied
    if when is None or when is True:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError("Package '%s' cannot depend on itself." %
                                     pkg.name)

    type = canonical_deptype(type)
    conditions = pkg.dependencies.setdefault(dep_spec.name, {})

    # call this patches here for clarity -- we want patch to be a list,
    # but the caller doesn't have to make it one.
    if patches and dep_spec.virtual:
        raise DependencyPatchError("Cannot patch a virtual dependency.")

    # ensure patches is a list
    if patches is None:
        patches = []
    elif not isinstance(patches, (list, tuple)):
        patches = [patches]

    # auto-call patch() directive on any strings in patch list
    patches = [patch(p) if isinstance(p, string_types) else p for p in patches]
    assert all(callable(p) for p in patches)

    # this is where we actually add the dependency to this package
    if when_spec not in conditions:
        dependency = Dependency(pkg, dep_spec, type=type)
        conditions[when_spec] = dependency
    else:
        dependency = conditions[when_spec]
        dependency.spec.constrain(dep_spec, deps=False)
        dependency.type |= set(type)

    # apply patches to the dependency
    for execute_patch in patches:
        execute_patch(dependency)
Ejemplo n.º 27
0
def resource(pkg, **kwargs):
    """
    Define an external resource to be fetched and staged when building the
    package. Based on the keywords present in the dictionary the appropriate
    FetchStrategy will be used for the resource. Resources are fetched and
    staged in their own folder inside spack stage area, and then linked into
    the stage area of the package that needs them.

    List of recognized keywords:

    * 'when' : (optional) represents the condition upon which the resource is
    needed
    * 'destination' : (optional) path where to link the resource. This path
    must be relative to the main package stage area.
    * 'placement' : (optional) gives the possibility to fine tune how the
    resource is linked into the main package stage area.
    """
    when = kwargs.get('when', pkg.name)
    destination = kwargs.get('destination', "")
    placement = kwargs.get('placement', None)
    # Check if the path is relative
    if os.path.isabs(destination):
        message = "The destination keyword of a resource directive can't be"
        " an absolute path.\n"
        message += "\tdestination : '{dest}\n'".format(dest=destination)
        raise RuntimeError(message)
    # Check if the path falls within the main package stage area
    test_path = 'stage_folder_root'
    normalized_destination = os.path.normpath(join_path(
        test_path, destination))  # Normalized absolute path
    if test_path not in normalized_destination:
        message = "The destination folder of a resource must fall within the"
        " main package stage directory.\n"
        message += "\tdestination : '{dest}'\n".format(dest=destination)
        raise RuntimeError(message)
    when_spec = parse_anonymous_spec(when, pkg.name)
    resources = pkg.resources.setdefault(when_spec, [])
    name = kwargs.get('name')
    fetcher = from_kwargs(**kwargs)
    resources.append(Resource(name, fetcher, destination, placement))
Ejemplo n.º 28
0
def _depends_on(pkg, spec, when=None, type=None):
    # If when is False do nothing
    if when is False:
        return
    # If when is None or True make sure the condition is always satisfied
    if when is None or when is True:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    if type is None:
        # The default deptype is build and link because the common case is to
        # build against a library which then turns into a runtime dependency
        # due to the linker.
        # XXX(deptype): Add 'run' to this? It's an uncommon dependency type,
        #               but is most backwards-compatible.
        type = ('build', 'link')

    if isinstance(type, str):
        type = spack.spec.special_types.get(type, (type,))

    for deptype in type:
        if deptype not in spack.spec.alldeps:
            raise UnknownDependencyTypeError('depends_on', pkg.name, deptype)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError('depends_on', pkg.name)

    pkg_deptypes = pkg.dependency_types.setdefault(dep_spec.name, set())
    for deptype in type:
        pkg_deptypes.add(deptype)

    conditions = pkg.dependencies.setdefault(dep_spec.name, {})
    if when_spec in conditions:
        conditions[when_spec].constrain(dep_spec, deps=False)
    else:
        conditions[when_spec] = dep_spec
Ejemplo n.º 29
0
def _depends_on(pkg, spec, when=None, type=None):
    # If when is False do nothing
    if when is False:
        return
    # If when is None or True make sure the condition is always satisfied
    if when is None or when is True:
        when = pkg.name
    when_spec = parse_anonymous_spec(when, pkg.name)

    if type is None:
        # The default deptype is build and link because the common case is to
        # build against a library which then turns into a runtime dependency
        # due to the linker.
        # XXX(deptype): Add 'run' to this? It's an uncommon dependency type,
        #               but is most backwards-compatible.
        type = ('build', 'link')

    if isinstance(type, str):
        type = spack.spec.special_types.get(type, (type, ))

    for deptype in type:
        if deptype not in spack.spec.alldeps:
            raise UnknownDependencyTypeError('depends_on', pkg.name, deptype)

    dep_spec = Spec(spec)
    if pkg.name == dep_spec.name:
        raise CircularReferenceError('depends_on', pkg.name)

    pkg_deptypes = pkg.dependency_types.setdefault(dep_spec.name, set())
    for deptype in type:
        pkg_deptypes.add(deptype)

    conditions = pkg.dependencies.setdefault(dep_spec.name, {})
    if when_spec in conditions:
        conditions[when_spec].constrain(dep_spec, deps=False)
    else:
        conditions[when_spec] = dep_spec
Ejemplo n.º 30
0
 def __init__(self, spec):
     pkg = get_calling_module_name()
     if spec is True:
         spec = pkg
     self.spec = (parse_anonymous_spec(spec, pkg)
                  if spec is not False else None)
Ejemplo n.º 31
0
 def __init__(self, spec):
     pkg = get_calling_package_name()
     self.spec = parse_anonymous_spec(spec, pkg)
Ejemplo n.º 32
0
 def __init__(self, spec):
     pkg = get_calling_package_name()
     self.spec = parse_anonymous_spec(spec, pkg)