MCPcopy Create free account
hub / github.com/pytorch/executorch / _get_flatc_path

Function _get_flatc_path

exir/_serialize/_flatbuffer.py:261–295  ·  view source on GitHub ↗

Returns the path to the flatc executable, caching the result.

()

Source from the content-addressed store, hash-verified

259
260
261def _get_flatc_path() -> str:
262 """Returns the path to the flatc executable, caching the result."""
263 global _flatc_cached_path, _flatc_exit_stack
264 # Double-checked locking: fast path avoids the lock once cached.
265 if _flatc_cached_path is not None:
266 return _flatc_cached_path
267
268 with _flatc_lock:
269 if _flatc_cached_path is not None:
270 return _flatc_cached_path
271
272 flatc_resource = importlib.resources.files(__package__).joinpath(
273 _FLATC_RESOURCE_NAME
274 )
275 if flatc_resource.is_file():
276 exit_stack = contextlib.ExitStack()
277 flatc_path = exit_stack.enter_context(
278 importlib.resources.as_file(flatc_resource)
279 )
280 try:
281 current_mode = flatc_path.stat().st_mode
282 if not (current_mode & stat.S_IXUSR):
283 flatc_path.chmod(
284 current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH
285 )
286 except OSError:
287 pass
288 _flatc_exit_stack = exit_stack
289 # Clean up the extracted temp file on normal process exit.
290 atexit.register(exit_stack.close)
291 _flatc_cached_path = str(flatc_path)
292 else:
293 _flatc_cached_path = os.getenv("FLATC_EXECUTABLE", "flatc")
294
295 return _flatc_cached_path
296
297
298def _reset_flatc_cache_after_fork() -> None:

Callers 1

_run_flatcFunction · 0.85

Calls 1

registerMethod · 0.45

Tested by

no test coverage detected