'Circle CI: is there a built-in way to run a job on modified files only?

I would like to setup a Circle CI job that runs the black code formatter against only the python files that were created or modified in a PR, and leave the rest alone.

I know how to do this on my local terminal:

black $(git diff --name-only <target_branch_name>..<modifications_branch_name> -- '*.py')

From my research, it seems that doing this with Circle CI is not as simple because:

  1. a normal git diff on a Circle CI environment returns nothing
  2. the target branch name is not present in the built-in env vars

This article shows how one can set this up (very complicated procedure), but I wanted to ask if anyone knows how I can do this in a simpler way. Any help is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source