def load_plugin(self, project, name, version=None, plugin_module_name=None): display_name = _plugin_display_name(name, version, plugin_module_name) update_plugin = False force_reinstall = False thirdparty_plugin = name # Maybe we already installed this plugin from PyPI before if thirdparty_plugin.startswith(PYPI_PLUGIN_PROTOCOL): thirdparty_plugin = thirdparty_plugin.replace( PYPI_PLUGIN_PROTOCOL, "") update_plugin = should_update_package(version) elif thirdparty_plugin.startswith(VCS_PLUGIN_PROTOCOL): if not plugin_module_name: raise UnspecifiedPluginNameException(name) thirdparty_plugin = plugin_module_name force_reinstall = True # This is done before we attempt to load a plugin regardless of whether it can be loaded or not if update_plugin or force_reinstall: self.logger.info( "Downloading or updating plugin {0}".format(display_name)) try: _install_external_plugin(project, name, version, self.logger, plugin_module_name, update_plugin, force_reinstall) self.logger.info( "Installed or updated plugin {0}.".format(display_name)) except MissingPluginException as e: self.logger.error( "Could not install or upgrade plugin {0}: {1}.".format( display_name, e)) # Now let's try to load the plugin try: return self._load_installed_plugin(thirdparty_plugin, name) except MissingPluginException: if update_plugin or force_reinstall: # If we already tried installing - fail fast raise self.logger.warn("Missing plugin {0}".format(display_name)) # We have failed to update or to load a plugin without a previous installation self.logger.info("Downloading plugin {0}".format(display_name)) try: _install_external_plugin(project, name, version, self.logger, plugin_module_name) self.logger.info("Installed plugin {0}.".format(display_name)) except MissingPluginException as e: self.logger.error("Could not install plugin {0}: {1}.".format( display_name, e)) raise # After we have failed to update or load return self._load_installed_plugin(thirdparty_plugin, name)
def _filter_dependencies(logger, project, dependencies, entry_paths, ignore_installed): dependencies = as_list(dependencies) installed_packages = get_packages_info(entry_paths) dependencies_to_install = [] dependency_constraints = [] for dependency in dependencies: logger.debug("Inspecting package %s", dependency) if ignore_installed: logger.debug("Package %s will be installed because existing installation will be ignored", dependency) dependencies_to_install.append(dependency) continue if dependency.declaration_only: logger.info("Package %s is declaration-only and will not be installed", dependency) continue if isinstance(dependency, RequirementsFile): # Always add requirement file-based dependencies logger.debug("Package %s is a requirement file and will be updated", dependency) dependencies_to_install.append(dependency) continue elif isinstance(dependency, Dependency): if dependency.version: dependency_constraints.append(dependency) logger.debug("Package %s is added to the list of installation constraints", dependency) if dependency.url: # Always add dependency that is url-based logger.debug("Package %s is URL-based and will be updated", dependency) dependencies_to_install.append(dependency) continue if should_update_package(dependency.version) and not getattr(dependency, "version_not_a_spec", False): # Always add dependency that has a version specifier indicating desire to always update logger.debug("Package %s has a non-exact version specifier and will be updated", dependency) dependencies_to_install.append(dependency) continue dependency_name = dependency.name.lower() if dependency_name not in installed_packages: # If dependency not installed at all then install it logger.debug("Package %s is not installed and will be installed", dependency) dependencies_to_install.append(dependency) continue if dependency.version and not version_satisfies_spec(dependency.version, installed_packages[dependency_name].version): # If version is specified and version constraint is not satisfied logger.debug("Package '%s' is not satisfied by installed dependency version '%s' and will be installed" % (dependency, installed_packages[dependency_name].version)) dependencies_to_install.append(dependency) continue logger.debug("Package '%s' is already up-to-date and will be skipped" % dependency) return dependencies_to_install, installed_packages, dependency_constraints
def _filter_dependencies(logger, project, dependencies): dependencies = as_list(dependencies) installed_packages = get_package_version(dependencies) dependencies_to_install = [] for dependency in dependencies: logger.debug("Inspecting dependency '%s'" % dependency) if isinstance(dependency, RequirementsFile): # Always add requirement file-based dependencies logger.debug( "Dependency '%s' is a requirement file and will be included" % dependency) dependencies_to_install.append(dependency) continue elif isinstance(dependency, Dependency): if dependency.url: # Always add dependency that is url-based logger.debug( "Dependency '%s' is URL-based and will be included" % dependency) dependencies_to_install.append(dependency) continue if should_update_package(dependency.version) and not getattr( dependency, "version_not_a_spec", False): # Always add dependency that has a version specifier indicating desire to always update logger.debug( "Dependency '%s' has a non-exact version specifier and will be included" % dependency) dependencies_to_install.append(dependency) continue dependency_name = dependency.name.lower() if dependency_name not in installed_packages: # If dependency not installed at all then install it logger.debug( "Dependency '%s' is not installed and will be included" % dependency) dependencies_to_install.append(dependency) continue if dependency.version and not version_satisfies_spec( dependency.version, installed_packages[dependency_name]): # If version is specified and version constraint is not satisfied logger.debug( "Dependency '%s' is not satisfied by installed dependency version '%s' and will be included" % (dependency, installed_packages[dependency_name])) dependencies_to_install.append(dependency) continue logger.debug( "Dependency '%s' is already up-to-date and will be skipped" % dependency) return dependencies_to_install, installed_packages
def _filter_dependencies(logger, project, dependencies): dependencies = as_list(dependencies) installed_packages = pip_utils.get_package_version(dependencies) dependencies_to_install = [] dependency_constraints = [] for dependency in dependencies: logger.debug("Inspecting dependency '%s'" % dependency) if isinstance(dependency, RequirementsFile): # Always add requirement file-based dependencies logger.debug("Dependency '%s' is a requirement file and will be included" % dependency) dependencies_to_install.append(dependency) continue elif isinstance(dependency, Dependency): if dependency.version: dependency_constraints.append(dependency) logger.debug( "Dependency '%s' is added to the list of installation constraints" % dependency) if dependency.url: # Always add dependency that is url-based logger.debug("Dependency '%s' is URL-based and will be included" % dependency) dependencies_to_install.append(dependency) continue if pip_utils.should_update_package(dependency.version) \ and not getattr(dependency, "version_not_a_spec", False): # Always add dependency that has a version specifier indicating desire to always update logger.debug("Dependency '%s' has a non-exact version specifier and will be included" % dependency) dependencies_to_install.append(dependency) continue dependency_name = dependency.name.lower() if dependency_name not in installed_packages: # If dependency not installed at all then install it logger.debug("Dependency '%s' is not installed and will be included" % dependency) dependencies_to_install.append(dependency) continue if dependency.version \ and not pip_utils.version_satisfies_spec(dependency.version, installed_packages[dependency_name]): # If version is specified and version constraint is not satisfied logger.debug("Dependency '%s' is not satisfied by installed dependency version '%s' and will be included" % (dependency, installed_packages[dependency_name])) dependencies_to_install.append(dependency) continue logger.debug("Dependency '%s' is already up-to-date and will be skipped" % dependency) return dependencies_to_install, installed_packages, dependency_constraints
def load_plugin(self, project, name, version=None, plugin_module_name=None): display_name = _plugin_display_name(name, version, plugin_module_name) update_plugin = False force_reinstall = False thirdparty_plugin = name # Maybe we already installed this plugin from PyPI before if thirdparty_plugin.startswith(PYPI_PLUGIN_PROTOCOL): thirdparty_plugin = thirdparty_plugin.replace(PYPI_PLUGIN_PROTOCOL, "") update_plugin = should_update_package(version) elif thirdparty_plugin.startswith(VCS_PLUGIN_PROTOCOL): if not plugin_module_name: raise UnspecifiedPluginNameException(name) thirdparty_plugin = plugin_module_name force_reinstall = True # This is done before we attempt to load a plugin regardless of whether it can be loaded or not if update_plugin or force_reinstall: self.logger.info("Downloading or updating plugin {0}".format(display_name)) try: _install_external_plugin(project, name, version, self.logger, plugin_module_name, update_plugin, force_reinstall) self.logger.info("Installed or updated plugin {0}.".format(display_name)) except MissingPluginException as e: self.logger.error("Could not install or upgrade plugin {0}: {1}.".format(display_name, e)) # Now let's try to load the plugin try: return self._load_installed_plugin(thirdparty_plugin, name) except MissingPluginException: if update_plugin or force_reinstall: # If we already tried installing - fail fast raise self.logger.warn("Missing plugin {0}".format(display_name)) # We have failed to update or to load a plugin without a previous installation self.logger.info("Downloading plugin {0}".format(display_name)) try: _install_external_plugin(project, name, version, self.logger, plugin_module_name) self.logger.info("Installed plugin {0}.".format(display_name)) except MissingPluginException as e: self.logger.error("Could not install plugin {0}: {1}.".format(display_name, e)) raise # After we have failed to update or load return self._load_installed_plugin(thirdparty_plugin, name)
def install_dependencies(logger, project, dependencies, python_env, log_file_name, local_mapping=None, constraints_file_name=None, log_file_mode="ab", package_type="dependency", target_dir=None, ignore_installed=False, ): entry_paths = target_dir or python_env.site_paths dependencies_to_install, orig_installed_pkgs, dependency_constraints = _filter_dependencies(logger, project, dependencies, entry_paths, ignore_installed) constraints_file = None if constraints_file_name: constraints_file = np(jp(python_env.env_dir, constraints_file_name)) create_constraint_file(constraints_file, dependency_constraints) if not local_mapping: local_mapping = {} install_batch = [] for dependency in dependencies_to_install: url = getattr(dependency, "url", None) install_options = {} if should_update_package(dependency.version) and not getattr(dependency, "version_not_a_spec", False): install_options["upgrade"] = True if dependency.name in local_mapping or url: install_options["force_reinstall"] = bool(url) if not target_dir and dependency.name in local_mapping: install_options["target_dir"] = local_mapping[dependency.name] install_batch.append((as_pip_install_target(dependency), install_options)) logger.info("Processing %s packages '%s%s'%s to be installed with %s", package_type, dependency.name, dependency.version if dependency.version else "", " from %s" % url if url else "", install_options) if install_batch: pip_env = {"PIP_NO_INPUT": "1"} if project.offline: pip_env["PIP_NO_INDEX"] = "1" logger.warn("PIP will be operating in the offline mode") with open(np(log_file_name), log_file_mode) as log_file: results = pip_install_batches(install_batch, python_env, 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"), insecure_installs=project.get_property( "install_dependencies_insecure_installation"), verbose=project.get_property("pip_verbose"), constraint_file=constraints_file, logger=logger, outfile_name=log_file, error_file_name=log_file, target_dir=target_dir, ignore_installed=ignore_installed) for result in results: if result: raise BuildFailedException("Unable to install %s packages into %s. " "Please see '%s' for full details:\n%s", package_type, python_env.env_dir, log_file_name, tail_log(log_file_name)) return dependencies_to_install