def validate_supported_uri(uri: URI) -> None: if (not is_ipfs_uri(uri) and not is_etherscan_uri(uri) # noqa: W503 and not is_valid_registry_uri(uri) # noqa: W503 and not is_valid_content_addressed_github_uri(uri) # noqa: W503 ): raise UriNotSupportedError( f"Target uri: {uri} not a currently supported uri. " "Target uris must be one of: ipfs, github blob, etherscan, or registry." )
def resolve_sources( package: Package, ipfs_backend: BaseIPFSBackend) -> Iterable[Tuple[str, str]]: for path, source in package.manifest["sources"].items(): if is_ipfs_uri(source): contents = to_text( ipfs_backend.fetch_uri_contents(source)).rstrip("\n") else: # for inlined sources contents = source yield path, contents
def write_docs_to_disk(package: Package, package_dir: Path, ipfs_backend: BaseIPFSBackend) -> None: try: doc_uri = package.manifest["meta"]["links"]["documentation"] except KeyError: return if is_ipfs_uri(doc_uri): documentation = ipfs_backend.fetch_uri_contents(doc_uri) doc_path = package_dir / "documentation.md" doc_path.touch() doc_path.write_bytes(documentation)
def resolve_sources( package: Package, ipfs_backend: BaseIPFSBackend) -> Iterable[Tuple[str, str]]: for path, source_object in package.manifest["sources"].items(): # for inlined sources if "content" in source_object: yield path, source_object["content"] else: ipfs_uri = next( (uri for uri in source_object["urls"] if is_ipfs_uri(uri)), None) if not ipfs_uri: raise InstallError( "Manifest is missing a content-addressed uri.") contents = to_text( ipfs_backend.fetch_uri_contents(ipfs_uri)).rstrip("\n") yield path, contents
def sources(self) -> Iterable[str]: if "sources" not in self.manifest: yield "None.\n" else: for source_id, source_object in self.manifest["sources"].items(): # truncate data if inlined source if "content" in source_object: truncated = ( source_object["content"][:50] .replace("\n", " ") .replace("\r", " ") ) yield f"{source_id}: {truncated}\n" else: all_urls = source_object["urls"] ipfs_url = next((url for url in all_urls if is_ipfs_uri(url)), None) if not ipfs_url: yield f"{source_id}: {source_object['urls'][0]}\n" else: yield f"{source_id}: {ipfs_url}\n"