MCPcopy Index your code
hub / github.com/huggingface/diffusers / get_diff_for_doctesting

Function get_diff_for_doctesting

utils/tests_fetcher.py:310–348  ·  view source on GitHub ↗

Get the diff in doc examples between a base commit and one or several commits. Args: repo (`git.Repo`): A git repository (for instance the Transformers repo). base_commit (`str`): The commit reference of where to compare for the diff. This is the cur

(repo: Repo, base_commit: str, commits: List[str])

Source from the content-addressed store, hash-verified

308
309
310def get_diff_for_doctesting(repo: Repo, base_commit: str, commits: List[str]) -> List[str]:
311 """
312 Get the diff in doc examples between a base commit and one or several commits.
313
314 Args:
315 repo (`git.Repo`):
316 A git repository (for instance the Transformers repo).
317 base_commit (`str`):
318 The commit reference of where to compare for the diff. This is the current commit, not the branching point!
319 commits (`List[str]`):
320 The list of commits with which to compare the repo at `base_commit` (so the branching point).
321
322 Returns:
323 `List[str]`: The list of Python and Markdown files with a diff (files added or renamed are always returned, files
324 modified are returned if the diff in the file is only in doctest examples).
325 """
326 print("\n### DIFF ###\n")
327 code_diff = []
328 for commit in commits:
329 for diff_obj in commit.diff(base_commit):
330 # We only consider Python files and doc files.
331 if not diff_obj.b_path.endswith(".py") and not diff_obj.b_path.endswith(".md"):
332 continue
333 # We always add new python/md files
334 if diff_obj.change_type in ["A"]:
335 code_diff.append(diff_obj.b_path)
336 # Now for modified files
337 elif diff_obj.change_type in ["M", "R"]:
338 # In case of renames, we'll look at the tests using both the old and new name.
339 if diff_obj.a_path != diff_obj.b_path:
340 code_diff.extend([diff_obj.a_path, diff_obj.b_path])
341 else:
342 # Otherwise, we check modifications contain some doc example(s).
343 if diff_contains_doc_examples(repo, commit, diff_obj.b_path):
344 code_diff.append(diff_obj.a_path)
345 else:
346 print(f"Ignoring diff in {diff_obj.b_path} as it doesn't contain any doc example.")
347
348 return code_diff
349
350
351def get_all_doctest_files() -> List[str]:

Callers 1

get_doctest_filesFunction · 0.85

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…