Skip to content

Commit

Permalink
Support include file
Browse files Browse the repository at this point in the history
Summary:
The existing implementation doesn't support including another thrift file. This diff fixed it.

The main change of this diff is in

```
tools/build_defs/fbcode_macros/build_defs/lib/thrift/patch.bzl
```

However, after this diff, we will need to enable `python_patch` for all included files, thus we have to enable it for all annotations.

In the future we could potentially create `no_languages_deps` (similar to `no_plugin_deps` to improve the ergonomic).

Reviewed By: thedavekwon

Differential Revision: D64764838

fbshipit-source-id: 373539f6c4d1184ae2b2a1caacc2ec8717d6cfcc
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Oct 25, 2024
1 parent 288dfaa commit f9ff628
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
}}MapPatch({{> common/thrift_patch_callback}}, patch.as_map_patch(), type_info){{!
}}{{/type:value_type}}{{/type:map?}}{{!
}}{{#type:struct}}{{!
}}{{type:patch_module_path}}.{{struct:py_name}}Patch(patch){{!
}}{{#type:need_patch_module_path?}}{{type:patch_module_path}}.{{/type:need_patch_module_path?}}{{struct:py_name}}Patch(patch){{!
}}{{/type:struct}}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}}
# @{{!}}generated
from __future__ import annotations

import typing
import typing as _typing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ This is for pep 484 typing for thrift patch types
}}{{#type:float?}}FloatPatch{{/type:float?}}{{!
}}{{#type:string?}}StringPatch{{/type:string?}}{{!
}}{{#type:binary?}}BinaryPatch{{/type:binary?}}{{!
}}{{#type:struct}}{{struct:py_name}}Patch{{/type:struct}}{{!
}}{{#type:struct}}{{!
}}{{#type:need_patch_module_path?}}{{type:patch_module_path}}.{{/type:need_patch_module_path?}}{{!
}}{{struct:py_name}}Patch{{!
}}{{/type:struct}}{{!
}}{{#type:list?}}ListPatch[{{!
}}{{#type:list_elem_type}}{{> types/unadapted_pep484_type}}{{/type:list_elem_type}}{{!
}}]{{/type:list?}}{{!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# @generated
from __future__ import annotations

import typing
import typing as _typing
Expand Down Expand Up @@ -59,7 +60,7 @@ def MyDataField(self) -> OptionalFieldPatch[
MyDataItemPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyDataItemPatch(patch),
lambda patch, type_info: MyDataItemPatch(patch),
self._patch,
3,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyDataItem))
Expand Down Expand Up @@ -181,7 +182,7 @@ def myStruct(self) -> OptionalFieldPatch[
MyStructPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyStructPatch(patch),
lambda patch, type_info: MyStructPatch(patch),
self._patch,
2,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyStruct))
Expand All @@ -191,7 +192,7 @@ def myDataItem(self) -> OptionalFieldPatch[
MyDataItemPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyDataItemPatch(patch),
lambda patch, type_info: MyDataItemPatch(patch),
self._patch,
3,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyDataItem))
Expand Down Expand Up @@ -235,7 +236,7 @@ def myStruct(self) -> OptionalFieldPatch[
MyStructPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyStructPatch(patch),
lambda patch, type_info: MyStructPatch(patch),
self._patch,
3,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyStruct))
Expand All @@ -245,7 +246,7 @@ def myUnion(self) -> OptionalFieldPatch[
MyUnionPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyUnionPatch(patch),
lambda patch, type_info: MyUnionPatch(patch),
self._patch,
4,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyUnion))
Expand Down Expand Up @@ -279,7 +280,7 @@ def myStruct(self) -> OptionalFieldPatch[
MyStructPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyStructPatch(patch),
lambda patch, type_info: MyStructPatch(patch),
self._patch,
3,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyStruct))
Expand All @@ -289,7 +290,7 @@ def myUnion(self) -> OptionalFieldPatch[
MyUnionPatch]:

return OptionalFieldPatch(
lambda patch, type_info: test.fixtures.basic.module.thrift_patch.MyUnionPatch(patch),
lambda patch, type_info: MyUnionPatch(patch),
self._patch,
4,
_fbthrift_python_types.StructTypeInfo(test.fixtures.basic.module.thrift_types.MyUnion))
Expand Down

0 comments on commit f9ff628

Please sign in to comment.