def release_package(self, package_name: str, version: str, manifest_uri: str) -> bytes: """ Returns the release id generated by releasing a package on the current registry. Requires ``web3.PM`` to have a registry set. Requires ``web3.eth.defaultAccount`` to be the registry owner. * Parameters: * ``package_name``: Must be a valid package name, matching the given manifest. * ``version``: Must be a valid package version, matching the given manifest. * ``manifest_uri``: Must be a valid content-addressed URI. Currently, only IPFS and Github content-addressed URIs are supported. """ validate_is_supported_manifest_uri(manifest_uri) raw_manifest = to_text(resolve_uri_contents(manifest_uri)) validate_raw_manifest_format(raw_manifest) manifest = json.loads(raw_manifest) validate_manifest_against_schema(manifest) if package_name != manifest['package_name']: raise ManifestValidationError( f"Provided package name: {package_name} does not match the package name " f"found in the manifest: {manifest['package_name']}.") if version != manifest['version']: raise ManifestValidationError( f"Provided package version: {version} does not match the package version " f"found in the manifest: {manifest['version']}.") self._validate_set_registry() return self.registry._release(package_name, version, manifest_uri)
def from_uri(cls, uri: str, w3: Web3) -> "Package": """ Return a Package object instantiated by a manifest located at a content-addressed URI. URI schemes supported: - IPFS `ipfs://Qm...` - HTTP `https://raw.githubusercontent.com/repo/path.json#hash` - Registry `ercXXX://registry.eth/greeter?version=1.0.0` """ contents = resolve_uri_contents(uri) manifest = json.loads(to_text(contents)) return cls(manifest, w3)
def from_uri(cls, uri: str, w3: Web3) -> "Package": """ Returns a Package object instantiated by a manifest located at a content-addressed URI. A valid ``Web3`` instance is also required. URI schemes supported: - IPFS `ipfs://Qm...` - HTTP `https://api.github.com/repos/:owner/:repo/git/blobs/:file_sha` - Registry `ercXXX://registry.eth/greeter?version=1.0.0` .. code:: python OwnedPackage = Package.from_uri('ipfs://QmbeVyFLSuEUxiXKwSsEjef7icpdTdA4kGG9BcrJXKNKUW', w3) # noqa: E501 """ contents = to_text(resolve_uri_contents(uri)) validate_raw_manifest_format(contents) manifest = json.loads(contents) return cls(manifest, w3, uri)
def test_resolve_uri_contents_raises_exception_for_unsupported_schemes(uri): with pytest.raises(CannotHandleURI): resolve_uri_contents(uri)