|
@@ -67,12 +67,22 @@ DOCS_DIR = pathlib.Path(__file__).parent.resolve()
|
|
PYTHON_DIR = DOCS_DIR.parent
|
|
PYTHON_DIR = DOCS_DIR.parent
|
|
SOURCE_DIR = PYTHON_DIR / "google" / "protobuf"
|
|
SOURCE_DIR = PYTHON_DIR / "google" / "protobuf"
|
|
SOURCE_POSIX = SOURCE_DIR.as_posix()
|
|
SOURCE_POSIX = SOURCE_DIR.as_posix()
|
|
|
|
+
|
|
|
|
+# Modules which are always included:
|
|
|
|
+INCLUDED_MODULES = (
|
|
|
|
+ "google.protobuf.internal.containers",
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+# Packages to ignore, including all modules (unless in INCLUDED_MODULES):
|
|
IGNORED_PACKAGES = (
|
|
IGNORED_PACKAGES = (
|
|
"compiler",
|
|
"compiler",
|
|
|
|
+ "docs",
|
|
"internal",
|
|
"internal",
|
|
"pyext",
|
|
"pyext",
|
|
"util",
|
|
"util",
|
|
)
|
|
)
|
|
|
|
+
|
|
|
|
+# Ignored module stems in all packages (unless in INCLUDED_MODULES):
|
|
IGNORED_MODULES = (
|
|
IGNORED_MODULES = (
|
|
"any_test_pb2",
|
|
"any_test_pb2",
|
|
"api_pb2",
|
|
"api_pb2",
|
|
@@ -81,6 +91,7 @@ IGNORED_MODULES = (
|
|
"test_messages_proto3_pb2",
|
|
"test_messages_proto3_pb2",
|
|
"test_messages_proto2",
|
|
"test_messages_proto2",
|
|
)
|
|
)
|
|
|
|
+
|
|
TOC_REGEX = re.compile(
|
|
TOC_REGEX = re.compile(
|
|
r"\.\. START REFTOC.*\.\. END REFTOC\.\n",
|
|
r"\.\. START REFTOC.*\.\. END REFTOC\.\n",
|
|
flags=re.DOTALL,
|
|
flags=re.DOTALL,
|
|
@@ -120,20 +131,28 @@ AUTOMODULE_TEMPLATE = """.. DO NOT EDIT, generated by generate_docs.py.
|
|
def find_modules():
|
|
def find_modules():
|
|
modules = []
|
|
modules = []
|
|
for module_path in SOURCE_DIR.glob("**/*.py"):
|
|
for module_path in SOURCE_DIR.glob("**/*.py"):
|
|
- package_posix = module_path.parent.as_posix()
|
|
|
|
- if any(ignored in package_posix for ignored in IGNORED_PACKAGES):
|
|
|
|
|
|
+ # Determine the (dotted) relative package and module names.
|
|
|
|
+ package_path = module_path.parent.relative_to(PYTHON_DIR)
|
|
|
|
+ if package_path == SOURCE_DIR:
|
|
|
|
+ package_name = ""
|
|
|
|
+ module_name = module_path.stem
|
|
|
|
+ else:
|
|
|
|
+ package_name = package_path.as_posix().replace("/", ".")
|
|
|
|
+ module_name = package_name + "." + module_path.stem
|
|
|
|
+
|
|
|
|
+ # Filter: first, accept anything in the whitelist; then, reject anything
|
|
|
|
+ # at package level, then module name level.
|
|
|
|
+ if any(include == module_name for include in INCLUDED_MODULES):
|
|
|
|
+ pass
|
|
|
|
+ elif any(ignored in package_name for ignored in IGNORED_PACKAGES):
|
|
continue
|
|
continue
|
|
- if any(ignored in module_path.stem for ignored in IGNORED_MODULES):
|
|
|
|
|
|
+ elif any(ignored in module_path.stem for ignored in IGNORED_MODULES):
|
|
continue
|
|
continue
|
|
|
|
|
|
- package_name = "google.protobuf{}".format(
|
|
|
|
- package_posix[len(SOURCE_POSIX) :].replace("/", ".")
|
|
|
|
- )
|
|
|
|
if module_path.name == "__init__.py":
|
|
if module_path.name == "__init__.py":
|
|
modules.append(package_name)
|
|
modules.append(package_name)
|
|
else:
|
|
else:
|
|
- module_name = module_path.stem
|
|
|
|
- modules.append("{}.{}".format(package_name, module_name))
|
|
|
|
|
|
+ modules.append(module_name)
|
|
|
|
|
|
return modules
|
|
return modules
|
|
|
|
|