def main(): """ _main_ Execute selfsetup command """ opts = build_parser(sys.argv[1:]) config = load_setup_configuration() # make sure gitconfig has a cirrus section if 'cirrus' not in config.gitconfig.sections: config.gitconfig.add_section('cirrus') if is_anaconda(): config.gitconfig.set_param('alias', 'cirrus', '! {0}/cirrus'.format(cirrus_bin())) else: config.gitconfig.set_param( 'alias', 'cirrus', '! {0}/bin/cirrus'.format(os.environ['VIRTUALENV_HOME'])) # make sure the creds plugin value is set if opts.cred_plugin is not None: config._set_creds_plugin(opts.cred_plugin) if not opts.robot_mode: interactive_setup(opts, config) else: robot_setup(opts, config)
def get_builder_plugin(): """ Get the builder plugin name default. If not provided by CLI opt, start with user pref in gitconfig, Look for hint in cirrus conf or just resort to a guess based on what python cirrus is using """ # TODO look up in git config config = load_configuration() builder = None if config.has_gitconfig_param('builder'): builder = str(config.get_gitconfig_param('builder')) if builder: LOGGER.info("Using Builder Plugin from gitconfig: {}".format(builder)) return builder build_config = config.get('build', {}) builder = build_config.get('builder') if builder is not None: LOGGER.info( "Using Builder Plugin from cirrus.conf: {}".format(builder)) return builder # fall back to old defaults if is_anaconda(): LOGGER.info("Using default CondaPip builder") builder = "CondaPip" else: LOGGER.info("Using default VirtualenvPip builder") builder = "VirtualenvPip" return builder
def get_builder_plugin(): """ Get the builder plugin name default. If not provided by CLI opt, start with user pref in gitconfig, Look for hint in cirrus conf or just resort to a guess based on what python cirrus is using """ # TODO look up in git config config = load_configuration() builder = None if config.has_gitconfig_param('builder'): builder = str(config.get_gitconfig_param('builder')) if builder: LOGGER.info("Using Builder Plugin from gitconfig: {}".format(builder)) return builder build_config = config.get('build', {}) builder = build_config.get('builder') if builder is not None: LOGGER.info("Using Builder Plugin from cirrus.conf: {}".format(builder)) return builder # fall back to old defaults if is_anaconda(): LOGGER.info("Using default CondaPip builder") builder = "CondaPip" else: LOGGER.info("Using default VirtualenvPip builder") builder = "VirtualenvPip" return builder
def pip_install(version, update_setuptools=False): """pip install the version of cirrus requested""" pip_req = 'cirrus-cli=={0}'.format(version) venv_path = virtualenv_home() venv_name = os.path.basename(venv_path) LOGGER.info("running pip upgrade...") if is_anaconda(): if update_setuptools: local( 'source {0}/bin/activate {1} && pip install --upgrade setuptools'.format( venv_path, venv_path ) ) local( 'source {0}/bin/activate {1} && pip install --upgrade {2}'.format( venv_path, venv_path, pip_req ) ) else: if update_setuptools: local( ' . ./{0}/bin/activate && pip install --upgrade setuptools'.format( venv_name ) ) local( ' . ./{0}/bin/activate && pip install --upgrade {1}'.format( venv_name, pip_req ) )
def pip_install(version, update_setuptools=False): """pip install the version of cirrus requested""" pip_req = 'cirrus-cli=={0}'.format(version) venv_path = virtualenv_home() venv_name = os.path.basename(venv_path) LOGGER.info("running pip upgrade...") if is_anaconda(): if update_setuptools: local( 'source {0}/bin/activate {1} && pip install --upgrade setuptools' .format(venv_path, venv_path)) local( 'source {0}/bin/activate {1} && pip install --upgrade {2}'.format( venv_path, venv_path, pip_req)) else: if update_setuptools: local(' . ./{0}/bin/activate && pip install --upgrade setuptools'. format(venv_name)) local(' . ./{0}/bin/activate && pip install --upgrade {1}'.format( venv_name, pip_req))
def execute_build(opts): """ _execute_build_ Execute the build in the current package context. - reads the config to check for custom build parameters - defaults to ./venv for virtualenv - defaults to ./requirements.txt for reqs - removes existing virtualenv if clean flag is set - builds the virtualenv - pip installs the requirements into it : param argparse.Namspace opts: A Namespace of build options """ working_dir = repo_directory() config = load_configuration() build_params = config.get('build', {}) # we have custom build controls in the cirrus.conf venv_name = build_params.get('virtualenv_name', 'venv') reqs_name = build_params.get('requirements_file', 'requirements.txt') extra_reqs = build_params.get('extra_requirements', '') python_bin = build_params.get('python', None) if opts.python: python_bin = opts.python extra_reqs = [x.strip() for x in extra_reqs.split(',') if x.strip()] if opts.extras: extra_reqs.extend(opts.extras) extra_reqs = set(extra_reqs) # dedupe venv_path = os.path.join(working_dir, venv_name) if is_anaconda(): conda_venv(venv_path, opts, python_bin) else: virtualenv_venv(venv_path, opts, python_bin) # custom pypi server pypi_server = config.pypi_url() pip_options = config.pip_options() pip_command_base = None if pypi_server is not None: pypirc = PypircFile() if pypi_server in pypirc.index_servers: pypi_url = pypirc.get_pypi_url(pypi_server) else: pypi_conf = get_pypi_auth() pypi_url = ( "https://{pypi_username}:{pypi_token}@{pypi_server}/simple" ).format(pypi_token=pypi_conf['token'], pypi_username=pypi_conf['username'], pypi_server=pypi_server) pip_command_base = ('{0}/bin/pip install -i {1}').format( venv_path, pypi_url) if opts.upgrade: cmd = ('{0} --upgrade ' '-r {1}').format(pip_command_base, reqs_name) else: cmd = ('{0} ' '-r {1}').format(pip_command_base, reqs_name) else: pip_command_base = '{0}/bin/pip install'.format(venv_path) # no pypi server if opts.upgrade: cmd = '{0} --upgrade -r {1}'.format(pip_command_base, reqs_name) else: cmd = '{0} -r {1}'.format(pip_command_base, reqs_name) if pip_options: cmd += " {} ".format(pip_options) try: local(cmd) except OSError as ex: msg = ("Error running pip install command during build\n" "Error was {0}\n" "Running command: {1}\n" "Working Dir: {2}\n" "Virtualenv: {3}\n" "Requirements: {4}\n").format(ex, cmd, working_dir, venv_path, reqs_name) LOGGER.error(msg) sys.exit(1) if extra_reqs: if opts.upgrade: commands = [ "{0} --upgrade -r {1}".format(pip_command_base, reqfile) for reqfile in extra_reqs ] else: commands = [ "{0} -r {1}".format(pip_command_base, reqfile) for reqfile in extra_reqs ] for cmd in commands: LOGGER.info("Installing extra requirements... {}".format(cmd)) try: local(cmd) except OSError as ex: msg = ("Error running pip install command extra " "requirements install: {}\n{}").format(reqfile, ex) LOGGER.error(msg) sys.exit(1) # setup for development if opts.nosetupdevelop: msg = "skipping python setup.py develop..." LOGGER.info(msg) else: LOGGER.info('running python setup.py develop...') activate = activate_command(venv_path) local('{} && python setup.py develop'.format(activate))
def activate_command(venv_path): if is_anaconda(): command = "source {}/bin/activate {}".format(venv_path, venv_path) else: command = ". {}/bin/activate".format(venv_path) return command