コード例 #1
0
ファイル: versions.py プロジェクト: wrwilliams/spack
def test_new_versions_only(monkeypatch):
    """Test a package for which new versions should be available."""
    from spack.pkg.builtin.mock.brillig import Brillig  # type: ignore[import]

    def mock_fetch_remote_versions(*args, **kwargs):
        mock_remote_versions = {
            # new version, we expect this to be in output:
            Version('99.99.99'): {},
            # some packages use '3.2' equivalently to '3.2.0'
            # thus '3.2.1' is considered to be a new version
            # and expected in the output also
            Version('3.2.1'):
            {},  # new version, we expect this to be in output
            Version('3.2'): {},
            Version('1.0.0'): {},
        }
        return mock_remote_versions

    mock_versions = {
        # already checksummed versions:
        Version('3.2'): {},
        Version('1.0.0'): {},
    }
    monkeypatch.setattr(Brillig, 'versions', mock_versions)
    monkeypatch.setattr(Brillig, 'fetch_remote_versions',
                        mock_fetch_remote_versions)
    v = versions('--new', 'brillig')
    assert (v.strip(' \n\t') == "99.99.99\n  3.2.1")
コード例 #2
0
def test_list_highest():
    vl = VersionList(['master', '1.2.3', 'develop', '3.4.5', 'foobar'])
    assert vl.highest() == Version('develop')
    assert vl.lowest() == Version('foobar')
    assert vl.highest_numeric() == Version('3.4.5')

    vl2 = VersionList(['master', 'develop'])
    assert vl2.highest_numeric() is None
    assert vl2.preferred() == Version('develop')
    assert vl2.lowest() == Version('master')
コード例 #3
0
    def test_preferred_versions(self):
        """Test preferred package versions are applied correctly
        """
        update_packages('mpileaks', 'version', ['2.3'])
        spec = concretize('mpileaks')
        assert spec.version == Version('2.3')

        update_packages('mpileaks', 'version', ['2.2'])
        spec = concretize('mpileaks')
        assert spec.version == Version('2.2')
コード例 #4
0
 def mock_fetch_remote_versions(*args, **kwargs):
     mock_remote_versions = {
         # new version, we expect this to be in output:
         Version('99.99.99'): {},
         # some packages use '3.2' equivalently to '3.2.0'
         # thus '3.2.1' is considered to be a new version
         # and expected in the output also
         Version('3.2.1'): {},  # new version, we expect this to be in output
         Version('3.2'): {},
         Version('1.0.0'): {},
     }
     return mock_remote_versions
コード例 #5
0
    def test_preferred(self):
        """"Test packages with some version marked as preferred=True"""
        spec = Spec('python')
        spec.concretize()
        assert spec.version == Version('2.7.11')

        # now add packages.yaml with versions other than preferred
        # ensure that once config is in place, non-preferred version is used
        update_packages('python', 'version', ['3.5.0'])
        spec = Spec('python')
        spec.concretize()
        assert spec.version == Version('3.5.0')
コード例 #6
0
ファイル: package.py プロジェクト: BlueBrain/spack
class ClangTools(Package):
    """Copy binaries like clang-format out of an LLVM installation and into a
    clean directory for which a module can safely be generated."""

    has_code = False
    homepage = LLVM.homepage

    # Add a clang-format version for every LLVM version
    for llvm_ver in LLVM.versions:
        clang_tools_ver = Version(str(llvm_ver) + "p2")
        version(clang_tools_ver)
        depends_on(
            "llvm@{}".format(llvm_ver), when="@{}".format(clang_tools_ver), type="build"
        )

    def install(self, spec, prefix):
        for utility in (
            ("bin", "clang-format"),
            ("bin", "clang-tidy"),
            ("bin", "git-clang-format"),
            ("share", "clang", "clang-format-diff.py"),
        ):
            source_dir = spec["llvm"].prefix
            destination_dir = spec.prefix
            for component in utility[:-1]:
                source_dir = source_dir.join(component)
                destination_dir = destination_dir.join(component)
            mkdirp(destination_dir)
            install(source_dir.join(utility[-1]), destination_dir.join(utility[-1]))
コード例 #7
0
ファイル: conftest.py プロジェクト: jbaksta/spack
    def __init__(self,
                 name,
                 dependencies,
                 dependency_types,
                 conditions=None,
                 versions=None):
        self.name = name
        self.spec = None
        self.dependencies = ordereddict_backport.OrderedDict()

        assert len(dependencies) == len(dependency_types)
        for dep, dtype in zip(dependencies, dependency_types):
            d = Dependency(self, Spec(dep.name), type=dtype)
            if not conditions or dep.name not in conditions:
                self.dependencies[dep.name] = {Spec(name): d}
            else:
                dep_conditions = conditions[dep.name]
                dep_conditions = dict(
                    (Spec(x), Dependency(self, Spec(y), type=dtype))
                    for x, y in dep_conditions.items())
                self.dependencies[dep.name] = dep_conditions

        if versions:
            self.versions = versions
        else:
            versions = list(Version(x) for x in [1, 2, 3])
            self.versions = dict((x, {'preferred': False}) for x in versions)

        self.variants = {}
        self.provided = {}
        self.conflicts = {}
        self.patches = {}
コード例 #8
0
def get_mac_sys_type():
    """Return a Mac OS SYS_TYPE or None if this isn't a mac."""
    mac_ver = py_platform.mac_ver()[0]
    if not mac_ver:
        return None

    return "macosx_%s_%s" % (Version(mac_ver).up_to(2), py_platform.machine())
コード例 #9
0
ファイル: mac_os.py プロジェクト: wangvsa/spack
    def __init__(self):
        """Autodetects the mac version from a dictionary.

        If the mac version is too old or too new for Spack to recognize,
        will use a generic "macos" version string until Spack is updated.
        """
        mac_releases = {
            '10.0':  'cheetah',
            '10.1':  'puma',
            '10.2':  'jaguar',
            '10.3':  'panther',
            '10.4':  'tiger',
            '10.5':  'leopard',
            '10.6':  'snowleopard',
            '10.7':  'lion',
            '10.8':  'mountainlion',
            '10.9':  'mavericks',
            '10.10': 'yosemite',
            '10.11': 'elcapitan',
            '10.12': 'sierra',
            '10.13': 'highsierra',
            '10.14': 'mojave',
            '10.15': 'catalina',
            '10.16': 'bigsur',
            '11': 'bigsur',
            '12': 'monterey',
        }

        # Big Sur versions go 11.0, 11.0.1, 11.1 (vs. prior versions that
        # only used the minor component)
        part = 1 if macos_version() >= Version('11') else 2

        mac_ver = str(macos_version().up_to(part))
        name = mac_releases.get(mac_ver, "macos")
        super(MacOs, self).__init__(name, mac_ver)
コード例 #10
0
ファイル: versions.py プロジェクト: zygyz/spack
 def check_repr_and_str(vrs):
     a = Version(vrs)
     assert repr(a) == "Version('" + vrs + "')"
     b = eval(repr(a))
     assert a == b
     assert str(a) == vrs
     assert str(a) == str(b)
コード例 #11
0
ファイル: versions.py プロジェクト: zygyz/spack
def test_up_to():
    v = Version('1.23-4_5b')

    assert v.up_to(1).string == '1'
    assert v.up_to(2).string == '1.23'
    assert v.up_to(3).string == '1.23-4'
    assert v.up_to(4).string == '1.23-4_5'
    assert v.up_to(5).string == '1.23-4_5b'

    assert v.up_to(-1).string == '1.23-4_5'
    assert v.up_to(-2).string == '1.23-4'
    assert v.up_to(-3).string == '1.23'
    assert v.up_to(-4).string == '1'

    assert v.up_to(2).dotted.string == '1.23'
    assert v.up_to(2).dashed.string == '1-23'
    assert v.up_to(2).underscored.string == '1_23'
    assert v.up_to(2).joined.string == '123'

    assert v.dotted.up_to(2).string == '1.23' == v.up_to(2).dotted.string
    assert v.dashed.up_to(2).string == '1-23' == v.up_to(2).dashed.string
    assert v.underscored.up_to(2).string == '1_23'
    assert v.up_to(2).underscored.string == '1_23'

    assert v.up_to(2).up_to(1).string == '1'
コード例 #12
0
    def _execute(pkg):
        # TODO: checksum vs md5 distinction is confusing -- fix this.
        # special case checksum for backward compatibility
        if checksum:
            kwargs['md5'] = checksum

        # Store kwargs for the package to later with a fetch_strategy.
        pkg.versions[Version(ver)] = kwargs
コード例 #13
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')])
コード例 #14
0
ファイル: url_parse.py プロジェクト: zygyz/spack
def test_url_parse_name_and_version(name, version, url):
    # Make sure correct name and version are extracted.
    parsed_name, parsed_version = parse_name_and_version(url)
    assert parsed_name == name
    assert parsed_version == Version(version)

    # Make sure Spack formulates the right URL when we try to
    # build one with a specific version.
    assert url == substitute_version(url, version)
コード例 #15
0
ファイル: mac_os.py プロジェクト: BlueBrain/spack
def macos_version():
    """Get the current macOS version as a version object.

    This has three mechanisms for determining the macOS version, which is used
    for spack identification (the ``os`` in the spec's ``arch``) and indirectly
    for setting the value of ``MACOSX_DEPLOYMENT_TARGET``, which affects the
    ``minos`` value of the ``LC_BUILD_VERSION`` macho header. Mixing ``minos``
    values can lead to lots of linker warnings, and using a consistent version
    (pinned to the major OS version) allows distribution across clients that
    might be slightly behind.

    The version determination is made with three mechanisms in decreasing
    priority:

    1. The ``MACOSX_DEPLOYMENT_TARGET`` variable overrides the actual operating
       system version, just like the value can be used to build for older macOS
       targets on newer systems. Spack currently will truncate this value when
       building packages, but at least the major version will be the same.

    2. The system ``sw_vers`` command reports the actual operating system
       version.

    3. The Python ``platform.mac_ver`` function is a fallback if the operating
       system identification fails, because some Python versions and/or
       installations report the OS
       on which Python was *built* rather than the one on which it is running.
    """
    env_ver = os.environ.get('MACOSX_DEPLOYMENT_TARGET', None)
    if env_ver:
        return Version(env_ver)

    try:
        output = Executable('sw_vers')(output=str, fail_on_error=False)
    except Exception:
        # FileNotFoundError, or spack.util.executable.ProcessError
        pass
    else:
        match = re.search(r'ProductVersion:\s*([0-9.]+)', output)
        if match:
            return Version(match.group(1))

    # Fall back to python-reported version, which can be inaccurate around
    # macOS 11 (e.g. showing 10.16 for macOS 12)
    return Version(py_platform.mac_ver()[0])
コード例 #16
0
def version(ver, checksum, **kwargs):
    """Adds a version and associated metadata to the package."""
    pkg = caller_locals()

    versions = pkg.setdefault('versions', {})
    patches = pkg.setdefault('patches', {})

    ver = Version(ver)
    url = kwargs.get('url', None)

    versions[ver] = VersionDescriptor(checksum, url)
コード例 #17
0
    def test_develop(self):
        """Test concretization with develop-like versions"""
        spec = Spec('develop-test')
        spec.concretize()
        assert spec.version == Version('0.2.15')
        spec = Spec('develop-test2')
        spec.concretize()
        assert spec.version == Version('0.2.15')

        # now add packages.yaml with develop-like versions
        # ensure that once config is in place, develop-like version is used
        update_packages('develop-test', 'version', ['develop'])
        spec = Spec('develop-test')
        spec.concretize()
        assert spec.version == Version('develop')

        update_packages('develop-test2', 'version', ['0.2.15.develop'])
        spec = Spec('develop-test2')
        spec.concretize()
        assert spec.version == Version('0.2.15.develop')
コード例 #18
0
    def _execute_version(pkg):
        if checksum is not None:
            if hasattr(pkg, 'has_code') and not pkg.has_code:
                raise VersionChecksumError(
                    "{0}: Checksums not allowed in no-code packages"
                    "(see '{1}' version).".format(pkg.name, ver))

            kwargs['checksum'] = checksum

        # Store kwargs for the package to later with a fetch_strategy.
        pkg.versions[Version(ver)] = kwargs
コード例 #19
0
ファイル: mac_os.py プロジェクト: BlueBrain/spack
def macos_cltools_version():
    """Find the last installed version of the CommandLineTools.

    The CLT version might only affect the build if it's selected as the macOS
    SDK path.
    """
    pkgutil = Executable('pkgutil')
    output = pkgutil('--pkg-info=com.apple.pkg.cltools_executables',
                     output=str, fail_on_error=False)
    match = re.search(r'version:\s*([0-9.]+)', output)
    if match:
        return Version(match.group(1))

    # No CLTools installed by package manager: try Xcode
    output = pkgutil('--pkg-info=com.apple.pkg.Xcode',
                     output=str, fail_on_error=False)
    match = re.search(r'version:\s*([0-9.]+)', output)
    if match:
        return Version(match.group(1))

    return None
コード例 #20
0
ファイル: versions.py プロジェクト: zygyz/spack
def test_get_item():
    a = Version('0.1_2-3')
    assert isinstance(a[1], int)
    # Test slicing
    b = a[0:2]
    assert isinstance(b, Version)
    assert b == Version('0.1')
    assert repr(b) == "Version('0.1')"
    assert str(b) == '0.1'
    b = a[0:3]
    assert isinstance(b, Version)
    assert b == Version('0.1_2')
    assert repr(b) == "Version('0.1_2')"
    assert str(b) == '0.1_2'
    b = a[1:]
    assert isinstance(b, Version)
    assert b == Version('1_2-3')
    assert repr(b) == "Version('1_2-3')"
    assert str(b) == '1_2-3'
    # Raise TypeError on tuples
    with pytest.raises(TypeError):
        b.__getitem__(1, 2)
コード例 #21
0
def version(pkg, ver, checksum=None, **kwargs):
    """Adds a version and metadata describing how to fetch it.
       Metadata is just stored as a dict in the package's versions
       dictionary.  Package must turn it into a valid fetch strategy
       later.
    """
    # TODO: checksum vs md5 distinction is confusing -- fix this.
    # special case checksum for backward compatibility
    if checksum:
        kwargs['md5'] = checksum

    # Store kwargs for the package to later with a fetch_strategy.
    pkg.versions[Version(ver)] = kwargs
コード例 #22
0
ファイル: mac_os.py プロジェクト: BlueBrain/spack
def macos_sdk_version():
    """Return the version of the active macOS SDK.

    The SDK version usually corresponds to the installed Xcode version and can
    affect how some packages (especially those that use the GUI) can fail. This
    information should somehow be embedded into the future "compilers are
    dependencies" feature.

    The macOS deployment target cannot be greater than the SDK version, but
    usually it can be at least a few versions less.
    """
    xcrun = Executable('xcrun')
    return Version(xcrun('--show-sdk-version', output=str).rstrip())
コード例 #23
0
ファイル: versions.py プロジェクト: zygyz/spack
def test_formatted_strings():
    versions = ('1.2.3b', '1_2_3b', '1-2-3b', '1.2-3b', '1.2_3b', '1-2.3b',
                '1-2_3b', '1_2.3b', '1_2-3b')
    for item in versions:
        v = Version(item)
        assert v.dotted.string == '1.2.3b'
        assert v.dashed.string == '1-2-3b'
        assert v.underscored.string == '1_2_3b'
        assert v.joined.string == '123b'

        assert v.dotted.dashed.string == '1-2-3b'
        assert v.dotted.underscored.string == '1_2_3b'
        assert v.dotted.dotted.string == '1.2.3b'
        assert v.dotted.joined.string == '123b'
コード例 #24
0
ファイル: url.py プロジェクト: wangvsa/spack
def parse_version(path):
    """Try to extract a version string from a filename or URL.

    Args:
        path (str): The filename or URL for the package

    Returns:
        spack.version.Version: The version of the package

    Raises:
        UndetectableVersionError: If the URL does not match any regexes
    """
    version, start, length, i, regex = parse_version_offset(path)
    return Version(version)
コード例 #25
0
    def test_compiler_add(self, mock_compiler_dir):
        # Compilers available by default.
        old_compilers = set(spack.compilers.all_compiler_specs())

        args = spack.util.pattern.Bunch(all=None,
                                        compiler_spec=None,
                                        add_paths=[mock_compiler_dir],
                                        scope=None)
        spack.cmd.compiler.compiler_find(args)

        # Ensure new compiler is in there
        new_compilers = set(spack.compilers.all_compiler_specs())
        new_compiler = new_compilers - old_compilers
        assert any(c.version == Version(test_version) for c in new_compiler)
コード例 #26
0
ファイル: linux_distro.py プロジェクト: wrwilliams/spack
def kernel_version():
    """Return the kernel version as a Version object.
       Note that the kernel version is distinct from OS and/or
       distribution versions. For instance:
       >>> external.distro.id()
       'centos'
       >>> external.distro.version()
       '7'
       >>> platform.release()
       '5.10.84+'
    """
    # Strip '+' characters just in case we're running a
    # version built from git/etc
    clean_version = re.sub(r'\+', r'', py_platform.release())
    return Version(clean_version)
コード例 #27
0
def version(ver, checksum=None, **kwargs):
    """Adds a version and metadata describing how to fetch it.
       Metadata is just stored as a dict in the package's versions
       dictionary.  Package must turn it into a valid fetch strategy
       later.
    """
    pkg = caller_locals()
    versions = pkg.setdefault('versions', {})

    # special case checksum for backward compatibility
    if checksum:
        kwargs['md5'] = checksum

    # Store the kwargs for the package to use later when constructing
    # a fetch strategy.
    versions[Version(ver)] = kwargs
コード例 #28
0
def for_package_version(pkg, version):
    """Determine a fetch strategy based on the arguments supplied to
       version() in the package description."""

    # No-code packages have a custom fetch strategy to work around issues
    # with resource staging.
    if not pkg.has_code:
        return BundleFetchStrategy()

    check_pkg_attributes(pkg)

    if not isinstance(version, Version):
        version = Version(version)

    # If it's not a known version, try to extrapolate one by URL
    if version not in pkg.versions:
        return _extrapolate(pkg, version)

    # Set package args first so version args can override them
    args = {'fetch_options': pkg.fetch_options}
    # Grab a dict of args out of the package version dict
    args.update(pkg.versions[version])

    # If the version specifies a `url_attr` directly, use that.
    for fetcher in all_strategies:
        if fetcher.url_attr in args:
            _check_version_attributes(fetcher, pkg, version)
            return fetcher(**args)

    # if a version's optional attributes imply a particular fetch
    # strategy, and we have the `url_attr`, then use that strategy.
    for fetcher in all_strategies:
        if hasattr(pkg, fetcher.url_attr) or fetcher.url_attr == 'url':
            optionals = fetcher.optional_attrs
            if optionals and any(a in args for a in optionals):
                _check_version_attributes(fetcher, pkg, version)
                return _from_merged_attrs(fetcher, pkg, version)

    # if the optional attributes tell us nothing, then use any `url_attr`
    # on the package.  This prefers URL vs. VCS, b/c URLFetchStrategy is
    # defined first in this file.
    for fetcher in all_strategies:
        if hasattr(pkg, fetcher.url_attr):
            _check_version_attributes(fetcher, pkg, version)
            return _from_merged_attrs(fetcher, pkg, version)

    raise InvalidArgsError(pkg, version, **args)
コード例 #29
0
    def test_compiler_add(self, mock_compiler_dir, monkeypatch):
        # This test randomly stall on Travis when spawning processes
        # in Python 2.6 unit tests
        if sys.version_info < (3, 0, 0):
            monkeypatch.setattr(llnl.util.multiproc, 'parmap', map)

        # Compilers available by default.
        old_compilers = set(spack.compilers.all_compiler_specs())

        args = spack.util.pattern.Bunch(all=None,
                                        compiler_spec=None,
                                        add_paths=[mock_compiler_dir],
                                        scope=None)
        spack.cmd.compiler.compiler_find(args)

        # Ensure new compiler is in there
        new_compilers = set(spack.compilers.all_compiler_specs())
        new_compiler = new_compilers - old_compilers
        assert any(c.version == Version(test_version) for c in new_compiler)
コード例 #30
0
    def test_compiler_add(self):
        # compilers available by default.
        old_compilers = set(spack.compilers.all_compilers())

        # add our new compiler and find again.
        compiler_dir = make_mock_compiler()

        try:
            args = MockArgs(add_paths=[compiler_dir])
            spack.cmd.compiler.compiler_find(args)

            # ensure new compiler is in there
            new_compilers = set(spack.compilers.all_compilers())
            new_compiler = new_compilers - old_compilers
            self.assertTrue(new_compiler)
            self.assertTrue(
                new_compiler.pop().version == Version(test_version))

        finally:
            shutil.rmtree(compiler_dir, ignore_errors=True)