Exemple #1
0
def deploy():
    """
    Create and upload python package to PYPI.
    """
    c = helpers.Meta('meta.json')
    version = c.get('version')
    name = c.get('name')
    run("python setup.py sdist")
    package_path = "dist/{}-{}.tar.gz".format(name, version)
    run("twine upload {}".format(package_path))
Exemple #2
0
def setup(dev=False, test=False, prod=False, all=False):
    """
    Setup a project environment.
    """
    cwd = os.getcwd()
    m = helpers.Meta('meta.json')
    project_name = m.get('name')
    project_env_path = "{}".format(os.path.join(VIRTUALENV_HOME, project_name))
    if dev:
        env = 'dev'
        project_env_path = "{}".format(
            os.path.join(VIRTUALENV_HOME, project_name))
    elif test:
        env = 'test'
        project_env_path = "{}-test".format(
            os.path.join(VIRTUALENV_HOME, project_name))
    elif prod:
        env = 'prod'
        project_env_path = "{}-prod".format(
            os.path.join(VIRTUALENV_HOME, project_name))
    else:
        print "TODO: setup dev, test and prod environments."
    project_path = os.path.join(os.path.dirname(cwd), project_name)
    run('virtualenv {}'.format(project_env_path))
    # register dependency resolve task
    run("echo '\npy resolve' >> {}/bin/activate".format(project_env_path))
    run("echo '\nEASY_ENV=\"{0}\"\nexport EASY_ENV' >> {1}/bin/activate".
        format(env, project_env_path))
    # link the env to project folder
    run("echo '{0}' > {1}/.project".format(project_path, project_env_path))

    # copy py script to virtualenv and replace python path to the one in vritalenv
    py_script = """#!{}/bin/python

import sys

from easypy import core

if __name__ == '__main__':
    core.router(sys.argv)
""".format(project_env_path)
    run('echo \"{0}\" > {1}/bin/py'.format(py_script, project_env_path))
    # help virtualenvwrapper find project directory
    run('chmod +x {}/bin/py'.format(project_env_path))
    # copy easypy and invoke to site-packages
    import easypy
    import invoke
    easypy_path = easypy.__path__[0]
    invoke_path = invoke.__path__[0]
    run('ln -s {} {}/lib/python2.7/site-packages/easypy'.format(
        easypy_path, project_env_path))
    run('ln -s {} {}/lib/python2.7/site-packages/invoke'.format(
        invoke_path, project_env_path))
Exemple #3
0
def remove(package, dev=False, test=False, prod=False):
    """
    Remove a package.
    """
    run("pip uninstall %s" % package, pty=True)
    c = helpers.Meta('meta.json')
    if dev:
        c.remove_req('dev', package)
    elif test:
        c.remove_req('test', package)
    elif prod:
        c.remove_req('prod', package)
    else:
        c.remove_req('common', package)
Exemple #4
0
def add(package, dev=False, test=False, prod=False):
    """
    Add a package.
    """
    if not helpers.Site.has(package):
        run("pip install %s" % package, pty=True)
    else:
        raise PackageAlreadyInstalled(package)
    c = helpers.Meta('meta.json')
    package_detail = helpers.Site.detail_on(package)
    if dev:
        c.add_req('dev', package_detail)
    elif test:
        c.add_req('test', package_detail)
    elif prod:
        c.add_req('prod', package_detail)
    else:
        c.add_req('common', package_detail)
Exemple #5
0
def resolve():
    # remove resolve command from activate file
    project_env_path = os.getenv('VIRTUAL_ENV')
    activate_script_path = os.path.join(project_env_path, 'bin/activate')
    # read contents
    activate_script = open(activate_script_path, 'r')
    script_content = activate_script.read()
    activate_script.close()
    script_content = script_content.replace('\npy resolve', '')
    # remove py resolve command from script
    activate_script = open(activate_script_path, 'w')
    activate_script.write(script_content)
    activate_script.close()
    # prepare to install requirements
    env = os.getenv('EASY_ENV')
    c = helpers.Meta('meta.json')
    requirements = c.get_requirements(env)
    for areq in requirements:
        run("pip install %s" % areq)
Exemple #6
0
def meta(key_value):
    """
    Give information on a project.
    """
    c = helpers.Meta('meta.json')
    try:
        # its set request
        composite_key, value = key_value.split('=')
        keys = composite_key.split('.')
        c.set(keys, value)
    except ValueError:
        keys = key_value.split('.')
        data = c.data
        for akey in keys:
            data = data[akey]
        if hasattr(data, '__iter__'):
            for adata in data:
                print adata
        else:
            print data
Exemple #7
0
    "url": "https://github.com/ludbek/easypy",
    "license": open("LICENSE.nf").read(),
    # See https://PyPI.python.org/PyPI?%3Aaction=list_classifier
    "classifiers": "",
    "keywords": "package manager, task executor, package creator",
    "packages": find_packages(),
    "include_package_data": True,
    "package_data": {},
    "entry_points": {
        'console_scripts': [
            'py = easypy.core:router',
        ]
    },
}

c = helpers.Meta('meta.json')
package['name'] = c.get('name')
package['version'] = c.get('version')
package['description'] = c.get('description')
package['install_requires'] = c.get_requirements('prod')

setup(**package)

# configure virtualenvwrapper
path_to_bashrc = os.path.join(os.path.expanduser("~"), ".bashrc")
file = open(path_to_bashrc, 'r')
content = file.read()
file.close()

if not "source /usr/local/bin/virtualenvwrapper.sh" in content:
    vw_config = """