codingutf8 2020 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license this script reports modified py files under the desired list of toplevel subdirs passed as a list of arguments e g python utilsgetmodifiedfiles py utils src tests examples it uses git to find the forking point and which files were modified i e files not under git won t be considered since the output of this script is fed into makefile commands it doesn t print a newline after the results coding utf 8 2020 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license this script reports modified py files under the desired list of top level sub dirs passed as a list of arguments e g python utils get_modified_files py utils src tests examples it uses git to find the forking point and which files were modified i e files not under git won t be considered since the output of this script is fed into makefile commands it doesn t print a newline after the results
import re
import subprocess
import sys


fork_point_sha = subprocess.check_output("git merge-base main HEAD".split()).decode("utf-8")
modified_files = (
    subprocess.check_output(f"git diff --diff-filter=d --name-only {fork_point_sha}".split()).decode("utf-8").split()
)

joined_dirs = "|".join(sys.argv[1:])
regex = re.compile(rf"^({joined_dirs}).*?\.py$")

relevant_modified_files = [x for x in modified_files if regex.match(x)]
print(" ".join(relevant_modified_files), end="")