Skip to content

Commit

Permalink
Add a py3-cbindings target which will eventually hold the imported c …
Browse files Browse the repository at this point in the history
…types used in thrift py3

Summary:
This diff adds a `cbindings.pxd` and a `py3-cbindings` target to hold it, which for now just re-exports everything defined in types.pxd, but will later hold just the [c bindings](https://www.internalfb.com/code/fbsource/[320dcea0bcbd8d29b2e978c21018d5ded6c7848d]/fbcode/thrift/compiler/generate/templates/py3/types.pxd.mustache?lines=19-35) thrift py3 uses.

This is part of a migration to split out the c bindings out of `types.pxd` for the thrift python auto migrate project.

1: all cython_library targets will be codemodded to add a `py3-cbindings` dependency for each `py3-types` dependency they have
2: All cython `from .*types cimport` lines will be changed to `from .*cbindings cimport`
3: The c bindings will be split out of `types.pxd`, and `types.pxd` will be changed to depend on `cbindings.pxd`, removing the c++ dependency on python libraries import py3, when running in auto migrate mode.

Reviewed By: ahilger

Differential Revision: D64352295

fbshipit-source-id: 7aa76ee132066374c830a87d30204f568fd965da
  • Loading branch information
Filip Francetic authored and facebook-github-bot committed Oct 18, 2024
1 parent 0b657c9 commit 5a9787d
Show file tree
Hide file tree
Showing 69 changed files with 970 additions and 0 deletions.
1 change: 1 addition & 0 deletions thrift/compiler/generate/t_mstch_py3_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,7 @@ void t_mstch_py3_generator::generate_types() {
std::vector<std::string> cythonFilesWithTypeContext{
"types.pyx",
"types.pxd",
"cbindings.pxd",
"types.pyi",
};

Expand Down
26 changes: 26 additions & 0 deletions thrift/compiler/generate/templates/py3/cbindings.pxd.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{!
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.
}}
{{> common/auto_generated_py}}
from {{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types cimport (
{{#program:enums}}c{{enum:name}},
{{/program:enums}}{{!
}}{{#program:filtered_structs}}c{{struct:name}},
{{/program:filtered_structs}}{{!
}}{{#program:constants}}c{{constant:name}},
{{/program:constants}}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/basic-annotations/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cMyEnum,
cMyStructNestedAnnotation,
cSecretStruct,
cmyStruct,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/basic-enum/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from test.fixtures.enumstrict.module.types cimport (
cEmptyEnum,
cMyEnum,
cMyUseIntrinsicDefaultEnum,
cMyBigEnum,
cMyStruct,
ckOne,
cenumNames,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/basic-stack-arguments/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cMyEnum,
cMyStruct,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/basic/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from test.fixtures.basic.module.types cimport (
cMyEnum,
cHackEnum,
cMyStruct,
cContainers,
cMyDataItem,
cMyUnion,
cMyException,
cMyExceptionWithMessage,
cReservedKeyword,
cUnionToBeRenamed,
cFLAG,
cOFFSET,
cCOUNT,
cMASK,
cE,
cDATE,
cAList,
cASet,
cAMap,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/complex-union/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cComplexUnion,
cListUnion,
cDataUnion,
cVal,
cValUnion,
cVirtualComplexUnion,
cNonCopyableStruct,
cNonCopyableUnion,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/constants/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cEmptyEnum,
cCity,
cCompany,
cInternship,
cRange,
cstruct1,
cstruct2,
cstruct3,
cstruct4,
cunion1,
cunion2,
cmyInt,
cname,
cmulti_line_string,
cstates,
cx,
cy,
cz,
czeroDoubleValue,
clongDoubleValue,
cbin,
cmy_company,
cfoo,
cbar,
cmymap,
cinstagram,
cpartial_const,
ckRanges,
cinternList,
cpod_0,
cpod_s_0,
cpod_1,
cpod_s_1,
cpod_2,
cpod_trailing_commas,
cpod_s_2,
cpod_3,
cpod_s_3,
cpod_4,
cu_1_1,
cu_1_2,
cu_1_3,
cu_2_1,
cu_2_2,
cu_2_3,
cu_2_4,
cu_2_5,
cu_2_6,
capostrophe,
ctripleApostrophe,
cquotationMark,
cbackslash,
cescaped_a,
cchar2ascii,
cescaped_strings,
cfalse_c,
ctrue_c,
czero_byte,
czero16,
czero32,
czero64,
czero_dot_zero,
cempty_string,
cempty_int_list,
cempty_string_list,
cempty_int_set,
cempty_string_set,
cempty_int_int_map,
cempty_int_string_map,
cempty_string_int_map,
cempty_string_string_map,
cmaxIntDec,
cmaxIntOct,
cmaxIntHex,
cmaxIntBin,
cmaxDub,
cminDub,
cminSDub,
cmaxPIntDec,
cmaxPIntOct,
cmaxPIntHex,
cmaxPIntBin,
cmaxPDub,
cminPDub,
cminPSDub,
cminIntDec,
cminIntOct,
cminIntHex,
cminIntBin,
cmaxNDub,
cminNDub,
cminNSDub,
cI2B,
cI2B_REF,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/empty-struct/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cEmpty,
cNada,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/enums/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from test.fixtures.enums.module.types cimport (
cMetasyntactic,
cMyEnum1,
cMyEnum2,
cMyEnum3,
cMyEnum4,
cMyBitmaskEnum1,
cMyBitmaskEnum2,
cSomeStruct,
cMyStruct,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/exceptions/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cFiery,
cSerious,
cComplexFieldNames,
cCustomFieldNames,
cExceptionWithPrimitiveField,
cExceptionWithStructuredAnnotation,
cBanal,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Autogenerated by Thrift for includes.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from includes.types cimport (
cIncluded,
cExampleIncluded,
cIncludedConstant,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/includes/src/module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cMyStruct,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for transitive.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from transitive.types cimport (
cFoo,
cExampleFoo,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/includes/src/includes.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from includes.types cimport (
cIncluded,
cExampleIncluded,
cIncludedConstant,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for transitive.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from transitive.types cimport (
cFoo,
cExampleFoo,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Autogenerated by Thrift for includes.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from includes.types cimport (
cIncluded,
cExampleIncluded,
cIncludedConstant,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# Autogenerated by Thrift for module.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from module.types cimport (
cMyStruct,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/includes/src/service.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from service.types cimport (
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for transitive.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from transitive.types cimport (
cFoo,
cExampleFoo,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/includes/src/transitive.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from transitive.types cimport (
cFoo,
cExampleFoo,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Autogenerated by Thrift for includes.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from includes.types cimport (
cIncluded,
cExampleIncluded,
cIncludedConstant,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Autogenerated by Thrift for thrift/compiler/test/fixtures/includes/src/matching_struct_names.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
# @generated
#
from matching_struct_names.types cimport (
cMyStruct,
cCombo,
)
Loading

0 comments on commit 5a9787d

Please sign in to comment.