user596922 user596922 - 1 year ago 40
Python Question

Use Git commands within Python code

I have been asked to write a script that pulls the latest code from Git, makes a build, and performs some automated unit tests.

I found that there are two built-in Python modules for interacting with Git that are readily available:


What approach/module should I use?

Answer Source

An easier solution would be to use the Python subprocess module to call git. In your case, this would pull the latest code and build:

import subprocess["git", "pull"])["make"])["make", "test"])