示例#1
0
def install_pkg(virtualenv, pkg, options=DEFAULT_OPTIONS, version=None,
                allow_source_package=False):
    """
    Install package in the given virtualenv

    Parameters
    ----------
    virtualenv : `str`
        Virtualenv base path
    pkg : `str`
        Package name
    version : `str`
        Package version, defaults to latest available
    allow_source_package : `bool`
        If the package is setup as a source package in the current runtime
        context, set it up from there otherwise use easy_install.
    """
    requirement = pkg
    if allow_source_package:
        dists = [d for d in working_set if d.project_name == pkg]
        if dists and not dists[0].location.endswith('.egg'):
            setup_pkg(virtualenv, dists[0].location, options)
            return

    if version:
        requirement = '%s==%s' % (pkg, version)
    get_log().info("Installing requirement %s" % requirement)
    if getattr(options, 'no_action', False):
        return

    # Using easy_install as an argument here to get around #! path limits
    run([os.path.join(virtualenv, 'bin', 'python'),
         os.path.join(virtualenv, 'bin', 'easy_install'), requirement])
示例#2
0
def setup_pkg(virtualenv, pkg_dir, options, test=True, indent_txt='',
              deps=True):
    """
    Sets up a package in the given virtualenv

    Parameters
    ----------
    virtualenv : `str`
        virtulenv base dir
    pkg_dir : `str`
        package checkout dir
    options : `optparse.Options`
        command-line options
    test : `bool`
        True/False will install test packages
    deps : `bool`
        True/False will install dependencies
    """
    from path import path as p
    get_log().info("%s Setting up package in %s" % (indent_txt, pkg_dir))
    if getattr(options, 'no_action', False):
        return
    python = p(virtualenv) / 'bin' / 'python'
    cmd = [python, 'setup.py']
    if options.verbose:
        cmd.append('-v')
    cmd.append('develop')
    if not test:
        cmd.append('--no-test')
    if getattr(options, 'prefer_final', False):
        cmd.append('--prefer-final')
    if not deps:
        cmd.append('--no-deps')
    with chdir(pkg_dir):
        run(cmd, capture_stdout=not options.verbose)
示例#3
0
def checkout_pkg(dest_dir, pypi, pkg, options, branch='trunk', indent_txt='', vcs='svn'):
    """
    Checks out a package by name to a specified dest dir

    Parameters
    ----------
    dest_dir : `str`
        Destination dir
    pypi : `pkglib.pypi.PyPi`
        PyPi API
    pkg : `str`
        Package Name
    branch : `str`
        VCS branch name
    options : `optparse.Options`
        Cmdline options
    """
    if os.path.isfile(os.path.join(dest_dir, 'setup.py')):
        get_log().info("%s %s already checked out" % (indent_txt, pkg))
        return

    uri = pypi.get_vcs_uri(pkg)

    if vcs == 'svn':
        uri = '%s/%s' % (uri, branch)
        cmd = ['svn' 'co', uri, dest_dir]
    else:
        raise ValueError("Unsupported vcs: {0}".format(vcs))

    get_log().info("%s Checking out %s from %s" % (indent_txt, pkg, uri))
    if getattr(options, 'no_action', False):
        return
    run(cmd, capture_stdout=not options.verbose)
示例#4
0
def checkout_pkg(dest_dir, pypi, pkg, options, branch='trunk', indent_txt=''):
    """
    Checks out a package by name to a specified dest dir

    Parameters
    ----------
    dest_dir : `str`
        Destination dir
    pypi : `pkglib.pypi.PyPi`
        PyPi API
    pkg : `str`
        Package Name
    branch : `str`
        VCS branch name
    options : `optparse.Options`
        Cmdline options
    """
    uri = pypi.get_vcs_uri(pkg)
    svn_dir = '%s/%s' % (uri, branch)
    if os.path.isfile(os.path.join(dest_dir, 'setup.py')):
        get_log().info("%s %s already checked out" % (indent_txt, pkg))
    else:
        get_log().info("%s Checking out %s from %s" % (indent_txt, pkg, svn_dir))
        if getattr(options, 'no_action', False):
            return
        run((CONFIG.vcs, 'co', svn_dir, dest_dir),
            capture_stdout=not options.verbose)
示例#5
0
文件: manage.py 项目: drkjam/pkglib
def create_virtualenv(dest, virtualenv_cmd=None):
    """
    Create Python Virtualenv for deployment.
    Unsets ``PYTHONPATH`` to ensure it is a clean build (I'm looking at you, Eclipse..)

    Parameters
    ----------
    dest : `str`
        Destination directory path

    """
    if virtualenv_cmd == None:
        virtualenv_cmd = CONFIG.virtualenv_executable
    print "Creating virtualenv at %s" % dest
    base = os.path.dirname(dest)
    if not os.path.isdir(base):
        os.makedirs(base)
    env = dict(os.environ)
    if 'PYTHONPATH' in env:
        del(env['PYTHONPATH'])
    run([virtualenv_cmd, dest, '--distribute'], env=env)
示例#6
0
# -*- coding: utf-8 -*-
from cmdline import run
from dotenv import load_dotenv

if __name__ == '__main__':
    load_dotenv(verbose=True)
    run()