def prepare(project, logger): target_directory = project.expand_path("$dir_target") if not os.path.exists(target_directory): logger.debug("Creating target directory %s", target_directory) os.mkdir(target_directory) reports_directory = project.expand_path("$dir_reports") if not os.path.exists(reports_directory): logger.debug("Creating reports directory %s", reports_directory) os.mkdir(reports_directory) plugin_dependency_versions = get_package_version(project.plugin_dependencies, logger) for plugin_dependency in project.plugin_dependencies: logger.debug("Processing plugin dependency %s" % plugin_dependency) if plugin_dependency.name.lower() not in plugin_dependency_versions or not \ version_satisfies_spec(plugin_dependency.version, plugin_dependency_versions[plugin_dependency.name.lower()]): logger.info("Installing plugin dependency %s" % plugin_dependency) log_file = project.expand_path("$dir_reports", safe_log_file_name("dependency_%s_install.log" % plugin_dependency)) pip_install(as_pip_install_target(plugin_dependency), index_url=project.get_property("install_dependencies_index_url"), extra_index_url=project.get_property("install_dependencies_extra_index_url"), verbose=project.get_property("verbose"), logger=logger, force_reinstall=plugin_dependency.url is not None, outfile_name=log_file, error_file_name=log_file)
def prepare(project, logger): target_directory = project.expand_path("$dir_target") if not os.path.exists(target_directory): logger.debug("Creating target directory %s", target_directory) os.mkdir(target_directory) reports_directory = project.expand_path("$dir_reports") if not os.path.exists(reports_directory): logger.debug("Creating reports directory %s", reports_directory) os.mkdir(reports_directory) plugin_dependency_versions = get_package_version( project.plugin_dependencies, logger) for plugin_dependency in project.plugin_dependencies: logger.debug("Processing plugin dependency %s" % plugin_dependency) if plugin_dependency.name.lower() not in plugin_dependency_versions or not \ version_satisfies_spec(plugin_dependency.version, plugin_dependency_versions[plugin_dependency.name.lower()]): logger.info("Installing plugin dependency %s" % plugin_dependency) log_file = project.expand_path( "$dir_reports", safe_log_file_name("dependency_%s_install.log" % plugin_dependency)) pip_install(as_pip_install_target(plugin_dependency), index_url=project.get_property( "install_dependencies_index_url"), extra_index_url=project.get_property( "install_dependencies_extra_index_url"), verbose=project.get_property("verbose"), logger=logger, force_reinstall=plugin_dependency.url is not None, outfile_name=log_file, error_file_name=log_file)
def test_pip_install_environ_inherited(self, execute_command): pip_utils.pip_install("blah") execute_command.assert_called_once_with(ANY, cwd=None, env=os.environ, error_file_name=None, outfile_name=None, shell=False)
def test_pip_install_environ_overwritten(self, execute_command): env_dict = dict() pip_utils.pip_install("blah", env=env_dict) execute_command.assert_called_once_with(ANY, cwd=None, env=env_dict, error_file_name=None, outfile_name=None, shell=False)
def install_distribution(project, logger): logger.info("Installing project %s-%s", project.name, project.version) _prepare_reports_dir(project) outfile_name = project.expand_path("$dir_reports", "distutils", "pip_install_%s" % datetime.utcnow().strftime("%Y%m%d%H%M%S")) pip_install(project.expand_path("$dir_dist"), force_reinstall=True, logger=logger, verbose=project.get_property("verbose"), cwd=".", outfile_name=outfile_name, error_file_name=outfile_name)
def install_distribution(project, logger): logger.info("Installing project %s-%s", project.name, project.version) _prepare_reports_dir(project) outfile_name = project.expand_path("$dir_reports", "distutils", "pip_install_%s" % datetime.utcnow().strftime("%Y%m%d%H%M%S")) pip_install(project.expand_path("$dir_dist"), index_url=project.get_property("install_dependencies_index_url"), extra_index_url=project.get_property("install_dependencies_extra_index_url"), force_reinstall=True, logger=logger, verbose=project.get_property("verbose"), cwd=".", outfile_name=outfile_name, error_file_name=outfile_name)
def test_pip_install_environ_inherited(self): python_env = Mock() python_env.executable = [] python_env.environ = {} pip_utils.pip_install("blah", python_env) python_env.execute_command.assert_called_once_with( ANY, cwd=None, env=python_env.environ, error_file_name=None, outfile_name=None, shell=False, no_path_search=True)
def test_pip_install_environ_overwritten(self): env_dict = {"a": "b"} python_env = Mock() python_env.executable = [] python_env.environ = {} pip_utils.pip_install("blah", python_env, env=env_dict) python_env.execute_command.assert_called_once_with( ANY, cwd=None, env=env_dict, error_file_name=None, outfile_name=None, shell=False, no_path_search=True)
def _do_install_dependency(logger, project, dependency, upgrade, eager_upgrade, force_reinstall, constraint_file, target_dir, log_file): batch = isinstance(dependency, collections.Iterable) exit_code = pip_utils.pip_install( install_targets=dependency, index_url=project.get_property("install_dependencies_index_url"), extra_index_url=project.get_property("install_dependencies_extra_index_url"), upgrade=upgrade, insecure_installs=project.get_property("install_dependencies_insecure_installation"), force_reinstall=force_reinstall, target_dir=target_dir, verbose=project.get_property("verbose"), trusted_host=project.get_property("install_dependencies_trusted_host"), constraint_file=constraint_file, eager_upgrade=eager_upgrade, logger=logger, outfile_name=log_file) if exit_code != 0: if batch: dependency_name = " batch dependencies." else: dependency_name = " dependency '%s'." % dependency.name raise BuildFailedException("Unable to install%s See %s for full details:\n%s", dependency_name, log_file, tail_log(log_file))
def _install_external_plugin(project, name, version, logger, plugin_module_name, upgrade=False, force_reinstall=False): if not name.startswith(PYPI_PLUGIN_PROTOCOL) and not name.startswith(VCS_PLUGIN_PROTOCOL): message = "Only plugins starting with '{0}' are currently supported" raise MissingPluginException(name, message.format((PYPI_PLUGIN_PROTOCOL, VCS_PLUGIN_PROTOCOL))) if name.startswith(PYPI_PLUGIN_PROTOCOL): pip_package = name.replace(PYPI_PLUGIN_PROTOCOL, "") if version: pip_package += str(version) upgrade = True elif name.startswith(VCS_PLUGIN_PROTOCOL): pip_package = name.replace(VCS_PLUGIN_PROTOCOL, "") force_reinstall = True with tempfile.NamedTemporaryFile(delete=True) as log_file: log_file_name = log_file.name result = pip_install(pip_package, index_url=project.get_property("install_dependencies_index_url"), extra_index_url=project.get_property("install_dependencies_extra_index_url"), trusted_host=project.get_property("install_dependencies_trusted_host"), upgrade=upgrade, force_reinstall=force_reinstall, logger=logger, outfile_name=log_file_name, error_file_name=log_file_name, cwd=".") if result != 0: logger.error("The following pip error was encountered:\n" + "".join(read_file(log_file_name))) message = "Failed to install plugin from {0}".format(pip_package) raise MissingPluginException(name, message)
def _do_install_dependency(logger, project, dependency, upgrade, eager_upgrade, force_reinstall, constraint_file, target_dir, log_file): batch = isinstance(dependency, collections.Iterable) exit_code = pip_utils.pip_install( install_targets=dependency, index_url=project.get_property("install_dependencies_index_url"), extra_index_url=project.get_property( "install_dependencies_extra_index_url"), upgrade=upgrade, insecure_installs=project.get_property( "install_dependencies_insecure_installation"), force_reinstall=force_reinstall, target_dir=target_dir, verbose=project.get_property("verbose"), trusted_host=project.get_property("install_dependencies_trusted_host"), constraint_file=constraint_file, eager_upgrade=eager_upgrade, logger=logger, outfile_name=log_file) if exit_code != 0: if batch: dependency_name = " batch dependencies." else: dependency_name = " dependency '%s'." % dependency.name raise BuildFailedException( "Unable to install%s See %s for full details:\n%s", dependency_name, log_file, tail_log(log_file))
def prepare(project, logger): target_directory = project.expand_path("$dir_target") if not os.path.exists(target_directory): logger.debug("Creating target directory %s", target_directory) os.mkdir(target_directory) reports_directory = project.expand_path("$dir_reports") if not os.path.exists(reports_directory): logger.debug("Creating reports directory %s", reports_directory) os.mkdir(reports_directory) plugin_dependency_versions = pip_utils.get_package_version( project.plugin_dependencies, logger) for plugin_dependency in project.plugin_dependencies: logger.debug("Processing plugin dependency %s" % plugin_dependency) dependency_name = plugin_dependency.name.lower() no_version_installed = dependency_name not in plugin_dependency_versions if not no_version_installed: version_satisfies = pip_utils.version_satisfies_spec( plugin_dependency.version, plugin_dependency_versions[dependency_name]) if no_version_installed or not version_satisfies: logger.info("Installing plugin dependency %s" % plugin_dependency) log_file = project.expand_path( "$dir_reports", safe_log_file_name("dependency_%s_install.log" % plugin_dependency)) install_targets = pip_utils.as_pip_install_target( plugin_dependency) result = pip_utils.pip_install( install_targets=install_targets, index_url=project.get_property( "install_dependencies_index_url"), extra_index_url=project.get_property( "install_dependencies_extra_index_url"), verbose=project.get_property("verbose"), logger=logger, force_reinstall=plugin_dependency.url is not None, outfile_name=log_file, error_file_name=log_file) if result: log_lines = list(tail(log_file)) log = log_lines[-1] if not project.get_property( "debug") else "\n".join(log_lines) if no_version_installed: raise MissingPluginDependencyException( ",".join(install_targets), log) else: logger.error("Failed to install '%s':\n%s", plugin_dependency, log)