def test_yaml_directory_layout_build_path(tmpdir, config): """This tests build path method.""" spec = Spec('python') spec.concretize() layout = DirectoryLayout(str(tmpdir)) rel_path = os.path.join(layout.metadata_dir, layout.packages_dir) assert layout.build_packages_path(spec) == os.path.join( spec.prefix, rel_path)
def test_python_namespace_conflict(tmpdir, namespace_extensions, monkeypatch, builtin_and_mock_packages): """Test the view update logic in PythonPackage reports an error when two python extensions with different namespaces have a conflicting __init__ file. """ ext1_prefix, ext2_prefix, py_namespace = namespace_extensions other_namespace = py_namespace + 'other' python_spec = spack.spec.Spec('[email protected]') python_spec._concrete = True ext1_pkg = create_python_ext_pkg('py-extension1', ext1_prefix, python_spec, monkeypatch, py_namespace) ext2_pkg = create_python_ext_pkg('py-extension2', ext2_prefix, python_spec, monkeypatch, other_namespace) view_dir = str(tmpdir.join('view')) layout = DirectoryLayout(view_dir) view = YamlFilesystemView(view_dir, layout) python_pkg = python_spec.package python_pkg.activate(ext1_pkg, view) view.extensions_layout.add_extension(python_spec, ext1_pkg.spec) with pytest.raises(MergeConflictError): python_pkg.activate(ext2_pkg, view)
def test_python_ignore_namespace_init_conflict(tmpdir, namespace_extensions, builtin_and_mock_packages, monkeypatch): """Test the view update logic in PythonPackage ignores conflicting instances of __init__ for packages which are in the same namespace. """ ext1_prefix, ext2_prefix, py_namespace = namespace_extensions python_spec = spack.spec.Spec('[email protected]') python_spec._concrete = True ext1_pkg = create_python_ext_pkg('py-extension1', ext1_prefix, python_spec, monkeypatch, py_namespace) ext2_pkg = create_python_ext_pkg('py-extension2', ext2_prefix, python_spec, monkeypatch, py_namespace) view_dir = str(tmpdir.join('view')) layout = DirectoryLayout(view_dir) view = YamlFilesystemView(view_dir, layout) python_pkg = python_spec.package python_pkg.activate(ext1_pkg, view) # Normally handled by Package.do_activate, but here we activate directly view.extensions_layout.add_extension(python_spec, ext1_pkg.spec) python_pkg.activate(ext2_pkg, view) f1 = 'lib/python2.7/site-packages/examplenamespace/ext1_sample.py' f2 = 'lib/python2.7/site-packages/examplenamespace/ext2_sample.py' init_file = 'lib/python2.7/site-packages/examplenamespace/__init__.py' assert os.path.exists(os.path.join(view_dir, f1)) assert os.path.exists(os.path.join(view_dir, f2)) assert os.path.exists(os.path.join(view_dir, init_file))
def test_remove_extensions_ordered(install_mockery, mock_fetch, tmpdir): view_dir = str(tmpdir.join('view')) layout = DirectoryLayout(view_dir) view = YamlFilesystemView(view_dir, layout) e2 = Spec('extension2').concretized() e2.package.do_install() view.add_specs(e2) e1 = e2['extension1'] view.remove_specs(e1, e2)
def install_dir_non_default_layout(tmpdir): """Hooks a fake install directory with a non-default layout""" scheme = os.path.join( '${name}', '${version}', '${architecture}-${compiler.name}-${compiler.version}-${hash}') real_store, real_layout = spack.store.store, spack.store.layout opt_dir = tmpdir.join('opt') spack.store.store = spack.store.Store(str(opt_dir)) spack.store.layout = DirectoryLayout(str(opt_dir), path_scheme=scheme) try: yield spack.store finally: spack.store.store = real_store spack.store.layout = real_layout
def test_perl_activation_view(tmpdir, perl_and_extension_dirs, monkeypatch, builtin_and_mock_packages): perl_prefix, ext_prefix = perl_and_extension_dirs perl_spec = spack.spec.Spec('[email protected]') perl_spec._concrete = True perl_spec.package.spec.prefix = perl_prefix ext_pkg = create_ext_pkg('perl-extension', ext_prefix, perl_spec, monkeypatch) view_dir = str(tmpdir.join('view')) layout = DirectoryLayout(view_dir) view = YamlFilesystemView(view_dir, layout) perl_pkg = perl_spec.package perl_pkg.activate(ext_pkg, view) assert not os.path.exists(os.path.join(perl_prefix, 'bin/perl-ext-tool')) assert os.path.exists(os.path.join(view_dir, 'bin/perl-ext-tool'))
def test_python_activation_view(tmpdir, python_and_extension_dirs, builtin_and_mock_packages, monkeypatch): python_prefix, ext_prefix = python_and_extension_dirs python_spec = spack.spec.Spec('[email protected]') python_spec._concrete = True python_spec.package.spec.prefix = python_prefix ext_pkg = create_python_ext_pkg('py-extension1', ext_prefix, python_spec, monkeypatch) view_dir = str(tmpdir.join('view')) layout = DirectoryLayout(view_dir) view = YamlFilesystemView(view_dir, layout) python_pkg = python_spec.package python_pkg.activate(ext_pkg, view) assert not os.path.exists(os.path.join(python_prefix, 'bin/py-ext-tool')) assert os.path.exists(os.path.join(view_dir, 'bin/py-ext-tool'))
def test_update_sbang(tmpdir, test_mirror): """Test the creation and installation of buildcaches with default rpaths into the non-default directory layout scheme, triggering an update of the sbang. """ scheme = os.path.join( '${name}', '${version}', '${architecture}-${compiler.name}-${compiler.version}-${hash}') spec_str = 'old-sbang' # Concretize a package with some old-fashioned sbang lines. old_spec = Spec(spec_str).concretized() old_spec_hash_str = '/{0}'.format(old_spec.dag_hash()) # Need a fake mirror with *function* scope. mirror_dir = test_mirror mirror_url = 'file://{0}'.format(mirror_dir) # Assume all commands will concretize old_spec the same way. install_cmd('--no-cache', old_spec.name) # Create a buildcache with the installed spec. buildcache_cmd('create', '-u', '-a', '-d', mirror_dir, old_spec_hash_str) # Need to force an update of the buildcache index buildcache_cmd('update-index', '-d', mirror_url) # Uninstall the original package. uninstall_cmd('-y', old_spec_hash_str) # Switch the store to the new install tree locations newtree_dir = tmpdir.join('newtree') s = spack.store.Store(str(newtree_dir)) s.layout = DirectoryLayout(str(newtree_dir), path_scheme=scheme) with spack.store.use_store(s): new_spec = Spec('old-sbang') new_spec.concretize() assert new_spec.dag_hash() == old_spec.dag_hash() # Install package from buildcache buildcache_cmd('install', '-a', '-u', '-f', new_spec.name) # Continue blowing away caches bindist.clear_spec_cache() spack.stage.purge() # test that the sbang was updated by the move sbang_style_1_expected = '''{0} #!/usr/bin/env python {1} '''.format(sbang.sbang_shebang_line(), new_spec.prefix.bin) sbang_style_2_expected = '''{0} #!/usr/bin/env python {1} '''.format(sbang.sbang_shebang_line(), new_spec.prefix.bin) installed_script_style_1_path = new_spec.prefix.bin.join( 'sbang-style-1.sh') assert sbang_style_1_expected == \ open(str(installed_script_style_1_path)).read() installed_script_style_2_path = new_spec.prefix.bin.join( 'sbang-style-2.sh') assert sbang_style_2_expected == \ open(str(installed_script_style_2_path)).read() uninstall_cmd('-y', '/%s' % new_spec.dag_hash())
def test_yaml_directory_layout_parameters(tmpdir, config): """This tests the various parameters that can be used to configure the install location """ spec = Spec('python') spec.concretize() # Ensure default layout matches expected spec format layout_default = DirectoryLayout(str(tmpdir)) path_default = layout_default.relative_path_for_spec(spec) assert (path_default == spec.format("{architecture}/" "{compiler.name}-{compiler.version}/" "{name}-{version}-{hash}")) # Test hash_length parameter works correctly layout_10 = DirectoryLayout(str(tmpdir), hash_length=10) path_10 = layout_10.relative_path_for_spec(spec) layout_7 = DirectoryLayout(str(tmpdir), hash_length=7) path_7 = layout_7.relative_path_for_spec(spec) assert (len(path_default) - len(path_10) == 22) assert (len(path_default) - len(path_7) == 25) # Test path_scheme arch, compiler, package7 = path_7.split('/') projections_package7 = {'all': "{name}-{version}-{hash:7}"} layout_package7 = DirectoryLayout(str(tmpdir), projections=projections_package7) path_package7 = layout_package7.relative_path_for_spec(spec) assert (package7 == path_package7) # Test separation of architecture or namespace spec2 = Spec('libelf').concretized() arch_scheme = "{architecture.platform}/{architecture.target}/{architecture.os}/{name}/{version}/{hash:7}" # NOQA: ignore=E501 ns_scheme = "${ARCHITECTURE}/${NAMESPACE}/${PACKAGE}-${VERSION}-${HASH:7}" # NOQA: ignore=E501 arch_ns_scheme_projections = {'all': arch_scheme, 'python': ns_scheme} layout_arch_ns = DirectoryLayout(str(tmpdir), projections=arch_ns_scheme_projections) arch_path_spec2 = layout_arch_ns.relative_path_for_spec(spec2) assert (arch_path_spec2 == spec2.format(arch_scheme)) ns_path_spec = layout_arch_ns.relative_path_for_spec(spec) assert (ns_path_spec == spec.format(ns_scheme)) # Ensure conflicting parameters caught with pytest.raises(InvalidDirectoryLayoutParametersError): DirectoryLayout(str(tmpdir), hash_length=20, projections=projections_package7)