From 35a2bf9d90662e984780574f3f893cfaf68be501 Mon Sep 17 00:00:00 2001 From: Tim Swast Date: Thu, 15 Aug 2019 16:22:02 -0700 Subject: [PATCH] python: publish sphinx docs to read the docs Background: This is a follow-up to the PR that adds sphinx docs. Read the Docs is a hosting platform for documentation, primarily Python docs. It supports builds at commit time as well as at specific git labels to support versioned docs. I have claimed the protobuf.readthedocs.io project and can add any Googlers who need access to be able to configure and trigger builds. https://readthedocs.org/projects/protobuf/builds/ It's also relatively easy to create a new project to test the documentation builds from a fork, such as https://readthedocs.org/projects/tswast-protobuf/builds/ About this change: Once web hooks are configured, Read the Docs will automatically build the docs for the latest changes on the master branch. I needed to update `python/setup.py` to support installation from the root of the repository because Read the Docs does not `cd python` before installing the protobuf package with `setup.py install`. To support this, I updated the file paths to use the absolute path to files. The `__file__` special variable comes in handy for this, as it provides the path to the `setup.py` file. A banner is added to the docs when published to readthedocs. This links to the official documentation and the future home of the stable API reference on googleapis.dev. --- .readthedocs.yml | 22 ++++++++ python/docs/conf.py | 17 ++++++- python/docs/generate_docs.py | 12 +++++ python/docs/google/protobuf.rst | 12 +++++ python/docs/google/protobuf/any_pb2.rst | 12 +++++ python/docs/google/protobuf/descriptor.rst | 12 +++++ .../google/protobuf/descriptor_database.rst | 12 +++++ .../docs/google/protobuf/descriptor_pb2.rst | 12 +++++ .../docs/google/protobuf/descriptor_pool.rst | 12 +++++ python/docs/google/protobuf/duration_pb2.rst | 12 +++++ python/docs/google/protobuf/empty_pb2.rst | 12 +++++ .../docs/google/protobuf/field_mask_pb2.rst | 12 +++++ python/docs/google/protobuf/json_format.rst | 12 +++++ python/docs/google/protobuf/message.rst | 12 +++++ .../docs/google/protobuf/message_factory.rst | 12 +++++ python/docs/google/protobuf/proto_builder.rst | 12 +++++ python/docs/google/protobuf/reflection.rst | 12 +++++ python/docs/google/protobuf/service.rst | 12 +++++ .../google/protobuf/service_reflection.rst | 12 +++++ python/docs/google/protobuf/struct_pb2.rst | 12 +++++ .../docs/google/protobuf/symbol_database.rst | 12 +++++ python/docs/google/protobuf/text_encoding.rst | 12 +++++ python/docs/google/protobuf/text_format.rst | 12 +++++ python/docs/google/protobuf/timestamp_pb2.rst | 12 +++++ python/docs/google/protobuf/type_pb2.rst | 12 +++++ python/docs/google/protobuf/wrappers_pb2.rst | 12 +++++ python/docs/index.rst | 12 +++++ python/setup.py | 51 ++++++++++++++----- 28 files changed, 376 insertions(+), 14 deletions(-) create mode 100644 .readthedocs.yml diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 000000000..88f4c100f --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,22 @@ +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +sphinx: + configuration: python/docs/conf.py + fail_on_warning: false + +# Setup build requirements for docs. +# Use conda so that we can install the latest libprotobuf package without +# having to build from scratch just for docs builds. +conda: + environment: python/docs/environment.yml + +python: + version: 3.7 + install: + - method: setuptools + path: python diff --git a/python/docs/conf.py b/python/docs/conf.py index 0b42b55d5..6aef7e483 100644 --- a/python/docs/conf.py +++ b/python/docs/conf.py @@ -41,7 +41,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # -# import os +import os # import sys # sys.path.insert(0, os.path.abspath('.')) import google.protobuf @@ -69,6 +69,7 @@ release = google.protobuf.__version__ # ones. extensions = [ "sphinx.ext.autosummary", + "sphinx.ext.ifconfig", "sphinx.ext.intersphinx", "sphinxcontrib.napoleon", ] @@ -237,3 +238,17 @@ autosummary_generate = True # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {"https://docs.python.org/": None} + +# -- Config values ----------------------------------------------------------- +# The setup() function is needed to add configuration values to the Sphinx +# builder. We use this to show a banner when built on Read the Docs. +# https://www.sphinx-doc.org/en/master/usage/extensions/ifconfig.html + +def setup(app): + app.add_config_value( + "build_env", + # Read the Docs sets a READTHEDOCS environment during builds. + # https://docs.readthedocs.io/en/stable/builds.html#build-environment + "readthedocs" if os.getenv("READTHEDOCS") else "", + "env" + ) diff --git a/python/docs/generate_docs.py b/python/docs/generate_docs.py index 9b76e0cac..07debedd1 100755 --- a/python/docs/generate_docs.py +++ b/python/docs/generate_docs.py @@ -95,6 +95,18 @@ TOC_TEMPLATE = """.. START REFTOC, generated by generate_docs.py. AUTOMODULE_TEMPLATE = """.. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + {module} {underline} diff --git a/python/docs/google/protobuf.rst b/python/docs/google/protobuf.rst index 0982bf31a..b26102e11 100644 --- a/python/docs/google/protobuf.rst +++ b/python/docs/google/protobuf.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf =============== diff --git a/python/docs/google/protobuf/any_pb2.rst b/python/docs/google/protobuf/any_pb2.rst index 42198c8cf..b6f47ef3f 100644 --- a/python/docs/google/protobuf/any_pb2.rst +++ b/python/docs/google/protobuf/any_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.any_pb2 ======================= diff --git a/python/docs/google/protobuf/descriptor.rst b/python/docs/google/protobuf/descriptor.rst index 949b97f61..29b07746f 100644 --- a/python/docs/google/protobuf/descriptor.rst +++ b/python/docs/google/protobuf/descriptor.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.descriptor ========================== diff --git a/python/docs/google/protobuf/descriptor_database.rst b/python/docs/google/protobuf/descriptor_database.rst index 912439d1f..1b8b3904d 100644 --- a/python/docs/google/protobuf/descriptor_database.rst +++ b/python/docs/google/protobuf/descriptor_database.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.descriptor_database =================================== diff --git a/python/docs/google/protobuf/descriptor_pb2.rst b/python/docs/google/protobuf/descriptor_pb2.rst index 6b18b44bb..94eec35c3 100644 --- a/python/docs/google/protobuf/descriptor_pb2.rst +++ b/python/docs/google/protobuf/descriptor_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.descriptor_pb2 ============================== diff --git a/python/docs/google/protobuf/descriptor_pool.rst b/python/docs/google/protobuf/descriptor_pool.rst index 8b1ab9943..c2ee33e7b 100644 --- a/python/docs/google/protobuf/descriptor_pool.rst +++ b/python/docs/google/protobuf/descriptor_pool.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.descriptor_pool =============================== diff --git a/python/docs/google/protobuf/duration_pb2.rst b/python/docs/google/protobuf/duration_pb2.rst index 7e39f9e94..4233e3cb5 100644 --- a/python/docs/google/protobuf/duration_pb2.rst +++ b/python/docs/google/protobuf/duration_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.duration_pb2 ============================ diff --git a/python/docs/google/protobuf/empty_pb2.rst b/python/docs/google/protobuf/empty_pb2.rst index 39cbb6431..c386a4c5c 100644 --- a/python/docs/google/protobuf/empty_pb2.rst +++ b/python/docs/google/protobuf/empty_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.empty_pb2 ========================= diff --git a/python/docs/google/protobuf/field_mask_pb2.rst b/python/docs/google/protobuf/field_mask_pb2.rst index 3a0c40cd3..d9d807069 100644 --- a/python/docs/google/protobuf/field_mask_pb2.rst +++ b/python/docs/google/protobuf/field_mask_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.field_mask_pb2 ============================== diff --git a/python/docs/google/protobuf/json_format.rst b/python/docs/google/protobuf/json_format.rst index 8f436e154..eb3b0c539 100644 --- a/python/docs/google/protobuf/json_format.rst +++ b/python/docs/google/protobuf/json_format.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.json_format =========================== diff --git a/python/docs/google/protobuf/message.rst b/python/docs/google/protobuf/message.rst index 03d0dda86..a20424807 100644 --- a/python/docs/google/protobuf/message.rst +++ b/python/docs/google/protobuf/message.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.message ======================= diff --git a/python/docs/google/protobuf/message_factory.rst b/python/docs/google/protobuf/message_factory.rst index b098a8d39..93183cc03 100644 --- a/python/docs/google/protobuf/message_factory.rst +++ b/python/docs/google/protobuf/message_factory.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.message_factory =============================== diff --git a/python/docs/google/protobuf/proto_builder.rst b/python/docs/google/protobuf/proto_builder.rst index 5cc17409d..36243a2ff 100644 --- a/python/docs/google/protobuf/proto_builder.rst +++ b/python/docs/google/protobuf/proto_builder.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.proto_builder ============================= diff --git a/python/docs/google/protobuf/reflection.rst b/python/docs/google/protobuf/reflection.rst index 0bee3e5f4..d177fc02f 100644 --- a/python/docs/google/protobuf/reflection.rst +++ b/python/docs/google/protobuf/reflection.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.reflection ========================== diff --git a/python/docs/google/protobuf/service.rst b/python/docs/google/protobuf/service.rst index 9b3a7b326..6d71f8108 100644 --- a/python/docs/google/protobuf/service.rst +++ b/python/docs/google/protobuf/service.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.service ======================= diff --git a/python/docs/google/protobuf/service_reflection.rst b/python/docs/google/protobuf/service_reflection.rst index 1fb688531..30f30dd29 100644 --- a/python/docs/google/protobuf/service_reflection.rst +++ b/python/docs/google/protobuf/service_reflection.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.service_reflection ================================== diff --git a/python/docs/google/protobuf/struct_pb2.rst b/python/docs/google/protobuf/struct_pb2.rst index 617a580f7..9179eede3 100644 --- a/python/docs/google/protobuf/struct_pb2.rst +++ b/python/docs/google/protobuf/struct_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.struct_pb2 ========================== diff --git a/python/docs/google/protobuf/symbol_database.rst b/python/docs/google/protobuf/symbol_database.rst index 76bcf2f4e..6ea73522f 100644 --- a/python/docs/google/protobuf/symbol_database.rst +++ b/python/docs/google/protobuf/symbol_database.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.symbol_database =============================== diff --git a/python/docs/google/protobuf/text_encoding.rst b/python/docs/google/protobuf/text_encoding.rst index 0e3a5d97b..a2eb959dc 100644 --- a/python/docs/google/protobuf/text_encoding.rst +++ b/python/docs/google/protobuf/text_encoding.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.text_encoding ============================= diff --git a/python/docs/google/protobuf/text_format.rst b/python/docs/google/protobuf/text_format.rst index 6b4c40a66..686b8fc00 100644 --- a/python/docs/google/protobuf/text_format.rst +++ b/python/docs/google/protobuf/text_format.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.text_format =========================== diff --git a/python/docs/google/protobuf/timestamp_pb2.rst b/python/docs/google/protobuf/timestamp_pb2.rst index 4160fe073..540df8395 100644 --- a/python/docs/google/protobuf/timestamp_pb2.rst +++ b/python/docs/google/protobuf/timestamp_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.timestamp_pb2 ============================= diff --git a/python/docs/google/protobuf/type_pb2.rst b/python/docs/google/protobuf/type_pb2.rst index 8f0fb1481..e9b19d7b8 100644 --- a/python/docs/google/protobuf/type_pb2.rst +++ b/python/docs/google/protobuf/type_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.type_pb2 ======================== diff --git a/python/docs/google/protobuf/wrappers_pb2.rst b/python/docs/google/protobuf/wrappers_pb2.rst index 037af966f..8f29aa783 100644 --- a/python/docs/google/protobuf/wrappers_pb2.rst +++ b/python/docs/google/protobuf/wrappers_pb2.rst @@ -1,5 +1,17 @@ .. DO NOT EDIT, generated by generate_docs.py. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + google.protobuf.wrappers_pb2 ============================ diff --git a/python/docs/index.rst b/python/docs/index.rst index d5bb39e78..57f7ce70c 100644 --- a/python/docs/index.rst +++ b/python/docs/index.rst @@ -3,6 +3,18 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. +.. ifconfig:: build_env == 'readthedocs' + + .. warning:: + + You are reading the documentation for the `latest committed changes + `_ of + the `Protocol Buffers package for Python + `_. + Some features may not yet be released. Read the documentation for the + latest released package at `googleapis.dev + `_. + Protocol Buffers Python API Reference ===================================== diff --git a/python/setup.py b/python/setup.py index 9aabbf7aa..d47885852 100755 --- a/python/setup.py +++ b/python/setup.py @@ -19,17 +19,23 @@ from distutils.command.build_py import build_py as _build_py from distutils.command.clean import clean as _clean from distutils.spawn import find_executable + +current_dir = os.path.dirname(__file__) +current_dir_relative = os.path.relpath(current_dir) +src_dir = os.path.abspath(os.path.join(current_dir, "..", "src")) +vsprojects_dir = os.path.abspath(os.path.join(current_dir, "..", "vsprojects")) + # Find the Protocol Compiler. if 'PROTOC' in os.environ and os.path.exists(os.environ['PROTOC']): protoc = os.environ['PROTOC'] -elif os.path.exists("../src/protoc"): - protoc = "../src/protoc" -elif os.path.exists("../src/protoc.exe"): - protoc = "../src/protoc.exe" -elif os.path.exists("../vsprojects/Debug/protoc.exe"): - protoc = "../vsprojects/Debug/protoc.exe" -elif os.path.exists("../vsprojects/Release/protoc.exe"): - protoc = "../vsprojects/Release/protoc.exe" +elif os.path.exists(os.path.join(src_dir, "protoc")): + protoc = os.path.join(src_dir, "protoc") +elif os.path.exists(os.path.join(src_dir, "protoc.exe")): + protoc = os.path.join(src_dir, "protoc.exe") +elif os.path.exists(os.path.join(vsprojects_dir, "Debug", "protoc.exe")): + protoc = os.path.join(vsprojects_dir, "Debug", "protoc.exe") +elif os.path.exists(os.path.join(vsprojects_dir, "Release", "protoc.exe")): + protoc = os.path.join(vsprojects_dir, "Release", "protoc.exe") else: protoc = find_executable("protoc") @@ -40,7 +46,7 @@ def GetVersion(): Do not import google.protobuf.__init__ directly, because an installed protobuf library may be loaded instead.""" - with open(os.path.join('google', 'protobuf', '__init__.py')) as version_file: + with open(os.path.join(current_dir, 'google', 'protobuf', '__init__.py')) as version_file: exec(version_file.read(), globals()) global __version__ return __version__ @@ -51,15 +57,21 @@ def generate_proto(source, require = True): .proto file. Does nothing if the output already exists and is newer than the input.""" + original_source = source + source = source.replace("../src", src_dir) + if not require and not os.path.exists(source): return - output = source.replace(".proto", "_pb2.py").replace("../src/", "") + output = os.path.join( + current_dir, + original_source.replace(".proto", "_pb2.py").replace("../src/", "") + ) if (not os.path.exists(output) or (os.path.exists(source) and os.path.getmtime(source) > os.path.getmtime(output))): - print("Generating %s..." % output) + print("Generating %s..." % os.path.relpath(output)) if not os.path.exists(source): sys.stderr.write("Can't find required file: %s\n" % source) @@ -71,7 +83,13 @@ def generate_proto(source, require = True): "or install the binary package.\n") sys.exit(-1) - protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ] + protoc_command = [ + protoc, + "-I{}".format(src_dir), + "-I{}".format(current_dir), + "--python_out={}".format(current_dir), + source, + ] if subprocess.call(protoc_command) != 0: sys.exit(-1) @@ -116,7 +134,7 @@ def GenerateUnittestProtos(): class clean(_clean): def run(self): # Delete generated files in the code tree. - for (dirpath, dirnames, filenames) in os.walk("."): + for (dirpath, dirnames, filenames) in os.walk(current_dir): for filename in filenames: filepath = os.path.join(dirpath, filename) if filepath.endswith("_pb2.py") or filepath.endswith(".pyc") or \ @@ -269,7 +287,14 @@ if __name__ == '__main__': "Programming Language :: Python :: 3.7", ], namespace_packages=['google'], + # package_dir is required when setup.py is not run from the python/ + # directory (such as from the ReadTheDocs build). See + # https://setuptools.readthedocs.io/en/latest/setuptools.html#using-find-packages + # package_dir must be a relative path. See: + # https://stackoverflow.com/a/53547931/101923 + package_dir={"": current_dir_relative}, packages=find_packages( + where=current_dir, exclude=[ 'import_test_package', ],