示例#1
0
def name_parsed_correctly(pkg, name):
    """Determine if the name of a package was correctly parsed.

    Args:
        pkg (spack.package.PackageBase): The Spack package
        name (str): The name that was extracted from the URL

    Returns:
        bool: True if the name was correctly parsed, else False
    """
    pkg_name = pkg.name

    name = simplify_name(name)

    # After determining a name, `spack create` determines a build system.
    # Some build systems prepend a special string to the front of the name.
    # Since this can't be guessed from the URL, it would be unfair to say
    # that these names are incorrectly parsed, so we remove them.
    if pkg_name.startswith('r-'):
        pkg_name = pkg_name[2:]
    elif pkg_name.startswith('py-'):
        pkg_name = pkg_name[3:]
    elif pkg_name.startswith('perl-'):
        pkg_name = pkg_name[5:]
    elif pkg_name.startswith('octave-'):
        pkg_name = pkg_name[7:]

    return name == pkg_name
示例#2
0
文件: url.py 项目: justintoo/spack
def name_parsed_correctly(pkg, name):
    """Determine if the name of a package was correctly parsed.

    Args:
        pkg (spack.package.PackageBase): The Spack package
        name (str): The name that was extracted from the URL

    Returns:
        bool: True if the name was correctly parsed, else False
    """
    pkg_name = pkg.name

    name = simplify_name(name)

    # After determining a name, `spack create` determines a build system.
    # Some build systems prepend a special string to the front of the name.
    # Since this can't be guessed from the URL, it would be unfair to say
    # that these names are incorrectly parsed, so we remove them.
    if pkg_name.startswith('r-'):
        pkg_name = pkg_name[2:]
    elif pkg_name.startswith('py-'):
        pkg_name = pkg_name[3:]
    elif pkg_name.startswith('octave-'):
        pkg_name = pkg_name[7:]

    return name == pkg_name
示例#3
0
文件: url.py 项目: wangvsa/spack
def name_parsed_correctly(pkg, name):
    """Determine if the name of a package was correctly parsed.

    Args:
        pkg (spack.package.PackageBase): The Spack package
        name (str): The name that was extracted from the URL

    Returns:
        bool: True if the name was correctly parsed, else False
    """
    pkg_name = remove_prefix(pkg.name)

    name = simplify_name(name)

    return name == pkg_name
示例#4
0
文件: create.py 项目: eic/spack
def get_name(args):
    """Get the name of the package based on the supplied arguments.

    If a name was provided, always use that. Otherwise, if a URL was
    provided, extract the name from that. Otherwise, use a default.

    Args:
        args (param argparse.Namespace): The arguments given to
            ``spack create``

    Returns:
        str: The name of the package
    """

    # Default package name
    name = 'example'

    if args.name is not None:
        # Use a user-supplied name if one is present
        name = args.name
        if len(args.name.strip()) > 0:
            tty.msg("Using specified package name: '{0}'".format(name))
        else:
            tty.die("A package name must be provided when using the option.")
    elif args.url is not None:
        # Try to guess the package name based on the URL
        try:
            name = parse_name(args.url)
            if name != args.url:
                desc = 'URL'
            else:
                desc = 'package name'
            tty.msg("This looks like a {0} for {1}".format(desc, name))
        except UndetectableNameError:
            tty.die("Couldn't guess a name for this package.",
                    "  Please report this bug. In the meantime, try running:",
                    "  `spack create --name <name> <url>`")

    name = simplify_name(name)

    if not valid_fully_qualified_module_name(name):
        tty.die("Package name can only contain a-z, 0-9, and '-'")

    return name
示例#5
0
文件: create.py 项目: LLNL/spack
def get_name(args):
    """Get the name of the package based on the supplied arguments.

    If a name was provided, always use that. Otherwise, if a URL was
    provided, extract the name from that. Otherwise, use a default.

    Args:
        args (param argparse.Namespace): The arguments given to
            ``spack create``

    Returns:
        str: The name of the package
    """

    # Default package name
    name = 'example'

    if args.name:
        # Use a user-supplied name if one is present
        name = args.name
        tty.msg("Using specified package name: '{0}'".format(name))
    elif args.url:
        # Try to guess the package name based on the URL
        try:
            name = parse_name(args.url)
            tty.msg("This looks like a URL for {0}".format(name))
        except UndetectableNameError:
            tty.die("Couldn't guess a name for this package.",
                    "  Please report this bug. In the meantime, try running:",
                    "  `spack create --name <name> <url>`")

    name = simplify_name(name)

    if not valid_fully_qualified_module_name(name):
        tty.die("Package name can only contain a-z, 0-9, and '-'")

    return name
示例#6
0
def configure_pipeline(parser, args):
    # Parse all of our inputs before trying to modify any recipes.
    modifications = {}
    packages_to_ignore = set(args.ignore_packages)
    mod_pattern = re.compile("^([^=]+)_(BRANCH|COMMIT|TAG)=(.*)$",
                             re.IGNORECASE)
    for mod_str in args.modifications:
        match = mod_pattern.match(mod_str)
        if not match:
            raise Exception("Could not parse: {}".format(mod_str))
        package_name = match.group(1)
        ref_type = match.group(2).lower()
        val = match.group(3)
        # Handle --ignore-packges arguments
        if package_name in packages_to_ignore:
            tty.info("{}: ignoring {}".format(package_name, mod_str))
            continue
        # Try and transform the input name, which is probably all upper case
        # and may contain underscores, into a Spack-style name that is all
        # lower case and contains hyphens.
        spack_package_name = simplify_name(package_name)
        # Check if this package exists
        try:
            spack.repo.get(spack_package_name)
        except spack.repo.UnknownPackageError:
            raise Exception(
                "Could not find a Spack package corresponding to {}, tried {}".
                format(package_name, spack_package_name))
        if spack_package_name in modifications:
            raise Exception(
                "Parsed multiple modifications for Spack package {} from: {}".
                format(spack_package_name, " ".join(args.modifications)))
        modifications[spack_package_name] = {
            "bash_name": package_name,
            "ref_type": ref_type,
            "ref": val,
        }

    # Translate any branches or tags into commit hashes and then use those
    # consistently. This guarantees different jobs in a pipeline all get the
    # same commit, and means we can handle provenance information (what did
    # @develop mean) in one place.
    git = which("git")
    if not git:
        raise Exception("Git is required")
    for spack_package_name, info in modifications.items():
        if info["ref_type"] == "commit":
            info["commit"] = info["ref"]
        else:
            if info["ref_type"] == "branch":
                remote_ref = "refs/heads/" + info["ref"]
            else:
                assert info["ref_type"] == "tag"
                remote_ref = "refs/tags/" + info["ref"]
            spack_package = spack.repo.get(spack_package_name)
            remote_refs = git("ls-remote",
                              spack_package.git,
                              remote_ref,
                              output=str).splitlines()
            assert len(remote_refs) < 2
            if len(remote_refs) == 0:
                raise Exception(
                    "Could not find {} {} on remote {} (tried {})".format(
                        info["ref_type"], info["ref"], spack_package.git,
                        remote_ref))
            commit, ref_check = remote_refs[0].split()
            assert remote_ref == ref_check
            tty.info("{}: resolved {} {} to {}".format(spack_package_name,
                                                       info["ref_type"],
                                                       info["ref"], commit))
            info["commit"] = commit

    if args.write_commit_file is not None:
        with open(args.write_commit_file, "w") as ofile:
            for spack_package_name, info in modifications.items():
                ofile.write("{}_COMMIT={}\n".format(info["bash_name"],
                                                    info["commit"]))

    # Now modify the Spack recipes of the given packages
    for spack_package_name, info in modifications.items():
        spack_package = spack.repo.get(spack_package_name)
        spack_recipe = os.path.join(spack_package.package_dir,
                                    spack.repo.package_file_name)
        # Using filter_file seems neater than calling sed, but it is a little
        # more limited. First, remove any existing branch/commit/tag from the
        # develop version.
        tty.info(
            "{}@develop: remove branch/commit/tag".format(spack_package_name))
        filter_file(
            "version\\s*\\(\\s*(['\"]{1})develop\\1(.*?)" +
            ",\\s*(branch|commit|tag)=(['\"]{1})(.*?)\\4(.*?)\\)",
            "version('develop'\\2\\6) # old: \\3=\\4\\5\\4",
            spack_recipe,
        )
        # Second, insert the new commit="sha" part
        tty.info('{}@develop: use commit="{}"'.format(spack_package_name,
                                                      info["commit"]))
        filter_file(
            "version\\('develop'",
            "version('develop', commit='{}'".format(info["commit"]),
            spack_recipe,
        )
        # Third, make sure that the develop version, and only the develop
        # version, is flagged as the preferred version. Start by getting a list
        # of versions that are already explicitly flagged as preferred.
        already_preferred = {
            str(v)
            for v, v_info in spack_package.versions.items()
            if v_info.get("preferred", False)
        }
        # Make sure the develop version has an explicit preferred=True.
        if "develop" not in already_preferred:
            tty.info(
                "{}@develop: add preferred=True".format(spack_package_name))
            filter_file("version\\('develop'",
                        "version('develop', preferred=True", spack_recipe)
        # Make sure no other versions have an explicit preferred=True.
        for other_version in already_preferred - {"develop"}:
            tty.info("{}@{}: remove preferred=True".format(
                spack_package_name, other_version))
            escaped_version = re.escape(other_version)
            filter_file(
                "version\\s*\\(\\s*(['\"]{1})" + escaped_version +
                "\\1(.*?),\\s*preferred=True(.*?)\\)",
                "version('{version}'\\2\\3)".format(version=other_version),
                spack_recipe,
            )