Skip to content

Commit

Permalink
Revert D67328763: Delete thrift py3 services reflection
Browse files Browse the repository at this point in the history
Differential Revision:
D67328763

Original commit changeset: 332a2d4b8c8c

Original Phabricator Diff: D67328763

fbshipit-source-id: 156592ddc1708b373e9f029c85d03e29ad1e9399
  • Loading branch information
generatedunixname89002005232357 authored and facebook-github-bot committed Dec 19, 2024
1 parent 4c4ad3c commit addb3d0
Show file tree
Hide file tree
Showing 105 changed files with 6,252 additions and 141 deletions.
3 changes: 2 additions & 1 deletion thrift/compiler/generate/t_mstch_py3_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,8 @@ void t_mstch_py3_generator::generate_services() {
std::vector<std::string> cythonFiles{
"clients_wrapper.pxd",
"services_wrapper.pxd",
"services_interface.pxd",
"services_reflection.pxd",
"services_reflection.py",
};

std::vector<std::string> cppFiles{
Expand Down
9 changes: 7 additions & 2 deletions thrift/compiler/generate/templates/py3/clients.pyx.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ import {{#includeNamespace}}{{value}}.{{/includeNamespace}}clients as _{{#includ
{{/hasServices?}}
{{/program:includeNamespaces}}
cimport {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_interface as _fbthrift_services_interface
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_reflection as _services_reflection
cimport {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_reflection as _services_reflection
{{#program:services}}
from {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.clients_wrapper cimport c{{service:name}}AsyncClient, c{{service:name}}ClientWrapper
Expand Down Expand Up @@ -198,10 +199,14 @@ cdef class {{service:name}}({{#service:extends}}{{#service:externalProgram?}}{{!
return self.create{{service:name}}()

{{/service:supportedInteractions}}
@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__{{service:name}}(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.c{{service:cpp_name}}SvIf].gen(response)
ServiceMetadata[_services_reflection.c{{service:cpp_name}}SvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down
9 changes: 7 additions & 2 deletions thrift/compiler/generate/templates/py3/services.pyx.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ cimport {{#includeNamespace}}{{value}}.{{/includeNamespace}}cbindings as _{{#inc
{{/hasTypes?}}
{{/program:includeNamespaces}}
cimport {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_interface as _fbthrift_services_interface
import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_reflection as _services_reflection
cimport {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.services_reflection as _services_reflection
import asyncio
import functools
Expand Down Expand Up @@ -258,10 +259,14 @@ cdef class {{service:name}}Interface(
{{/function:return_type}}
{{/service:supportedFunctions}}

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__{{service:name}}(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.c{{service:cpp_name}}SvIf].gen(response)
ServiceMetadata[_services_reflection.c{{service:cpp_name}}SvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{{!
Copyright (c) Meta Platforms, Inc. and affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
}}{{!
Reflection functions for clients and services
}}
{{> common/auto_generated_py}}

from thrift.py3.reflection import (
ArgumentSpec as __ArgumentSpec,
InterfaceSpec as __InterfaceSpec,
MethodSpec as __MethodSpec,
NumberType as __NumberType,
)

import folly.iobuf as _fbthrift_iobuf

{{#program:includeNamespaces}}
{{#hasTypes?}}
import {{#includeNamespace}}{{value}}.{{/includeNamespace}}types as _{{#includeNamespace}}{{value}}_{{/includeNamespace}}types
{{/hasTypes?}}
{{/program:includeNamespaces}}

import {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types as _{{#program:py3Namespaces}}{{value}}_{{/program:py3Namespaces}}{{program:name}}_types
{{#program:services}}


def get_reflection__{{service:name}}(for_clients: bool):
spec: __InterfaceSpec = __InterfaceSpec(
name="{{service:name}}",
methods=None,
annotations={
{{#service:annotations}}
{{> common/annotation }}
{{/service:annotations}}
},
)
{{#service:supportedFunctions}}
spec.add_method(
__MethodSpec.__new__(
__MethodSpec,
name="{{function:name}}",
arguments=(
{{#function:args}}
__ArgumentSpec.__new__(
__ArgumentSpec,
name="{{field:name}}",
type={{#field:type}}{{> types/python_type}}{{/field:type}},
kind={{#field:type}}{{> types/thrift_number_type}}{{/field:type}},
annotations={
{{#field:annotations}}
{{> common/annotation }}
{{/field:annotations}}
},
),
{{/function:args}}
),
result={{#function:return_type}}{{!
}}{{#type:void?}}{{^function:stream?}}None{{/function:stream?}}{{/type:void?}}{{!
}}{{#function:stream?}}{{!
}}{{> clients/stream_response_class_name}} if for_clients else {{!
}}{{> services/stream_response_class_name}}{{!
}}{{/function:stream?}}{{!
}}{{^type:void?}}{{^function:stream?}}{{> types/python_type}}{{/function:stream?}}{{/type:void?}}{{!
}}{{/function:return_type}},
result_kind={{#function:return_type}}{{!
}}{{^function:stream?}}{{> types/thrift_number_type}}{{/function:stream?}}{{!
}}{{#function:stream?}}__NumberType.NOT_A_NUMBER{{/function:stream?}}{{/function:return_type}},
exceptions=(
{{#function:exceptions}}
{{#field:type}}{{> types/python_type}}{{/field:type}},
{{/function:exceptions}}
),
annotations={
{{#function:annotations}}
{{> common/annotation }}
{{/function:annotations}}
},
)
)
{{/service:supportedFunctions}}
return spec
{{/program:services}}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ cimport module.types as _module_types
cimport module.cbindings as _module_cbindings
import module.types as _module_types

cimport module.services_interface as _fbthrift_services_interface
import module.services_reflection as _services_reflection
cimport module.services_reflection as _services_reflection

from module.clients_wrapper cimport cMyServiceAsyncClient, cMyServiceClientWrapper
from module.clients_wrapper cimport cMyServicePrioParentAsyncClient, cMyServicePrioParentClientWrapper
Expand Down Expand Up @@ -486,10 +487,14 @@ cdef class MyService(thrift.py3.client.Client):
return asyncio_shield(__future)


@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyService(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -563,10 +568,14 @@ cdef class MyServicePrioParent(thrift.py3.client.Client):
return asyncio_shield(__future)


@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyServicePrioParent(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServicePrioParentSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServicePrioParentSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -615,10 +624,14 @@ cdef class MyServicePrioChild(MyServicePrioParent):
return asyncio_shield(__future)


@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyServicePrioChild(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServicePrioChildSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServicePrioChildSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -684,10 +697,14 @@ cdef class BadService(thrift.py3.client.Client):
):
return self.createBadInteraction()

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__BadService(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cGoodServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cGoodServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -809,10 +826,14 @@ cdef class FooBarBazService(thrift.py3.client.Client):
return asyncio_shield(__future)


@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__FooBarBazService(for_clients=True)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cFooBarBazServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cFooBarBazServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ cimport module.types as _module_types
cimport module.cbindings as _module_cbindings
import module.types as _module_types

cimport module.services_interface as _fbthrift_services_interface
import module.services_reflection as _services_reflection
cimport module.services_reflection as _services_reflection

import asyncio
import functools
Expand Down Expand Up @@ -222,10 +223,14 @@ cdef class MyServiceInterface(
self):
raise NotImplementedError("async def doNothing is not implemented")

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyService(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -266,10 +271,14 @@ cdef class MyServicePrioParentInterface(
self):
raise NotImplementedError("async def pong is not implemented")

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyServicePrioParent(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServicePrioParentSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServicePrioParentSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -301,10 +310,14 @@ MyServicePrioParentInterface
self):
raise NotImplementedError("async def pang is not implemented")

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__MyServicePrioChild(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cMyServicePrioChildSvIf].gen(response)
ServiceMetadata[_services_reflection.cMyServicePrioChildSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -336,10 +349,14 @@ cdef class BadServiceInterface(
self):
raise NotImplementedError("async def bar is not implemented")

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__BadService(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cGoodServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cGoodServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down Expand Up @@ -389,10 +406,14 @@ cdef class FooBarBazServiceInterface(
self):
raise NotImplementedError("async def baz is not implemented")

@classmethod
def __get_reflection__(cls):
return _services_reflection.get_reflection__FooBarBazService(for_clients=False)

@staticmethod
def __get_metadata__():
cdef __fbthrift_cThriftServiceMetadataResponse response
ServiceMetadata[_fbthrift_services_interface.cFooBarBazServiceSvIf].gen(response)
ServiceMetadata[_services_reflection.cFooBarBazServiceSvIf].gen(response)
return __MetadataBox.box(cmove(deref(response.metadata_ref())))

@staticmethod
Expand Down
Loading

0 comments on commit addb3d0

Please sign in to comment.