def _build_one_inside_env( self, req, # type: InstallRequirement output_dir, # type: str python_tag=None, # type: Optional[str] ): # type: (...) -> Optional[str] with TempDirectory(kind="wheel") as temp_dir: if req.use_pep517: builder = self._build_one_pep517 else: builder = self._build_one_legacy wheel_path = builder(req, temp_dir.path, python_tag=python_tag) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: wheel_hash, length = hash_file(wheel_path) shutil.move(wheel_path, dest_path) logger.info( 'Created wheel for %s: ' 'filename=%s size=%d sha256=%s', req.name, wheel_name, length, wheel_hash.hexdigest()) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception: pass # Ignore return, we can't do anything else useful. self._clean_one(req) return None
def rehash(path, blocksize=1 << 20): # type: (str, int) -> Tuple[str, str] """Return (encoded_digest, length) for path using hashlib.sha256()""" h, length = hash_file(path, blocksize) digest = 'sha256=' + urlsafe_b64encode( h.digest()).decode('latin1').rstrip('=') return (digest, str(length))
def rehash(path, blocksize=1 << 20): # type: (str, int) -> Tuple[str, str] """Return (encoded_digest, length) for path using hashlib.sha256()""" h, length = hash_file(path, blocksize) digest = "sha256=" + urlsafe_b64encode( h.digest()).decode("latin1").rstrip("=") # unicode/str python2 issues return (digest, str(length)) # type: ignore
def _build_one_inside_env( req, # type: InstallRequirement output_dir, # type: str build_options, # type: List[str] global_options, # type: List[str] ): # type: (...) -> Optional[str] with TempDirectory(kind="wheel") as temp_dir: assert req.name if req.use_pep517: assert req.metadata_directory assert req.pep517_backend if global_options: logger.warning( 'Ignoring --global-option when building %s using PEP 517', req.name) if build_options: logger.warning( 'Ignoring --build-option when building %s using PEP 517', req.name) wheel_path = build_wheel_pep517( name=req.name, backend=req.pep517_backend, metadata_directory=req.metadata_directory, tempd=temp_dir.path, ) else: wheel_path = build_wheel_legacy( name=req.name, setup_py_path=req.setup_py_path, source_dir=req.unpacked_source_directory, global_options=global_options, build_options=build_options, tempd=temp_dir.path, ) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: wheel_hash, length = hash_file(wheel_path) shutil.move(wheel_path, dest_path) logger.info( 'Created wheel for %s: ' 'filename=%s size=%d sha256=%s', req.name, wheel_name, length, wheel_hash.hexdigest()) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception as e: logger.warning( "Building wheel for %s failed: %s", req.name, e, ) # Ignore return, we can't do anything else useful. if not req.use_pep517: _clean_one_legacy(req, global_options) return None
def _prepare_linked_requirement(self, req: InstallRequirement, parallel_builds: bool) -> BaseDistribution: assert req.link link = req.link self._ensure_link_req_src_dir(req, parallel_builds) hashes = self._get_linked_req_hashes(req) if link.is_existing_dir(): local_file = None elif link.url not in self._downloaded: try: local_file = unpack_url( link, req.source_dir, self._download, self.verbosity, self.download_dir, hashes, ) except NetworkConnectionError as exc: raise InstallationError( "Could not install requirement {} because of HTTP " "error {} for URL {}".format(req, exc, link)) else: file_path = self._downloaded[link.url] if hashes: hashes.check_against_path(file_path) local_file = File(file_path, content_type=None) # If download_info is set, we got it from the wheel cache. if req.download_info is None: # Editables don't go through this function (see # prepare_editable_requirement). assert not req.editable req.download_info = direct_url_from_link(link, req.source_dir) # Make sure we have a hash in download_info. If we got it as part of the # URL, it will have been verified and we can rely on it. Otherwise we # compute it from the downloaded file. if (isinstance(req.download_info.info, ArchiveInfo) and not req.download_info.info.hash and local_file): hash = hash_file(local_file.path)[0].hexdigest() req.download_info.info.hash = f"sha256={hash}" # For use in later processing, # preserve the file path on the requirement. if local_file: req.local_file_path = local_file.path dist = _get_prepared_distribution( req, self.build_tracker, self.finder, self.build_isolation, self.check_build_deps, ) return dist
def test_hash_file(self, tmpdir): self.prep(tmpdir) h, length = hash_file(self.test_file) assert length == self.test_file_len assert h.hexdigest() == self.test_file_hash
) else: wheel_path = build_wheel_legacy( name=req.name, setup_py_path=req.setup_py_path, source_dir=req.unpacked_source_directory, global_options=global_options, build_options=build_options, tempd=temp_dir.path, ) if wheel_path is not None: wheel_name = os.path.basename(wheel_path) dest_path = os.path.join(output_dir, wheel_name) try: wheel_hash, length = hash_file(wheel_path) shutil.move(wheel_path, dest_path) logger.info('Created wheel for %s: ' 'filename=%s size=%d sha256=%s', req.name, wheel_name, length, wheel_hash.hexdigest()) logger.info('Stored in directory: %s', output_dir) return dest_path except Exception as e: logger.warning( "Building wheel for %s failed: %s", req.name, e, ) # Ignore return, we can't do anything else useful. if not req.use_pep517: _clean_one_legacy(req, global_options)
InstalledCSVRow = Tuple[str, ...] logger = logging.getLogger(__name__) def normpath(src, p): # type: (str, str) -> str return os.path.relpath(src, p).replace(os.path.sep, '/') def rehash(path, blocksize=1 << 20): # type: (str, int) -> Tuple[str, str] >>>>>>> b66a76afa15ab74019740676a52a071b85ed8f71 """Return (encoded_digest, length) for path using hashlib.sha256()""" h, length = hash_file(path, blocksize) digest = 'sha256=' + urlsafe_b64encode( h.digest() ).decode('latin1').rstrip('=') # unicode/str python2 issues return (digest, str(length)) # type: ignore def csv_io_kwargs(mode): # type: (str) -> Dict[str, Any] """Return keyword arguments to properly open a CSV file in the given mode. """ <<<<<<< HEAD if PY2: return {'mode': '{}b'.format(mode)}
def test_hash_file(self, tmpdir: Path) -> None: self.prep(tmpdir) h, length = hash_file(os.fspath(self.test_file)) assert length == self.test_file_len assert h.hexdigest() == self.test_file_hash
def rehash(path: str, blocksize: int = 1 << 20) -> Tuple[str, str]: """Return (encoded_digest, length) for path using hashlib.sha256()""" h, length = hash_file(path, blocksize) digest = "sha256=" + urlsafe_b64encode( h.digest()).decode("latin1").rstrip("=") return (digest, str(length))