예제 #1
0
파일: list.py 프로젝트: wdmapp/spack
def version_json(pkg_names, out):
    """Print all packages with their latest versions."""
    pkgs = [spack.repo.get(name) for name in pkg_names]

    out.write('[\n')

    # output name and latest version for each package
    pkg_latest = ",\n".join([
        '  {{"name": "{0}",\n'
        '   "latest_version": "{1}",\n'
        '   "versions": {2},\n'
        '   "homepage": "{3}",\n'
        '   "file": "{4}",\n'
        '   "maintainers": {5},\n'
        '   "dependencies": {6}'
        '}}'.format(
            pkg.name,
            VersionList(pkg.versions).preferred(),
            json.dumps([str(v) for v in reversed(sorted(pkg.versions))]),
            pkg.homepage, github_url(pkg), json.dumps(pkg.maintainers),
            json.dumps(get_dependencies(pkg))) for pkg in pkgs
    ])
    out.write(pkg_latest)
    # important: no trailing comma in JSON arrays
    out.write('\n]\n')
예제 #2
0
파일: mirror.py 프로젝트: matz-e/spack
def get_matching_versions(specs, **kwargs):
    """Get a spec for EACH known version matching any spec in the list."""
    matching = []
    for spec in specs:
        pkg = spec.package

        # Skip any package that has no known versions.
        if not pkg.versions:
            tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
            continue

        num_versions = kwargs.get('num_versions', 0)
        matching_spec = []
        for i, v in enumerate(reversed(sorted(pkg.versions))):
            # Generate no more than num_versions versions for each spec.
            if num_versions and i >= num_versions:
                break

            # Generate only versions that satisfy the spec.
            if v.satisfies(spec.versions):
                s = Spec(pkg.name)
                s.versions = VersionList([v])
                s.variants = spec.variants.copy()
                # This is needed to avoid hanging references during the
                # concretization phase
                s.variants.spec = s
                matching_spec.append(s)

        if not matching_spec:
            tty.warn("No known version matches spec: %s" % spec)
        matching.extend(matching_spec)

    return matching
예제 #3
0
파일: versions.py 프로젝트: key4hep/spack
def test_version_list_with_range_included_in_concrete_version_interpreted_as_range():
    # Note: this test only tests whether we can construct a version list of a range
    # and a version, where the range is contained in the version when it is interpreted
    # as a range. That is: Version('3.1') interpreted as VersionRange('3.1', '3.1').
    # Cleary it *shouldn't* be interpreted that way, but that is how Spack currently
    # behaves, and this test only ensures that creating a VersionList of this type
    # does not throw like reported in the linked Github issue.
    VersionList([Version('3.1'), VersionRange('3.1.1', '3.1.2')])
예제 #4
0
파일: versions.py 프로젝트: sidpbury/spack
def versions(parser, args):
    pkg = spack.repo.get(args.package)

    safe_versions = pkg.versions

    if args.safe_only:
        tty.warn('"--safe-only" is deprecated. Use "--safe" instead.')
        args.safe = args.safe_only

    if not (args.remote or args.new):
        if sys.stdout.isatty():
            tty.msg('Safe versions (already checksummed):')

        if not safe_versions:
            if sys.stdout.isatty():
                tty.warn('Found no versions for {0}'.format(pkg.name))
                tty.debug('Manually add versions to the package.')
        else:
            colify(sorted(safe_versions, reverse=True), indent=2)

        if args.safe:
            return

    fetched_versions = pkg.fetch_remote_versions(args.concurrency)

    if args.new:
        if sys.stdout.isatty():
            tty.msg('New remote versions (not yet checksummed):')
        highest_safe_version = VersionList(safe_versions).highest_numeric()
        remote_versions = set([
            ver(v) for v in set(fetched_versions) if v > highest_safe_version
        ])
    else:
        if sys.stdout.isatty():
            tty.msg('Remote versions (not yet checksummed):')
        remote_versions = set(fetched_versions).difference(safe_versions)

    if not remote_versions:
        if sys.stdout.isatty():
            if not fetched_versions:
                tty.warn('Found no versions for {0}'.format(pkg.name))
                tty.debug('Check the list_url and list_depth attributes of '
                          'the package to help Spack find versions.')
            else:
                tty.warn('Found no unchecksummed versions for {0}'.format(
                    pkg.name))
    else:
        colify(sorted(remote_versions, reverse=True), indent=2)
예제 #5
0
def get_matching_versions(specs, num_versions=1):
    """Get a spec for EACH known version matching any spec in the list.
    For concrete specs, this retrieves the concrete version and, if more
    than one version per spec is requested, retrieves the latest versions
    of the package.
    """
    matching = []
    for spec in specs:
        pkg = spec.package

        # Skip any package that has no known versions.
        if not pkg.versions:
            tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
            continue

        pkg_versions = num_versions

        version_order = list(reversed(sorted(pkg.versions)))
        matching_spec = []
        if spec.concrete:
            matching_spec.append(spec)
            pkg_versions -= 1
            if spec.version in version_order:
                version_order.remove(spec.version)

        for v in version_order:
            # Generate no more than num_versions versions for each spec.
            if pkg_versions < 1:
                break

            # Generate only versions that satisfy the spec.
            if spec.concrete or v.satisfies(spec.versions):
                s = spack.spec.Spec(pkg.name)
                s.versions = VersionList([v])
                s.variants = spec.variants.copy()
                # This is needed to avoid hanging references during the
                # concretization phase
                s.variants.spec = s
                matching_spec.append(s)
                pkg_versions -= 1

        if not matching_spec:
            tty.warn("No known version matches spec: %s" % spec)
        matching.extend(matching_spec)

    return matching
예제 #6
0
def get_all_versions(specs):
    """Given a set of initial specs, return a new set of specs that includes
    each version of each package in the original set.

    Note that if any spec in the original set specifies properties other than
    version, this information will be omitted in the new set; for example; the
    new set of specs will not include variant settings.
    """

    version_specs = []
    for spec in specs:
        pkg = spec.package

        # Skip any package that has no known versions.
        if not pkg.versions:
            tty.msg("No safe (checksummed) versions for package %s" % pkg.name)
            continue

        for version in pkg.versions:
            version_spec = spack.spec.Spec(pkg.name)
            version_spec.versions = VersionList([version])
            version_specs.append(version_spec)

    return version_specs
예제 #7
0
    def concretize_version(self, spec):
        """If the spec is already concrete, return.  Otherwise take
           the preferred version from spackconfig, and default to the package's
           version if there are no available versions.

           TODO: In many cases we probably want to look for installed
                 versions of each package and use an installed version
                 if we can link to it.  The policy implemented here will
                 tend to rebuild a lot of stuff becasue it will prefer
                 a compiler in the spec to any compiler already-
                 installed things were built with.  There is likely
                 some better policy that finds some middle ground
                 between these two extremes.
        """
        # return if already concrete.
        if spec.versions.concrete:
            return False

        # List of versions we could consider, in sorted order
        pkg_versions = spec.package_class.versions
        usable = [v for v in pkg_versions
                  if any(v.satisfies(sv) for sv in spec.versions)]

        yaml_prefs = PackagePrefs(spec.name, 'version')

        # The keys below show the order of precedence of factors used
        # to select a version when concretizing.  The item with
        # the "largest" key will be selected.
        #
        # NOTE: When COMPARING VERSIONS, the '@develop' version is always
        #       larger than other versions.  BUT when CONCRETIZING,
        #       the largest NON-develop version is selected by default.
        keyfn = lambda v: (
            # ------- Special direction from the user
            # Respect order listed in packages.yaml
            -yaml_prefs(v),

            # The preferred=True flag (packages or packages.yaml or both?)
            pkg_versions.get(Version(v)).get('preferred', False),

            # ------- Regular case: use latest non-develop version by default.
            # Avoid @develop version, which would otherwise be the "largest"
            # in straight version comparisons
            not v.isdevelop(),

            # Compare the version itself
            # This includes the logic:
            #    a) develop > everything (disabled by "not v.isdevelop() above)
            #    b) numeric > non-numeric
            #    c) Numeric or string comparison
            v)
        usable.sort(key=keyfn, reverse=True)

        if usable:
            spec.versions = ver([usable[0]])
        else:
            # We don't know of any SAFE versions that match the given
            # spec.  Grab the spec's versions and grab the highest
            # *non-open* part of the range of versions it specifies.
            # Someone else can raise an error if this happens,
            # e.g. when we go to fetch it and don't know how.  But it
            # *might* work.
            if not spec.versions or spec.versions == VersionList([':']):
                raise NoValidVersionError(spec)
            else:
                last = spec.versions[-1]
                if isinstance(last, VersionRange):
                    if last.end:
                        spec.versions = ver([last.end])
                    else:
                        spec.versions = ver([last.start])
                else:
                    spec.versions = ver([last])

        return True   # Things changed
예제 #8
0
파일: versions.py 프로젝트: key4hep/spack
def test_version_list_with_range_and_concrete_version_is_not_concrete():
    v = VersionList([Version('3.1'), VersionRange('3.1.1', '3.1.2')])
    assert v.concrete