Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

为 PaddleSOT repo 增加 xdoctest 流水线 #195

Closed
SigureMo opened this issue Jun 23, 2023 · 1 comment · Fixed by #199
Closed

为 PaddleSOT repo 增加 xdoctest 流水线 #195

SigureMo opened this issue Jun 23, 2023 · 1 comment · Fixed by #199
Labels
🐾 meow 快乐喵喵开源活动专属认证

Comments

@SigureMo
Copy link
Member

SigureMo commented Jun 23, 2023

动机

相比于文字描述,示例代码可以更快地让开发者了解到一个 API 是如何使用的,其重要性不言而喻

目前 Paddle 主 repo 已经准备引入 xdoctest,见 中国软件开源创新大赛:飞桨框架任务挑战赛tracking issue,另外我们 PaddleSOT 合入 Paddle 也还有一段时间,我们可以尽可能使我们的代码风格更加现代,因此这里建议在 PaddleSOT 中增加流水线用于示例代码的检查

目前我已经在 #193 上验证了 xdoctest 的引入可行性,运行如下命令即可检查全部示例代码:

xdoctest sot

=====================================
_  _ ___  ____ ____ ___ ____ ____ ___
 \/  |  \ |  | |     |  |___ [__   |
_/\_ |__/ |__| |___  |  |___ ___]  |

=====================================

Start doctest_module('sot')
Listing tests
gathering tests
running 2 test(s)
====== <exec> ======
* DOCTEST : sot/opcode_translator/executor/dispatcher.py::Dispatcher:0, line 126 <- wrt source file
DOCTEST SOURCE
2 >>> def builtin_add(a: int, b: int) -> int:
3 ...     ...
4 ...
5 >>> Dispatcher.register(builtin_add, ("int", "int"), {}, lambda a, b: a + b)
6 >>> handler = Dispatcher.dispatch(builtin_add, 1, 2)
7 >>> handler(1, 2)
  3
DOCTEST STDOUT/STDERR
DOCTEST RESULT
* SUCCESS: sot/opcode_translator/executor/dispatcher.py::Dispatcher:0
====== </exec> ======
====== <exec> ======
* DOCTEST : sot/opcode_translator/executor/dispatcher.py::Dispatcher.register_decorator:0, line 170 <- wrt source file
DOCTEST SOURCE
 1 >>> def builtin_add(a: int, b: int) -> int:
 2 ...     ...
 3 ...
 4 >>> @Dispatcher.register_decorator(builtin_add)
 5 ... def builtin_add_dispatcher(a: int, b: int) -> int:
 6 ...     return a + b
 7 ...
 8 >>> handler = Dispatcher.dispatch(builtin_add, 1, 2)
 9 >>> handler(1, 2)
   3
DOCTEST STDOUT/STDERR
DOCTEST RESULT
* SUCCESS: sot/opcode_translator/executor/dispatcher.py::Dispatcher.register_decorator:0
====== </exec> ======
============
Finished doctests
2 / 2 passed
=== 2 passed in 1.17 seconds ===

两段示例代码均被正确提取,而且能够检测输出的正确性,本任务应在 #193 合入后开展,以确保正确性测试(已合入)

一些建议

  • 如果有合适的 pre-commit 可以直接集成 因为所有版本都要测,还是不要用 pre-commit 了
  • 如果没有就直接加一条流水线,可以考虑在 test 流水线里集成
  • Python 3.8、3.9、3.10 都应该测试

另外可以顺便升级一下 pre-commit 中的 common hooks 的版本,与 PaddlePaddle/Paddle#54796 同步

另外开发相关依赖应该放在 pyproject.toml 中的 project.optional-dependencies.dev

[project.optional-dependencies]
dev = [
    "xdoctest"
]

使用如下命令安装开发依赖:

pip install -e ".[dev]"

requirements.txt 不再使用,可以移除

@NotHaozi
Copy link
Collaborator

I try try

@SigureMo SigureMo added 🐾 meow 快乐喵喵开源活动专属认证 and removed good first issue Good for newcomers labels Jul 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐾 meow 快乐喵喵开源活动专属认证
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants