def _filter_package_files(package_files): package_reqs = [] package_keys = [] for filename in package_files: package_details = pip_helper.get_archive_details(filename) package_reqs.append(package_details['req']) package_keys.append(package_details['req'].key) package_rpm_names = self._convert_names_python2rpm(package_keys) filtered_files = [] for (filename, req, rpm_name) in zip(package_files, package_reqs, package_rpm_names): if req.key in no_pips: LOG.info(("Dependency %s was downloaded additionally " "but it is disallowed."), colorizer.quote(req)) continue if req.key in pips_keys: filtered_files.append(filename) continue # See if pip tried to download it but we already can satisfy # it via yum and avoid building it in the first place... (_version, repo) = self._find_yum_match(yum_map, req, rpm_name) if not repo: filtered_files.append(filename) else: LOG.info(("Dependency %s was downloaded additionally " "but it can be satisfied by %s from repository " "%s instead."), colorizer.quote(req), colorizer.quote(rpm_name), colorizer.quote(repo)) return filtered_files
def _examine_download_dir(self, pips_to_download, pip_download_dir): pip_names = set([p.key for p in pips_to_download]) what_downloaded = sh.listdir(pip_download_dir, files_only=True) LOG.info("Validating %s files that were downloaded.", len(what_downloaded)) for filename in what_downloaded: pkg_details = pip_helper.get_archive_details(filename) req = pkg_details['req'] if req.key not in pip_names: LOG.info("Dependency %s was automatically included.", colorizer.quote(req))
def _requirements_satisfied(pips_list, download_dir): downloaded_req = [pip_helper.get_archive_details(filename)["req"] for filename in sh.listdir(download_dir, files_only=True)] downloaded_req = dict((req.key, req.specs[0][1]) for req in downloaded_req) for req_str in pips_list: req = pip_helper.extract_requirement(req_str) try: downloaded_version = downloaded_req[req.key] except KeyError: return False else: if downloaded_version not in req: return False return True
def _requirements_satisfied(pips_list, download_dir): downloaded_req = [ pip_helper.get_archive_details(filename)["req"] for filename in sh.listdir(download_dir, files_only=True) ] downloaded_req = dict( (req.key, req.specs[0][1]) for req in downloaded_req) for req_str in pips_list: req = pip_helper.extract_requirement(req_str) try: downloaded_version = downloaded_req[req.key] except KeyError: return False else: if downloaded_version not in req: return False return True
def _build_dependencies(self): (pips_downloaded, package_files) = self.download_dependencies() # Analyze what was downloaded and eject things that were downloaded # by pip as a dependency of a download but which we do not want to # build or can satisfy by other means no_pips = [pkg_resources.Requirement.parse(name).key for name in self.python_names] no_pips.extend(self.ignore_pips) yum_map = self._get_known_yum_packages() pips_keys = set([p.key for p in pips_downloaded]) package_reqs = [] for filename in package_files: package_details = pip_helper.get_archive_details(filename) package_reqs.append((filename, package_details['req'])) def _filter_package_files(): yum_provided = [] req_names = [req.key for (filename, req) in package_reqs] package_rpm_names = self.py2rpm_helper.names_to_rpm_names(req_names) filtered_files = [] for filename, req in package_reqs: rpm_name = package_rpm_names[req.key] if req.key in no_pips: LOG.info(("Dependency %s was downloaded additionally " "but it is disallowed."), colorizer.quote(req)) continue if req.key in pips_keys: filtered_files.append(filename) continue # See if pip tried to download it but we already can satisfy # it via yum and avoid building it in the first place... rpm_info = self._find_yum_match(yum_map, req, rpm_name) if not rpm_info: filtered_files.append(filename) else: yum_provided.append((req, rpm_info)) LOG.info(("Dependency %s was downloaded additionally " "but it can be satisfied by %s from repository " "%s instead."), colorizer.quote(req), colorizer.quote(rpm_name), colorizer.quote(rpm_info['repo'])) return (filtered_files, yum_provided) LOG.info("Filtering %s downloaded files.", len(package_files)) filtered_package_files, yum_provided = _filter_package_files() if yum_provided: yum_buff = six.StringIO() for (req, rpm_info) in yum_provided: dep_info = { 'requirement': str(req), 'rpm': rpm_info, } yum_buff.write(json.dumps(dep_info)) yum_buff.write("\n") sh.append_file(self.yum_satisfies_filename, yum_buff.getvalue()) if not filtered_package_files: LOG.info("No SRPM package dependencies to build.") return for filename in package_files: if filename not in filtered_package_files: sh.unlink(filename) build_requires = six.StringIO() for (filename, req) in package_reqs: if filename in filtered_package_files: build_requires.write("%s # %s\n" % (req, sh.basename(filename))) sh.write_file(self.build_requires_filename, build_requires.getvalue()) # Now build them into SRPM rpm files. package_files = sorted(filtered_package_files) self.py2rpm_helper.build_all_srpms(package_files=package_files, tracewriter=self.tracewriter, jobs=self.jobs)
def _build_dependencies(self): (pips_downloaded, package_files) = self.download_dependencies() # Analyze what was downloaded and eject things that were downloaded # by pip as a dependency of a download but which we do not want to # build or can satisfy by other means no_pips = [ pkg_resources.Requirement.parse(name).key for name in self.python_names ] no_pips.extend(self.ignore_pips) yum_map = self._get_known_yum_packages() pips_keys = set([p.key for p in pips_downloaded]) package_reqs = [] for filename in package_files: package_details = pip_helper.get_archive_details(filename) package_reqs.append((filename, package_details['req'])) def _filter_package_files(): yum_provided = [] req_names = [req.key for (filename, req) in package_reqs] package_rpm_names = self.py2rpm_helper.names_to_rpm_names( req_names) filtered_files = [] for filename, req in package_reqs: rpm_name = package_rpm_names[req.key] if req.key in no_pips: LOG.info(("Dependency %s was downloaded additionally " "but it is disallowed."), colorizer.quote(req)) continue if req.key in pips_keys: filtered_files.append(filename) continue # See if pip tried to download it but we already can satisfy # it via yum and avoid building it in the first place... rpm_info = self._find_yum_match(yum_map, req, rpm_name) if not rpm_info: filtered_files.append(filename) else: yum_provided.append((req, rpm_info)) LOG.info(("Dependency %s was downloaded additionally " "but it can be satisfied by %s from repository " "%s instead."), colorizer.quote(req), colorizer.quote(rpm_name), colorizer.quote(rpm_info['repo'])) return (filtered_files, yum_provided) LOG.info("Filtering %s downloaded files.", len(package_files)) filtered_package_files, yum_provided = _filter_package_files() if yum_provided: yum_buff = six.StringIO() for (req, rpm_info) in yum_provided: dep_info = { 'requirement': str(req), 'rpm': rpm_info, } yum_buff.write(json.dumps(dep_info)) yum_buff.write("\n") sh.append_file(self.yum_satisfies_filename, yum_buff.getvalue()) if not filtered_package_files: LOG.info("No SRPM package dependencies to build.") return for filename in package_files: if filename not in filtered_package_files: sh.unlink(filename) build_requires = six.StringIO() for (filename, req) in package_reqs: if filename in filtered_package_files: build_requires.write("%s # %s\n" % (req, sh.basename(filename))) sh.write_file(self.build_requires_filename, build_requires.getvalue()) # Now build them into SRPM rpm files. package_files = sorted(filtered_package_files) self.py2rpm_helper.build_all_srpms(package_files=package_files, tracewriter=self.tracewriter, jobs=self.jobs)