def data_directory(self): """ The absolute pathname of the directory where pip-accel's data files are stored (a string). - Environment variable: ``$PIP_ACCEL_CACHE`` - Configuration option: ``data-directory`` - Default: ``/var/cache/pip-accel`` if running as ``root``, ``~/.pip-accel`` otherwise """ return expand_path(self.get(property_name='data_directory', environment_variable='PIP_ACCEL_CACHE', configuration_option='data-directory', default='/var/cache/pip-accel' if is_root() else '~/.pip-accel'))
def install_dependencies(self, requirement): """ Install missing dependencies for the given requirement. :param requirement: A :class:`.Requirement` object. :returns: :data:`True` when missing system packages were installed, :data:`False` otherwise. :raises: :exc:`.DependencyInstallationRefused` when automatic installation is disabled or refused by the operator. :raises: :exc:`.DependencyInstallationFailed` when the installation of missing system packages fails. If `pip-accel` fails to build a binary distribution, it will call this method as a last chance to install missing dependencies. If this function does not raise an exception, `pip-accel` will retry the build once. """ install_timer = Timer() missing_dependencies = self.find_missing_dependencies(requirement) if missing_dependencies: # Compose the command line for the install command. install_command = shlex.split( self.install_command) + missing_dependencies # Prepend `sudo' to the command line? if not WINDOWS and not is_root(): # FIXME Ideally this should properly detect the presence of `sudo'. # Or maybe this should just be embedded in the *.ini files? install_command.insert(0, 'sudo') # Always suggest the installation command to the operator. logger.info( "You seem to be missing %s: %s", pluralize(len(missing_dependencies), "dependency", "dependencies"), concatenate(missing_dependencies)) logger.info("You can install %s with this command: %s", "it" if len(missing_dependencies) == 1 else "them", " ".join(install_command)) if self.config.auto_install is False: # Refuse automatic installation and don't prompt the operator when the configuration says no. self.installation_refused( requirement, missing_dependencies, "automatic installation is disabled") # Get the operator's permission to install the missing package(s). if self.config.auto_install: logger.info( "Got permission to install %s (via auto_install option).", pluralize(len(missing_dependencies), "dependency", "dependencies")) elif self.confirm_installation(requirement, missing_dependencies, install_command): logger.info( "Got permission to install %s (via interactive prompt).", pluralize(len(missing_dependencies), "dependency", "dependencies")) else: logger.error( "Refused installation of missing %s!", "dependency" if len(missing_dependencies) == 1 else "dependencies") self.installation_refused(requirement, missing_dependencies, "manual installation was refused") if subprocess.call(install_command) == 0: logger.info( "Successfully installed %s in %s.", pluralize(len(missing_dependencies), "dependency", "dependencies"), install_timer) return True else: logger.error( "Failed to install %s.", pluralize(len(missing_dependencies), "dependency", "dependencies")) msg = "Failed to install %s required by Python package %s! (%s)" raise DependencyInstallationFailed( msg % (pluralize(len(missing_dependencies), "system package", "system packages"), requirement.name, concatenate(missing_dependencies))) return False
def install_dependencies(self, requirement): """ Install missing dependencies for the given requirement. :param requirement: A :class:`.Requirement` object. :returns: :data:`True` when missing system packages were installed, :data:`False` otherwise. :raises: :exc:`.DependencyInstallationRefused` when automatic installation is disabled or refused by the operator. :raises: :exc:`.DependencyInstallationFailed` when the installation of missing system packages fails. If `pip-accel` fails to build a binary distribution, it will call this method as a last chance to install missing dependencies. If this function does not raise an exception, `pip-accel` will retry the build once. """ install_timer = Timer() missing_dependencies = self.find_missing_dependencies(requirement) if missing_dependencies: # Compose the command line for the install command. install_command = shlex.split(self.install_command) + missing_dependencies # Prepend `sudo' to the command line? if not WINDOWS and not is_root(): # FIXME Ideally this should properly detect the presence of `sudo'. # Or maybe this should just be embedded in the *.ini files? install_command.insert(0, "sudo") # Always suggest the installation command to the operator. logger.info( "You seem to be missing %s: %s", pluralize(len(missing_dependencies), "dependency", "dependencies"), concatenate(missing_dependencies), ) logger.info( "You can install %s with this command: %s", "it" if len(missing_dependencies) == 1 else "them", " ".join(install_command), ) if self.config.auto_install is False: # Refuse automatic installation and don't prompt the operator when the configuration says no. self.installation_refused(requirement, missing_dependencies, "automatic installation is disabled") # Get the operator's permission to install the missing package(s). if self.config.auto_install: logger.info( "Got permission to install %s (via auto_install option).", pluralize(len(missing_dependencies), "dependency", "dependencies"), ) elif self.confirm_installation(requirement, missing_dependencies, install_command): logger.info( "Got permission to install %s (via interactive prompt).", pluralize(len(missing_dependencies), "dependency", "dependencies"), ) else: logger.error( "Refused installation of missing %s!", "dependency" if len(missing_dependencies) == 1 else "dependencies", ) self.installation_refused(requirement, missing_dependencies, "manual installation was refused") if subprocess.call(install_command) == 0: logger.info( "Successfully installed %s in %s.", pluralize(len(missing_dependencies), "dependency", "dependencies"), install_timer, ) return True else: logger.error( "Failed to install %s.", pluralize(len(missing_dependencies), "dependency", "dependencies") ) msg = "Failed to install %s required by Python package %s! (%s)" raise DependencyInstallationFailed( msg % ( pluralize(len(missing_dependencies), "system package", "system packages"), requirement.name, concatenate(missing_dependencies), ) ) return False