MCPcopy
hub / github.com/huggingface/diffusers / check_dummies

Function check_dummies

utils/check_dummies.py:132–167  ·  view source on GitHub ↗

Check if the dummy files are up to date and maybe `overwrite` with the right content.

(overwrite=False)

Source from the content-addressed store, hash-verified

130
131
132def check_dummies(overwrite=False):
133 """Check if the dummy files are up to date and maybe `overwrite` with the right content."""
134 dummy_files = create_dummy_files()
135 # For special correspondence backend to shortcut as used in utils/dummy_xxx_objects.py
136 short_names = {"torch": "pt"}
137
138 # Locate actual dummy modules and read their content.
139 path = os.path.join(PATH_TO_DIFFUSERS, "utils")
140 dummy_file_paths = {
141 backend: os.path.join(path, f"dummy_{short_names.get(backend, backend)}_objects.py")
142 for backend in dummy_files.keys()
143 }
144
145 actual_dummies = {}
146 for backend, file_path in dummy_file_paths.items():
147 if os.path.isfile(file_path):
148 with open(file_path, "r", encoding="utf-8", newline="\n") as f:
149 actual_dummies[backend] = f.read()
150 else:
151 actual_dummies[backend] = ""
152
153 for backend in dummy_files.keys():
154 if dummy_files[backend] != actual_dummies[backend]:
155 if overwrite:
156 print(
157 f"Updating diffusers.utils.dummy_{short_names.get(backend, backend)}_objects.py as the main "
158 "__init__ has new objects."
159 )
160 with open(dummy_file_paths[backend], "w", encoding="utf-8", newline="\n") as f:
161 f.write(dummy_files[backend])
162 else:
163 raise ValueError(
164 "The main __init__ has objects that are not present in "
165 f"diffusers.utils.dummy_{short_names.get(backend, backend)}_objects.py. Run `make fix-copies` "
166 "to fix this."
167 )
168
169
170if __name__ == "__main__":

Callers 1

check_dummies.pyFile · 0.85

Calls 2

create_dummy_filesFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…