예제 #1
0
def mock_archive():
    """Creates a very simple archive directory with a configure script and a
    makefile that installs to a prefix. Tars it up into an archive.
    """
    tar = spack.util.executable.which('tar', required=True)
    stage = spack.stage.Stage('mock-archive-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-archive-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)
    # Create the configure script
    configure_path = str(tmpdir.join(repo_name, 'configure'))
    with open(configure_path, 'w') as f:
        f.write(
            "#!/bin/sh\n"
            "prefix=$(echo $1 | sed 's/--prefix=//')\n"
            "cat > Makefile <<EOF\n"
            "all:\n"
            "\techo Building...\n\n"
            "install:\n"
            "\tmkdir -p $prefix\n"
            "\ttouch $prefix/dummy_file\n"
            "EOF\n"
        )
    os.chmod(configure_path, 0755)
    # Archive it
    current = tmpdir.chdir()
    archive_name = '{0}.tar.gz'.format(repo_name)
    tar('-czf', archive_name, repo_name)
    current.chdir()
    Archive = collections.namedtuple('Archive', ['url', 'path'])
    url = 'file://' + str(tmpdir.join(archive_name))
    # Return the url
    yield Archive(url=url, path=str(repodir))
    stage.destroy()
예제 #2
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
예제 #3
0
파일: conftest.py 프로젝트: zepx/spack
def mock_archive():
    """Creates a very simple archive directory with a configure script and a
    makefile that installs to a prefix. Tars it up into an archive.
    """
    tar = spack.util.executable.which('tar', required=True)
    stage = spack.stage.Stage('mock-archive-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-archive-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)
    # Create the configure script
    configure_path = str(tmpdir.join(repo_name, 'configure'))
    with open(configure_path, 'w') as f:
        f.write("#!/bin/sh\n"
                "prefix=$(echo $1 | sed 's/--prefix=//')\n"
                "cat > Makefile <<EOF\n"
                "all:\n"
                "\techo Building...\n\n"
                "install:\n"
                "\tmkdir -p $prefix\n"
                "\ttouch $prefix/dummy_file\n"
                "EOF\n")
    os.chmod(configure_path, 0755)
    # Archive it
    current = tmpdir.chdir()
    archive_name = '{0}.tar.gz'.format(repo_name)
    tar('-czf', archive_name, repo_name)
    current.chdir()
    Archive = collections.namedtuple('Archive', ['url', 'path'])
    url = 'file://' + str(tmpdir.join(archive_name))
    # Return the url
    yield Archive(url=url, path=str(repodir))
    stage.destroy()
def mock_hg_repository():
    """Creates a very simple hg repository with two commits."""
    hg = spack.util.executable.which('hg', required=True)
    stage = spack.stage.Stage('mock-hg-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-hg-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)

    get_rev = lambda: hg('id', '-i', output=str).strip()

    # Initialize the repository
    current = repodir.chdir()
    url = 'file://' + str(repodir)
    hg('init')
    # Commit file r0
    r0_file = 'r0_file'
    repodir.ensure(r0_file)
    hg('add', r0_file)
    hg('commit', '-m', 'revision 0', '-u', 'test')
    r0 = get_rev()
    # Commit file r1
    r1_file = 'r1_file'
    repodir.ensure(r1_file)
    hg('add', r1_file)
    hg('commit', '-m' 'revision 1', '-u', 'test')
    r1 = get_rev()
    current.chdir()

    Bunch = spack.util.pattern.Bunch

    checks = {
        'default':
        Bunch(revision=r1, file=r1_file, args={'hg': str(repodir)}),
        'rev0':
        Bunch(revision=r0,
              file=r0_file,
              args={
                  'hg': str(repodir),
                  'revision': r0
              })
    }
    t = Bunch(checks=checks, url=url, hash=get_rev, path=str(repodir))
    yield t
    stage.destroy()
예제 #5
0
def mock_hg_repository():
    """Creates a very simple hg repository with two commits."""
    hg = spack.util.executable.which('hg', required=True)
    stage = spack.stage.Stage('mock-hg-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-hg-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)

    get_rev = lambda: hg('id', '-i', output=str).strip()

    # Initialize the repository
    current = repodir.chdir()
    url = 'file://' + str(repodir)
    hg('init')
    # Commit file r0
    r0_file = 'r0_file'
    repodir.ensure(r0_file)
    hg('add', r0_file)
    hg('commit', '-m', 'revision 0', '-u', 'test')
    r0 = get_rev()
    # Commit file r1
    r1_file = 'r1_file'
    repodir.ensure(r1_file)
    hg('add', r1_file)
    hg('commit', '-m' 'revision 1', '-u', 'test')
    r1 = get_rev()
    current.chdir()

    Bunch = spack.util.pattern.Bunch

    checks = {
        'default': Bunch(
            revision=r1, file=r1_file, args={'hg': str(repodir)}
        ),
        'rev0': Bunch(
            revision=r0, file=r0_file, args={
                'hg': str(repodir), 'revision': r0
            }
        )
    }
    t = Bunch(checks=checks, url=url, hash=get_rev, path=str(repodir))
    yield t
    stage.destroy()
예제 #6
0
def mock_git_repository():
    """Creates a very simple git repository with two branches and
    two commits.
    """
    git = spack.util.executable.which('git', required=True)
    stage = spack.stage.Stage('mock-git-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-git-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)

    # Initialize the repository
    current = repodir.chdir()
    git('init')
    url = 'file://' + str(repodir)

    # r0 is just the first commit
    r0_file = 'r0_file'
    repodir.ensure(r0_file)
    git('add', r0_file)
    git('commit', '-m', 'mock-git-repo r0')

    branch = 'test-branch'
    branch_file = 'branch_file'
    git('branch', branch)

    tag_branch = 'tag-branch'
    tag_file = 'tag_file'
    git('branch', tag_branch)

    # Check out first branch
    git('checkout', branch)
    repodir.ensure(branch_file)
    git('add', branch_file)
    git('commit', '-m' 'r1 test branch')

    # Check out a second branch and tag it
    git('checkout', tag_branch)
    repodir.ensure(tag_file)
    git('add', tag_file)
    git('commit', '-m' 'tag test branch')

    tag = 'test-tag'
    git('tag', tag)

    git('checkout', 'master')

    # R1 test is the same as test for branch
    rev_hash = lambda x: git('rev-parse', x, output=str).strip()
    r1 = rev_hash(branch)
    r1_file = branch_file
    current.chdir()

    Bunch = spack.util.pattern.Bunch

    checks = {
        'master': Bunch(
            revision='master', file=r0_file, args={'git': str(repodir)}
        ),
        'branch': Bunch(
            revision=branch, file=branch_file, args={
                'git': str(repodir), 'branch': branch
            }
        ),
        'tag': Bunch(
            revision=tag, file=tag_file, args={'git': str(repodir), 'tag': tag}
        ),
        'commit': Bunch(
            revision=r1, file=r1_file, args={'git': str(repodir), 'commit': r1}
        )
    }

    t = Bunch(checks=checks, url=url, hash=rev_hash, path=str(repodir))
    yield t
    stage.destroy()
def mock_git_repository():
    """Creates a very simple git repository with two branches and
    two commits.
    """
    git = spack.util.executable.which('git', required=True)
    stage = spack.stage.Stage('mock-git-stage')
    tmpdir = py.path.local(stage.path)
    repo_name = 'mock-git-repo'
    tmpdir.ensure(repo_name, dir=True)
    repodir = tmpdir.join(repo_name)

    # Initialize the repository
    current = repodir.chdir()
    git('init')
    url = 'file://' + str(repodir)

    # r0 is just the first commit
    r0_file = 'r0_file'
    repodir.ensure(r0_file)
    git('add', r0_file)
    git('commit', '-m', 'mock-git-repo r0')

    branch = 'test-branch'
    branch_file = 'branch_file'
    git('branch', branch)

    tag_branch = 'tag-branch'
    tag_file = 'tag_file'
    git('branch', tag_branch)

    # Check out first branch
    git('checkout', branch)
    repodir.ensure(branch_file)
    git('add', branch_file)
    git('commit', '-m' 'r1 test branch')

    # Check out a second branch and tag it
    git('checkout', tag_branch)
    repodir.ensure(tag_file)
    git('add', tag_file)
    git('commit', '-m' 'tag test branch')

    tag = 'test-tag'
    git('tag', tag)

    git('checkout', 'master')

    # R1 test is the same as test for branch
    rev_hash = lambda x: git('rev-parse', x, output=str).strip()
    r1 = rev_hash(branch)
    r1_file = branch_file
    current.chdir()

    Bunch = spack.util.pattern.Bunch

    checks = {
        'master':
        Bunch(revision='master', file=r0_file, args={'git': str(repodir)}),
        'branch':
        Bunch(revision=branch,
              file=branch_file,
              args={
                  'git': str(repodir),
                  'branch': branch
              }),
        'tag':
        Bunch(revision=tag,
              file=tag_file,
              args={
                  'git': str(repodir),
                  'tag': tag
              }),
        'commit':
        Bunch(revision=r1,
              file=r1_file,
              args={
                  'git': str(repodir),
                  'commit': r1
              })
    }

    t = Bunch(checks=checks, url=url, hash=rev_hash, path=str(repodir))
    yield t
    stage.destroy()