Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/idl_gen_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,9 @@ class PythonGenerator : public BaseGenerator {
i != std::string::npos; i = directories.find(kPathSeparator, i + 1)) {
const std::string init_py =
directories.substr(0, i) + kPathSeparator + "__init__.py";
parser_.opts.file_saver->SaveFile(init_py.c_str(), "", false);
if (!FileExists(init_py.c_str())) {
parser_.opts.file_saver->SaveFile(init_py.c_str(), "", false);
}
}

const std::string filename = directories + defname;
Expand Down
10 changes: 10 additions & 0 deletions tests/PythonTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ ${test_dir}/../flatc -p -o ${gen_code_path} -I include_test nested_union_test.fb
${test_dir}/../flatc -p -o ${gen_code_path} -I include_test service_test.fbs --grpc --grpc-python-typed-handlers --python-typing --no-python-gen-numpy --gen-onefile
${test_dir}/../flatc -p -o ${gen_code_path} union_name_test.fbs --gen-object-api

# Verify that flatc --python preserves existing __init__.py files (#9229)
mkdir -p ${gen_code_path}/preserve_test
echo "# HANDWRITTEN CONTENT" > ${gen_code_path}/preserve_test/__init__.py
${test_dir}/../flatc -p -o ${gen_code_path}/preserve_test -I include_test monster_test.fbs
if ! grep -q "# HANDWRITTEN CONTENT" ${gen_code_path}/preserve_test/__init__.py; then
echo "FAIL: flatc overwrote existing __init__.py"
exit 1
fi
rm -rf ${gen_code_path}/preserve_test

# Syntax: run_tests <interpreter> <benchmark vtable dedupes>
# <benchmark read count> <benchmark build count>
interpreters_tested=()
Expand Down