예제 #1
0
파일: stage.py 프로젝트: key4hep/spack
    def test_diystage_path_valid(self, tmpdir):
        """Ensure DIYStage for a valid path behaves as expected."""
        path = str(tmpdir)
        stage = DIYStage(path)
        assert stage.path == path
        assert stage.source_path == path

        # Order doesn't really matter for DIYStage since they are
        # basically NOOPs; however, call each since they are part
        # of the normal stage usage and to ensure full test coverage.
        stage.create()  # Only sets the flag value
        assert stage.created

        stage.cache_local()  # Only outputs a message
        stage.fetch()  # Only outputs a message
        stage.check()  # Only outputs a message
        stage.expand_archive()  # Only outputs a message

        assert stage.expanded  # The path/source_path does exist

        with pytest.raises(spack.stage.RestageError):
            stage.restage()

        stage.destroy()  # A no-op
        assert stage.path == path  # Ensure can still access attributes
        assert os.path.exists(stage.source_path)  # Ensure path still exists
예제 #2
0
def _mirror(args):
    mirror_dir = spack.util.path.canonicalize_path(
        os.path.join(args.root_dir, LOCAL_MIRROR_DIR))

    # TODO: Here we are adding gnuconfig manually, but this can be fixed
    # TODO: as soon as we have an option to add to a mirror all the possible
    # TODO: dependencies of a spec
    root_specs = spack.bootstrap.all_root_specs(
        development=args.dev) + ['gnuconfig']
    for spec_str in root_specs:
        msg = 'Adding "{0}" and dependencies to the mirror at {1}'
        llnl.util.tty.msg(msg.format(spec_str, mirror_dir))
        # Suppress tty from the call below for terser messages
        llnl.util.tty.set_msg_enabled(False)
        spec = spack.spec.Spec(spec_str).concretized()
        for node in spec.traverse():
            spack.mirror.create(mirror_dir, [node])
        llnl.util.tty.set_msg_enabled(True)

    if args.binary_packages:
        msg = 'Adding binary packages from "{0}" to the mirror at {1}'
        llnl.util.tty.msg(msg.format(BINARY_TARBALL, mirror_dir))
        llnl.util.tty.set_msg_enabled(False)
        stage = spack.stage.Stage(BINARY_TARBALL, path=tempfile.mkdtemp())
        stage.create()
        stage.fetch()
        stage.expand_archive()
        build_cache_dir = os.path.join(stage.source_path, 'build_cache')
        shutil.move(build_cache_dir, mirror_dir)
        llnl.util.tty.set_msg_enabled(True)

    def write_metadata(subdir, metadata):
        metadata_rel_dir = os.path.join('metadata', subdir)
        metadata_yaml = os.path.join(args.root_dir, metadata_rel_dir,
                                     'metadata.yaml')
        llnl.util.filesystem.mkdirp(os.path.dirname(metadata_yaml))
        with open(metadata_yaml, mode='w') as f:
            spack.util.spack_yaml.dump(metadata, stream=f)
        return os.path.dirname(metadata_yaml), metadata_rel_dir

    instructions = (
        '\nTo register the mirror on the platform where it\'s supposed '
        'to be used, move "{0}" to its final location and run the '
        'following command(s):\n\n').format(args.root_dir)
    cmd = '  % spack bootstrap add --trust {0} <final-path>/{1}\n'
    _, rel_directory = write_metadata(subdir='sources',
                                      metadata=SOURCE_METADATA)
    instructions += cmd.format('local-sources', rel_directory)
    if args.binary_packages:
        abs_directory, rel_directory = write_metadata(subdir='binaries',
                                                      metadata=BINARY_METADATA)
        shutil.copy(spack.util.path.canonicalize_path(CLINGO_JSON),
                    abs_directory)
        shutil.copy(spack.util.path.canonicalize_path(GNUPG_JSON),
                    abs_directory)
        instructions += cmd.format('local-binaries', rel_directory)
    print(instructions)
예제 #3
0
파일: stage.py 프로젝트: FNALssi/spack
def test_stage_create_replace_path(tmp_build_stage_dir):
    """Ensure stage creation replaces a non-directory path."""
    _, test_stage_path = tmp_build_stage_dir
    test_stage_path.ensure(dir=True)

    nondir = test_stage_path.join('afile')
    nondir.ensure(dir=False)
    path = str(nondir)

    stage = Stage(path, name='')
    stage.create()  # Should ensure the path is converted to a dir

    assert os.path.isdir(stage.path)
예제 #4
0
파일: stage.py 프로젝트: key4hep/spack
def test_stage_create_replace_path(tmp_build_stage_dir):
    """Ensure stage creation replaces a non-directory path."""
    _, test_stage_path = tmp_build_stage_dir
    mkdirp(test_stage_path)

    nondir = os.path.join(test_stage_path, 'afile')
    touch(nondir)
    path = str(nondir)

    stage = Stage(path, name='')
    stage.create()

    # Ensure the stage path is "converted" to a directory
    assert os.path.isdir(stage.path)
예제 #5
0
파일: stage.py 프로젝트: key4hep/spack
    def test_diystage_preserve_file(self, tmpdir):
        """Ensure DIYStage preserves an existing file."""
        # Write a file to the temporary directory
        fn = tmpdir.join(_readme_fn)
        fn.write(_readme_contents)

        # Instantiate the DIYStage and ensure the above file is unchanged.
        path = str(tmpdir)
        stage = DIYStage(path)
        assert os.path.isdir(path)
        assert os.path.isfile(str(fn))

        stage.create()  # Only sets the flag value

        readmefn = str(fn)
        assert os.path.isfile(readmefn)
        with open(readmefn) as _file:
            _file.read() == _readme_contents