diff --git a/sdk/python/lib/pulumi/remote/__init__.py b/sdk/python/lib/pulumi/remote/__init__.py index 5d68ca516..01e424e80 100644 --- a/sdk/python/lib/pulumi/remote/__init__.py +++ b/sdk/python/lib/pulumi/remote/__init__.py @@ -18,4 +18,4 @@ The remote proxy implementation of the Pulumi Python SDK. from .remote import ( ProxyComponentResource, -) \ No newline at end of file +) diff --git a/sdk/python/lib/pulumi/remote/remote.py b/sdk/python/lib/pulumi/remote/remote.py index 2aed4f02b..735a7095c 100644 --- a/sdk/python/lib/pulumi/remote/remote.py +++ b/sdk/python/lib/pulumi/remote/remote.py @@ -12,20 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +import asyncio +import os +from subprocess import Popen +import time +from typing import Callable, Any, Dict, List, Optional +import grpc from .. import ComponentResource, CustomResource, Output, InvokeOptions, ResourceOptions, log, Input, Inputs, Resource from ..runtime.proto import runtime_pb2, runtime_pb2_grpc from ..runtime.rpc import deserialize_properties, serialize_properties from ..runtime.settings import SETTINGS -import asyncio -import grpc -import os -from subprocess import Popen -import time -from typing import Callable, Any, Dict, List, Optional - def spawnServer(library_path: str): - p = Popen(["node", "-e", "require('@pulumi/pulumi/remote/server')"], cwd=library_path, env={ + Popen(["node", "-e", "require('@pulumi/pulumi/remote/server')"], cwd=library_path, env={ **os.environ, 'PULUMI_NODEJS_PROJECT': SETTINGS.project, 'PULUMI_NODEJS_STACK': SETTINGS.stack, @@ -58,11 +57,11 @@ def get_server(library_path: str) -> runtime_pb2_grpc.RuntimeStub: # return d async def construct( - libraryPath: str, - resource: str, - name: str, - args: Any, - opts: ResourceOptions) -> Any: + libraryPath: str, + resource: str, + name: str, + args: Any, + _opts: ResourceOptions) -> Any: property_dependencies_resources: Dict[str, List[Resource]] = {} args_struct = await serialize_properties(args, property_dependencies_resources) # TODO - support opts serialization @@ -82,14 +81,14 @@ class ProxyComponentResource(ComponentResource): """ Abstract base class for proxies around component resources. """ - def __init__(__self__, + def __init__(self, t: str, name: str, library_path: str, library_name: str, inputs: Inputs, outputs: Dict[str, None], - opts: Optional[ResourceOptions]=None) -> None: + opts: Optional[ResourceOptions] = None) -> None: if opts is None or opts.urn is None: async def do_construct(): r = await construct(library_path, library_name, name, inputs, opts) diff --git a/sdk/python/lib/pulumi/runtime/resource.py b/sdk/python/lib/pulumi/runtime/resource.py index dd7f316ca..743fa96ee 100644 --- a/sdk/python/lib/pulumi/runtime/resource.py +++ b/sdk/python/lib/pulumi/runtime/resource.py @@ -293,7 +293,6 @@ def _get_resource(res: 'Resource', ty: str, name: str, custom: bool, props: 'Inp "Cannot get resource whose options are lacking a URN value") log.debug(f"registering resource: ty={ty}, name={name}, custom={custom}") - monitor = settings.get_monitor() # Prepare the resource. @@ -340,7 +339,7 @@ def _get_resource(res: 'Resource', ty: str, name: str, custom: bool, props: 'Inp async def do_get(): try: log.debug(f"preparing get: ty={ty}, name={name}, urn={urn}") - resolver = await prepare_resource(res, ty, custom, props, opts) + _ = await prepare_resource(res, ty, custom, props, opts) # Resolve the URN that we were given. Note that we are explicitly discarding the list of # dependencies returned to us from "serialize_property" (the second argument). This is @@ -349,8 +348,8 @@ def _get_resource(res: 'Resource', ty: str, name: str, custom: bool, props: 'Inp # dependency. TODO: This this actually true for "get"? resolved_urn = await rpc.serialize_property(urn, []) log.debug(f"get prepared: ty={ty}, name={name}, urn={urn}") - resp = await invoke("pulumi:pulumi:readStackResource", { "urn": resolved_urn }) - + resp = await invoke("pulumi:pulumi:readStackResource", {"urn": resolved_urn}) + except Exception as exn: log.debug( f"exception when preparing or executing rpc: {traceback.format_exc()}") @@ -364,7 +363,7 @@ def _get_resource(res: 'Resource', ty: str, name: str, custom: bool, props: 'Inp resolve_urn(resp["urn"]) if custom: resolve_id(resp["outputs"]["id"], True, None) # Get IDs are always known. - await rpc.resolve_properties(res, resolvers, resp["outputs"]) + await rpc.resolve_properties(resolvers, resp["outputs"]) asyncio.ensure_future(RPC_MANAGER.do_rpc("get resource", do_get)()) diff --git a/sdk/python/lib/pulumi/runtime/rpc.py b/sdk/python/lib/pulumi/runtime/rpc.py index 1d984a44e..ef6816336 100644 --- a/sdk/python/lib/pulumi/runtime/rpc.py +++ b/sdk/python/lib/pulumi/runtime/rpc.py @@ -250,7 +250,7 @@ def deserialize_properties(props_struct: struct_pb2.Struct, keep_unknowns: Optio proxy_constructor = PROXY_CONSTRUCTORS.get(typ, None) if proxy_constructor is not None: urn_name = urn_parts[3] - return proxy_constructor(urn_name, { 'urn': urn }) + return proxy_constructor(urn_name, {"urn": urn}) print(f"Saw valid URN {urn} during deserialization, but no proxy constructor is registered for type {typ}.") return urn @@ -441,9 +441,9 @@ async def resolve_outputs(res: 'Resource', # the user. all_properties[translated_key] = translate_output_properties(res, deserialize_property(value)) - await resolve_properties(res, resolvers, all_properties) + await resolve_properties(resolvers, all_properties) -async def resolve_properties(res: 'Resource', resolvers: Dict[str, Resolver], all_properties:Dict[str, Any]): +async def resolve_properties(resolvers: Dict[str, Resolver], all_properties: Dict[str, Any]): for key, value in all_properties.items(): # Skip "id" and "urn", since we handle those specially.