2024-05-29 12:47:29 -07:00
|
|
|
#ifndef FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|
|
|
|
|
#define FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2024-06-18 16:02:57 -07:00
|
|
|
#include "codegen/namer.h"
|
|
|
|
|
|
2024-05-29 12:47:29 -07:00
|
|
|
namespace flatbuffers {
|
|
|
|
|
namespace python {
|
2024-06-18 16:02:57 -07:00
|
|
|
static const Namer::Config kConfig = {
|
|
|
|
|
/*types=*/Case::kKeep,
|
|
|
|
|
/*constants=*/Case::kScreamingSnake,
|
|
|
|
|
/*methods=*/Case::kUpperCamel,
|
|
|
|
|
/*functions=*/Case::kUpperCamel,
|
|
|
|
|
/*fields=*/Case::kLowerCamel,
|
|
|
|
|
/*variable=*/Case::kLowerCamel,
|
|
|
|
|
/*variants=*/Case::kKeep,
|
|
|
|
|
/*enum_variant_seperator=*/".",
|
|
|
|
|
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
|
|
|
|
|
/*namespaces=*/Case::kKeep, // Packages in python.
|
|
|
|
|
/*namespace_seperator=*/".",
|
|
|
|
|
/*object_prefix=*/"",
|
|
|
|
|
/*object_suffix=*/"T",
|
|
|
|
|
/*keyword_prefix=*/"",
|
|
|
|
|
/*keyword_suffix=*/"_",
|
2026-01-21 02:06:07 +02:00
|
|
|
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
|
2024-06-18 16:02:57 -07:00
|
|
|
/*filenames=*/Case::kKeep,
|
|
|
|
|
/*directories=*/Case::kKeep,
|
|
|
|
|
/*output_path=*/"",
|
|
|
|
|
/*filename_suffix=*/"",
|
|
|
|
|
/*filename_extension=*/".py",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const Namer::Config kStubConfig = {
|
|
|
|
|
/*types=*/Case::kKeep,
|
|
|
|
|
/*constants=*/Case::kScreamingSnake,
|
|
|
|
|
/*methods=*/Case::kUpperCamel,
|
|
|
|
|
/*functions=*/Case::kUpperCamel,
|
|
|
|
|
/*fields=*/Case::kLowerCamel,
|
|
|
|
|
/*variables=*/Case::kLowerCamel,
|
|
|
|
|
/*variants=*/Case::kKeep,
|
|
|
|
|
/*enum_variant_seperator=*/".",
|
|
|
|
|
/*escape_keywords=*/Namer::Config::Escape::AfterConvertingCase,
|
|
|
|
|
/*namespaces=*/Case::kKeep, // Packages in python.
|
|
|
|
|
/*namespace_seperator=*/".",
|
|
|
|
|
/*object_prefix=*/"",
|
|
|
|
|
/*object_suffix=*/"T",
|
|
|
|
|
/*keyword_prefix=*/"",
|
|
|
|
|
/*keyword_suffix=*/"_",
|
2026-01-21 02:06:07 +02:00
|
|
|
/*keywords_casing=*/Namer::Config::KeywordsCasing::CaseSensitive,
|
2024-06-18 16:02:57 -07:00
|
|
|
/*filenames=*/Case::kKeep,
|
|
|
|
|
/*directories=*/Case::kKeep,
|
|
|
|
|
/*output_path=*/"",
|
|
|
|
|
/*filename_suffix=*/"",
|
|
|
|
|
/*filename_extension=*/".pyi",
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-29 12:47:29 -07:00
|
|
|
// `Version` represent a Python version.
|
|
|
|
|
//
|
|
|
|
|
// The zero value (i.e. `Version{}`) represents both Python2 and Python3.
|
|
|
|
|
//
|
|
|
|
|
// https://docs.python.org/3/faq/general.html#how-does-the-python-version-numbering-scheme-work
|
|
|
|
|
struct Version {
|
2025-09-23 21:50:27 -07:00
|
|
|
explicit Version(const std::string& version);
|
2024-05-29 12:47:29 -07:00
|
|
|
|
|
|
|
|
bool IsValid() const;
|
|
|
|
|
|
|
|
|
|
int16_t major = 0;
|
|
|
|
|
int16_t minor = 0;
|
|
|
|
|
int16_t micro = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-23 21:50:27 -07:00
|
|
|
std::set<std::string> Keywords(const Version& version);
|
2024-05-29 12:47:29 -07:00
|
|
|
|
|
|
|
|
struct Import {
|
|
|
|
|
bool IsLocal() const { return module == "."; }
|
|
|
|
|
|
|
|
|
|
std::string module;
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Imports {
|
2025-09-23 21:50:27 -07:00
|
|
|
const python::Import& Import(const std::string& module);
|
|
|
|
|
const python::Import& Import(const std::string& module,
|
|
|
|
|
const std::string& name);
|
2024-05-29 12:47:29 -07:00
|
|
|
|
2025-09-23 21:50:27 -07:00
|
|
|
const python::Import& Export(const std::string& module);
|
|
|
|
|
const python::Import& Export(const std::string& module,
|
|
|
|
|
const std::string& name);
|
2025-07-15 20:20:09 +02:00
|
|
|
|
2024-05-29 12:47:29 -07:00
|
|
|
std::vector<python::Import> imports;
|
2025-07-15 20:20:09 +02:00
|
|
|
std::vector<python::Import> exports;
|
2024-05-29 12:47:29 -07:00
|
|
|
};
|
|
|
|
|
} // namespace python
|
|
|
|
|
} // namespace flatbuffers
|
|
|
|
|
|
|
|
|
|
#endif // FLATBUFFERS_INCLUDE_CODEGEN_PYTHON_H_
|