我被要求编写一个脚本,从 Git 中提取最新代码、进行构建并执行一些自动化单元测试。
我发现有两个内置的 Python 模块可以随时使用,用于与 Git 交互:GitPython
and libgit2
.
我应该使用什么方法/模块?
更简单的解决方案是使用 Pythonsubprocess
调用 git 的模块。在您的情况下,这将提取最新的代码并构建:
import subprocess
subprocess.call(["git", "pull"])
subprocess.call(["make"])
subprocess.call(["make", "test"])
Docs:
- 子进程 - Python 2.x https://docs.python.org/2/library/subprocess.html
- 子进程 - Python 3.x https://docs.python.org/3/library/subprocess.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)