- tl;dr
- Prerequisites
- Setting up
- Building docs
- Previewing docs
- Translations
- API docs
- Auto-generated docs
- Cleaning up
- Reporting issues
- 前置条件
- 环境准备
- 构建文档
- 预览文档
- 更新翻译
- API 文档
- 自动生成的文档
- 文件清理
- 报告问题
Tip
Command line examples in this guide assume your working directory to be docs/.
python -m pip install -r requirements.txt
secretflow-doctools update-translations --lang zh_CN
secretflow-doctools build --lang en --lang zh_CN
secretflow-doctools previewThis project uses Sphinx to build documentation. You will need:
- Python >= 3.10
Run:
python -m pip install -r requirements.txtThis will:
- Install the required dependencies for building docs
Tip
Refer to ../CONTRIBUTING.md for information on setting up your Python environment.
You may also use other package managers such as uv or mamba.
secretflow-doctools is a command-line utility for building docs for SecretFlow
projects.
To build docs, run:
secretflow-doctools build --lang en --lang zh_CNThis will build both the English (en) and the Simplified Chinese (zh_CN) versions of
the documentation.
You should be able to see the following output:
SUCCESS to preview, run: secretflow-doctools preview -c .
Tip
If you are getting a "command not found" error, you might not have activated the
correct environment by running source .venv/bin/activate. Please review
Setting up.
The utility features a documentation previewer. You will be able to visualize how your changes will eventually appear on our website.
To preview the docs that was built, run:
secretflow-doctools previewThis will start the server. You should be able to see the following output:
* Running on http://127.0.0.1:5000
Navigate to http://127.0.0.1:5000 on your browser (the port number may be different), you should be able to see a page similar to the following:
Click on a version to see the preview. You should be able to see a page similar to the following:
Tip
You may leave the preview server running. When you run the build command again, refresh the page to see updated content.
After updating source docs, you should also update the corresponding translation files.
Important
If your updates involve rewriting existing texts, you MUST update translation files, otherwise some translated paragraphs may fall back to showing the original text.
Run:
secretflow-doctools update-translations --lang zh_CN
# `--lang zh_CN` sets the target language to Chinese (i.e. you are translating into Chinese)This will:
- Scan source text for changes
- Update the translation files under locales/ such that they become in-sync again
If there are updates, you should be able to see output similar to the following, and see changes in source control:
Update: locales/zh_CN/LC_MESSAGES/index.po +1, -0
...
SUCCESS finished updating translation files
This project uses GNU gettext to translate docs during build. Translation files are under locales/.
Paths to the translation files (PO files) mirror their source document counterparts. For example:
| Source texts | getting_started/install.rst |
| Translations | locales/zh_CN/LC_MESSAGES/getting_started/install.po |
PO files have the following syntax:
msgid "Hello, world!"
msgstr "你好,世界!"
msgid comes from source docs, which will be used to lookup translations during build,
and you should not modify them.
msgstr is the translation. Please update these.
Tip
Poedit is a free and open-source graphical editor for gettext PO files and is highly recommended.
[!IMPORTANT]
-
msgstrmay contain inline markups, such as bolded text or links. Translations should retain such markups. You should ensure the markup syntax is consistent with the source document:msgid "This is a `link <https://example.org/>`_." - msgstr "这是一个 [链接](https://example.org/) 。" + msgstr "这是一个 `链接 <https://example.org/>`_ 。"
-
You may notice a
fuzzylabel after updating translation files:#: ../../topics/ccl/usage.rst:9 + #, fuzzy - msgid "What is SCQL CCL? Please read :doc:`/topics/ccl/intro`." + msgid "What is SCQL CCL? Please read :doc:`/topics/ccl/intro` first." msgstr "什么是 SCQL CCL?请参阅 :doc:`/topics/ccl/intro`。"
fuzzyindicates that a source paragraph is updated but only slightly. You should revisefuzzytranslations, and then remove thefuzzylabel.fuzzyentries will still appear in the output even if they not updated in time, albeit the displayed content is then slightly different from source text. -
You may notice
.mofiles under locales/. These are binary files autogenerated during builds and are not editable. The files to edit are.pofiles.
After updating translations, build docs again to preview them.
reference/py_api.rst documents SPU's Python API.
Important
For API docs to display correctly, the corresponding Python modules must be importable at build time.
That is, from spu import ... must not throw. Essentially, this means that
dependencies must be installed and C/C++ modules must be compiled.
Some reference docs are auto-generated from code. To generate these docs, run:
make autogenerated
# see Makefile for actual commandImportant
Note that the generated files are NOT gitignored. You should run this step whenever there are updates to code, and commit the changes.
The above tasks generate temporary files under _build. To clean up these files, run:
secretflow-doctools cleanIf commands or previews aren't working as expecting, please file an issue at https://github.com/secretflow/doctools/issues.
For project-specific questions, please file an issue in this repository instead.
Note
To help with troubleshooting, set the LOGURU_LEVEL=DEBUG environment variable to see
debug logs.
secretflow-doctools invokes other programs. When LOGURU_LEVEL=DEBUG is set,
logging will contain the full commands being run:
| Command | Delegates to |
|---|---|
secretflow-doctools build |
sphinx-build |
secretflow-doctools update-translations |
sphinx-intl |
Tip
下文的示例命令建议在本目录 (docs) 下执行。
本项目使用 Sphinx 作为文档框架。你需要:
- Python >= 3.10
执行:
python -m pip install -r requirements.txt这将会:
secretflow-doctools 是针对隐语项目文档构建的辅助工具,它协助开发者在本地构建并
且预览文档。
执行:
secretflow-doctools build --lang en --lang zh_CN这将会构建英文版 en 以及中文版 zh_CN 文档。
如果一切正常,你应当能看到以下输出:
SUCCESS to preview, run: secretflow-doctools preview -c .
Tip
如果提示 secretflow-doctools 命令未找到,你可能没有执行 source .venv/bin/activate
以激活正确的 Python 环境;请参考环境准备中的指引。
如果想要只构建某个语言的文档,可以调整 --lang 选项。
工具提供了本地预览的能力,帮助开发者验证文档在发布到隐语官网后的显示效 果。
执行:
secretflow-doctools preview这将会在本地启动一个预览服务器。你应当能看到以下输出:
* Running on http://127.0.0.1:5000
用浏览器访问 http://127.0.0.1:5000 (或其它端口号),你应当能看到类似下图的页面,其中 将会列出在本地构建好的文档版本:
点击一个版本即可打开对应预览,你应当能看到类似下图的页面:
Tip
你可以保持预览服务器一直开启:在重新构建文档后,刷新页面即可看到更新的内容。
当你更新了文档原文(无论是新增、修改还是删除),你需要同时更新对应的翻译文件。
Important
如果你的变更是对现有文本进行修改,请务必同步翻译文件,否则现有翻译可能会失效,发布后可 能会出现中英文夹杂的情况。
执行:
secretflow-doctools update-translations --lang zh_CN
# 其中 --lang zh_CN 代表目标语言是中文(翻译成中文)这将会:
- 扫描文档原文的文本内容
- 更新 locales/ 目录下的翻译文件,使得它们和原文维持同步
如果有更新,你应当能看到类似下文的输出,并且在版本控制中看到文件修改:
Update: locales/zh_CN/LC_MESSAGES/index.po +1, -0
...
SUCCESS finished updating translation files
本项目使用 GNU gettext 来配置文档内容的多语言版本。翻译用文件全部位于 locales/ 目录下。
翻译文件(PO 文件)的路径与文档原文是一对一的关系,示例:
| 原文 | getting_started/install.rst |
| 翻译 | locales/zh_CN/LC_MESSAGES/getting_started/install.po |
翻译文件的格式如下:
msgid "Hello, world!"
msgstr "你好,世界!"
msgid 来自文档原文,将会用于在构建时通过原文索引到翻译,因此请勿修改。
msgstr 是翻译后的文本,请修改这一字段。
Important
以下是翻译的一些注意事项:
-
msgstr中可能会包含样式标记(比如字体加粗、链接等),在翻译文本中,标记应当与原文一 致:msgid "This is a `link <https://example.org/>`_." - msgstr "这是一个 [链接](https://example.org/) 。" + msgstr "这是一个 `链接 <https://example.org/>`_ 。"
-
在同步翻译文件后,你可能会留意到一些翻译条目被加上了
fuzzy的标记, 比如:#: ../../topics/ccl/usage.rst:9 + #, fuzzy - msgid "What is SCQL CCL? Please read :doc:`/topics/ccl/intro`." + msgid "What is SCQL CCL? Please read :doc:`/topics/ccl/intro` first." msgstr "什么是 SCQL CCL?请参阅 :doc:`/topics/ccl/intro`。"
fuzzy意味着gettext判断原文有轻微变化,需要人工校对。你应当更新翻译,然后将fuzzy标记去掉。fuzzy条目的意义在于构建后不会失效,也就是说,即使没有及时更新翻译,旧翻译也能继续显 示(不过会稍微与原文不一致)。 -
你可能会在 locales/ 目录下找到后缀为
.mo的文件,这些文件时构建时产生的 二进制文件,它们无法被修改也无需关注,你应当修改后缀为.po的文件。
在更新了翻译文件之后,重新执行文档构建然后预览文档,即可看到翻 译后的显示效果。
reference/py_api.rst 包含 SPU Python API 的文档。
Important
API 文档要正确渲染,对应的 Python 模块必须在文档构建时可以正确引用。 也就是说
,from spu import ... 不能抛出异常,意味着依赖有被安装,以及 C/C++ 模块有被构建。
一些参考文档由代码自动生成。要更新这些文档,执行:
make autogenerated
# 详细命令见 MakefileImportant
生成的文件不会被 gitignore。当相关代码有更新时,请执行这一步骤,并且提交产生的变更 。
以上流程会产生额外的临时文件,这些文件全部位于 _build 目录下。如果需要清理 ,可以执行:
secretflow-doctools clean如果在以上过程中遇到报错、预览无法显示等问题,可以提交问题到 https://github.com/secretflow/doctools/issues。
文档内容及本项目代码的相关问题请提交到本项目的 Issues 中。
Note
为协助排查问题,你可以设置 LOGURU_LEVEL=DEBUG 环境变量来让文档工具输出更多日志。
secretflow-doctools 会调用其他工具,在 LOGURU_LEVEL=DEBUG 时,日志会在每个步骤打印
完整的命令行指令:
secretflow-doctools build |
sphinx-build |
secretflow-doctools update-translations |
sphinx-intl |

