def test_wheel_version(tmpdir, data): future_wheel = "futurewheel-1.9-py2.py3-none-any.whl" broken_wheel = "brokenwheel-1.0-py2.py3-none-any.whl" future_version = (1, 9) unpack_file(data.packages.join(future_wheel), tmpdir + "future", None, None) unpack_file(data.packages.join(broken_wheel), tmpdir + "broken", None, None) assert wheel.wheel_version(tmpdir + "future") == future_version assert not wheel.wheel_version(tmpdir + "broken")
def test_wheel_version(tmpdir, data): future_wheel = 'futurewheel-1.9-py2.py3-none-any.whl' broken_wheel = 'brokenwheel-1.0-py2.py3-none-any.whl' future_version = (1, 9) unpack_file(data.packages.join(future_wheel), tmpdir + 'future', None, None) unpack_file(data.packages.join(broken_wheel), tmpdir + 'broken', None, None) assert wheel.wheel_version(tmpdir + 'future') == future_version assert not wheel.wheel_version(tmpdir + 'broken')
def install_requirements(self, requirements, **kw): """ Manually install a requirement set from binary and/or wheel distributions. :param requirements: A list of :class:`pip_accel.req.Requirement` objects. :param kw: Any keyword arguments are passed on to :func:`~pip_accel.bdist.BinaryDistributionManager.install_binary_dist()`. :returns: The number of packages that were just installed (an integer). """ install_timer = Timer() install_types = [] if any(not req.is_wheel for req in requirements): install_types.append('binary') if any(req.is_wheel for req in requirements): install_types.append('wheel') logger.info("Installing from %s distributions ..", concatenate(install_types)) # Track installed files by default (unless the caller specifically opted out). kw.setdefault('track_installed_files', True) num_installed = 0 for requirement in requirements: # If we're upgrading over an older version, first remove the # old version to make sure we don't leave files from old # versions around. if is_installed(requirement.name): uninstall(requirement.name) # When installing setuptools we need to uninstall distribute, # otherwise distribute will shadow setuptools and all sorts of # strange issues can occur (e.g. upgrading to the latest # setuptools to gain wheel support and then having everything # blow up because distribute doesn't know about wheels). if requirement.name == 'setuptools' and is_installed('distribute'): uninstall('distribute') if requirement.is_editable: logger.debug("Installing %s in editable form using pip.", requirement) command = InstallCommand() opts, args = command.parse_args( ['--no-deps', '--editable', requirement.source_directory]) command.run(opts, args) elif requirement.is_wheel: logger.info("Installing %s wheel distribution using pip ..", requirement) wheel_version = pip_wheel_module.wheel_version( requirement.source_directory) pip_wheel_module.check_compatibility(wheel_version, requirement.name) requirement.pip_requirement.move_wheel_files( requirement.source_directory) else: binary_distribution = self.bdists.get_binary_dist(requirement) self.bdists.install_binary_dist(binary_distribution, **kw) num_installed += 1 logger.info("Finished installing %s in %s.", pluralize(num_installed, "requirement"), install_timer) return num_installed
def install_requirements(self, requirements, **kw): """ Manually install a requirement set from binary and/or wheel distributions. :param requirements: A list of :class:`pip_accel.req.Requirement` objects. :param kw: Any keyword arguments are passed on to :func:`~pip_accel.bdist.BinaryDistributionManager.install_binary_dist()`. :returns: The number of packages that were just installed (an integer). """ install_timer = Timer() install_types = [] if any(not req.is_wheel for req in requirements): install_types.append('binary') if any(req.is_wheel for req in requirements): install_types.append('wheel') logger.info("Installing from %s distributions ..", concatenate(install_types)) # Track installed files by default (unless the caller specifically opted out). kw.setdefault('track_installed_files', True) num_installed = 0 for requirement in requirements: # If we're upgrading over an older version, first remove the # old version to make sure we don't leave files from old # versions around. if is_installed(requirement.name): uninstall(requirement.name) # When installing setuptools we need to uninstall distribute, # otherwise distribute will shadow setuptools and all sorts of # strange issues can occur (e.g. upgrading to the latest # setuptools to gain wheel support and then having everything # blow up because distribute doesn't know about wheels). if requirement.name == 'setuptools' and is_installed('distribute'): uninstall('distribute') if requirement.is_editable: logger.debug("Installing %s in editable form using pip.", requirement) command = InstallCommand() opts, args = command.parse_args(['--no-deps', '--editable', requirement.source_directory]) command.run(opts, args) elif requirement.is_wheel: logger.info("Installing %s wheel distribution using pip ..", requirement) wheel_version = pip_wheel_module.wheel_version(requirement.source_directory) pip_wheel_module.check_compatibility(wheel_version, requirement.name) requirement.pip_requirement.move_wheel_files(requirement.source_directory) else: binary_distribution = self.bdists.get_binary_dist(requirement) self.bdists.install_binary_dist(binary_distribution, **kw) num_installed += 1 logger.info("Finished installing %s in %s.", pluralize(num_installed, "requirement"), install_timer) return num_installed
def install( self, install_options, # type: List[str] global_options=None, # type: Optional[Sequence[str]] root=None, # type: Optional[str] home=None, # type: Optional[str] prefix=None, # type: Optional[str] warn_script_location=True, # type: bool use_user_site=False, # type: bool pycompile=True # type: bool ): # type: (...) -> None global_options = global_options if global_options is not None else [] if self.editable: self.install_editable( install_options, global_options, prefix=prefix, ) return if self.is_wheel: version = wheel.wheel_version(self.source_dir) wheel.check_compatibility(version, self.name) self.move_wheel_files( self.source_dir, root=root, prefix=prefix, home=home, warn_script_location=warn_script_location, use_user_site=use_user_site, pycompile=pycompile, ) self.install_succeeded = True return # Extend the list of global and install options passed on to # the setup.py call with the ones from the requirements file. # Options specified in requirements file override those # specified on the command line, since the last option given # to setup.py is the one that is used. global_options = list(global_options) + \ self.options.get('global_options', []) install_options = list(install_options) + \ self.options.get('install_options', []) if self.isolated: # https://github.com/python/mypy/issues/1174 global_options = global_options + ["--no-user-cfg"] # type: ignore with TempDirectory(kind="record") as temp_dir: record_filename = os.path.join(temp_dir.path, 'install-record.txt') install_args = self.get_install_args( global_options, record_filename, root, prefix, pycompile, ) msg = 'Running setup.py install for %s' % (self.name, ) with open_spinner(msg) as spinner: with indent_log(): with self.build_env: call_subprocess( install_args + install_options, cwd=self.setup_py_dir, show_stdout=False, spinner=spinner, ) if not os.path.exists(record_filename): logger.debug('Record file %s not found', record_filename) return self.install_succeeded = True def prepend_root(path): if root is None or not os.path.isabs(path): return path else: return change_root(root, path) with open(record_filename) as f: for line in f: directory = os.path.dirname(line) if directory.endswith('.egg-info'): egg_info_dir = prepend_root(directory) break else: logger.warning( 'Could not find .egg-info directory in install record' ' for %s', self, ) # FIXME: put the record somewhere # FIXME: should this be an error? return new_lines = [] with open(record_filename) as f: for line in f: filename = line.strip() if os.path.isdir(filename): filename += os.path.sep new_lines.append( os.path.relpath(prepend_root(filename), egg_info_dir)) new_lines.sort() ensure_dir(egg_info_dir) inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt') with open(inst_files_path, 'w') as f: f.write('\n'.join(new_lines) + '\n')