Example #1
0
 def add_file(self, file_path, contents):
     fullpath = os.path.abspath(os.path.join(self.path, file_path))
     dir = os.path.dirname(fullpath)
     mktree(dir)
     open(fullpath, 'w').write(contents)
     self.env.run('git', 'add', file_path, cwd=self.path)
     self.env.run('git', 'commit', '--amend', '-m', 'initial checkin', cwd=self.path)
Example #2
0
def create_projects(env, **proj_metadata):
    """
    Create git repositories and an index for projects within env.

    env should be an Environment

    proj_metadata should be a dict mapping project names to
    DistributionMetadata objects representing their metadata.  

    Returns (index,projdirs) where:

    * index is the path to the locally-generated index

    * projdirs is a dict mapping project names to the paths to the
      locally-generated git repositories.
    """
    from distutils2.metadata import DistributionMetadata

    index = env.scratch_path/'index'
    mktree(index)
    repo = env.scratch_path/'repo'
    
    open(index/'index.html', 'w').write(
        '\n'.join(
            ['<html><head><title>Simple Index</title></head><body>']
            + [ '<a href=%r/>%s</a><br/>' % (p,p) for p in proj_metadata ]
            + ['</body></html>'])
        )
    
    projects = {}

    for p,metadata in proj_metadata.items():

        mktree(index/p)
        
        root = repo/p
        projects[p] = Project(p, root, env)
        mktree(root)

        env.run('git', 'init', cwd = root)

        dot_ryppl = root/'.ryppl'

        if isinstance(metadata, basestring):
            m = DistributionMetadata()
            m.read_file(StringIO(metadata))
            metadata = m
        elif isinstance(metadata, dict):
            m = DistributionMetadata()
            for k,v in metadata.items():
                m[k] = v
            metadata = m

        metadata['Name'] = p
        if metadata['Version'] == 'UNKNOWN':
            metadata['Version'] = '0.9'
        if metadata['Requires-Python'] == 'UNKNOWN':
            metadata['Requires-Python'] = '>2.0'
            

        mktree(dot_ryppl)
        metadata.write(dot_ryppl/'METADATA')

        # mktree(root/p)
        # open(root/p/'__init__.py', 'w').write('print "importing module %s"' % p)

        env.run('git', 'add', '*', Path('.ryppl')/'*', cwd = root)
        env.run('git', 'commit', '-m', 'initial checkin', cwd = root)

        repo_url = pathname2url(root)

        open(index/p/'index.html', 'w').write(
            '<html><head><title>Links for %(p)s</title></head>'
            '<body>'
            '<h1>Links for %(p)s</h1>'
            '<a href="git+file://%(repo_url)s#egg=%(p)s">Git Repository</a><br/>'
            '</body></html>'
            % locals()
            )
        
    return 'file://'+pathname2url(index),projects
Example #3
0
def main(argv):
    global use_distribute

    # Grab this script's options
    global use_distribute
    use_distribute = ('--distribute' in argv)
    prepare_env = [x for x in argv if x.startswith('--prepare-env=')]
    argv = [x for x in argv if x != '--distribute' and not x.startswith('--prepare-env=')]

    here = Path(sys.path[0])
    script_name = Path(__file__).name

    if not (here/script_name).exists:
        here = Path(__file__).abspath.folder
        assert (here/script_name).exists, "Can't locate directory of this script"

    # Make sure all external tools are set up to be used.
    print >> sys.stderr, 'Checking for installed prerequisites in PATH:',
    for tool in ('git',):
        print >> sys.stderr, tool,'...',
        assert_in_path(tool)
    print >> sys.stderr, 'ok'

    ryppl_root = here.folder

    #
    # Delete everything that could lead to stale test results
    #
    clean( ryppl_root )
    
    save_dir = os.getcwd()

    if prepare_env:
        venv_dir = prepare_env[-1][len('--prepare_env='):]
        mktree(venv_dir)
    else:
        venv_dir = mkdtemp('-ryppl_self_test')

    try:
        os.chdir(venv_dir)

        #
        # Prepare a clean, writable workspace
        #
        print >> sys.stderr, 'Preparing test environment ...'
        venv, lib, include, bin = create_virtualenv(venv_dir, distribute=use_distribute)

        abs_bin = Path(bin).abspath

        # Make sure it's first in PATH
        os.environ['PATH'] = str(
            Path.pathsep.join(( abs_bin, os.environ['PATH'] ))
            )

        #
        # Install python module testing prerequisites
        #
        pip_exe = abs_bin/'pip'+EXE
        download_cache = '--download-cache=' \
            + Path(gettempdir())/'ryppl-test-download-cache'
        def pip_install(*pkg):
            print >> sys.stderr, '   pip install',' '.join(pkg), '...',
            run(pip_exe, 'install', '-q', download_cache, *pkg)
            print >> sys.stderr, 'ok'
        pip_install('virtualenv')
        pip_install('--no-index', '-f', 'http://pypi.python.org/packages/source/n/nose/', 'nose')
        pip_install('scripttest>=1.0.4')
        print >> sys.stderr, 'ok'
        nosetests = abs_bin/'nosetests'+EXE
        test_cmd = [nosetests, '-w', ryppl_root/'test'] + argv
        if prepare_env:
            print 'Testing command:'
            print ' '.join(test_cmd)
        else:
            run( *test_cmd )

    finally:
        os.chdir(save_dir)
        # Keep VCSes from seeing spurious new/changed files
        clean(ryppl_root)
Example #4
0
def create_projects(env, **projects):
    from distutils2.metadata import DistributionMetadata

    index = env.scratch_path / "index"
    mktree(index)
    repo = env.scratch_path / "repo"

    open(index / "index.html", "w").write(
        "\n".join(
            ["<html><head><title>Simple Index</title></head><body>"]
            + ["<a href=%r/>%s</a><br/>" % (p, p) for p in projects]
            + ["</body></html>"]
        )
    )

    paths = {}

    for p, metadata in projects.items():

        mktree(index / p)

        root = repo / p
        paths[p] = root
        mktree(root)

        env.run("git", "init", cwd=root)

        dot_ryppl = root / ".ryppl"

        if isinstance(metadata, basestring):
            m = DistributionMetadata()
            m.read_file(StringIO(metadata))
            metadata = m
        elif isinstance(metadata, dict):
            m = DistributionMetadata()
            for k, v in metadata.items():
                m[k] = v
            metadata = m

        metadata["Name"] = p
        if metadata["Version"] == "UNKNOWN":
            metadata["Version"] = "0.9"
        if metadata["Requires-Python"] == "UNKNOWN":
            metadata["Requires-Python"] = ">2.0"

        mktree(dot_ryppl)
        metadata.write(dot_ryppl / "METADATA")

        # mktree(root/p)
        # open(root/p/'__init__.py', 'w').write('print "importing module %s"' % p)

        env.run("git", "add", "*", Path(".ryppl") / "*", cwd=root)
        env.run("git", "commit", "-m", "initial checkin", cwd=root)

        repo_url = pathname2url(root)

        open(index / p / "index.html", "w").write(
            "<html><head><title>Links for %(p)s</title></head>"
            "<body>"
            "<h1>Links for %(p)s</h1>"
            '<a href="git+file://%(repo_url)s#egg=%(p)s">Git Repository</a><br/>'
            "</body></html>" % locals()
        )

    return index, paths