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

Method copy_extensions_to_source

setup.py:479–514  ·  view source on GitHub ↗

For each extension in `ext_modules`, we need to copy the extension file from the build directory to the correct location in the local directory. This should only be triggered when inplace mode (editable mode) is enabled. Args: Returns:

(self)

Source from the content-addressed store, hash-verified

477 super().run()
478
479 def copy_extensions_to_source(self) -> None:
480 """For each extension in `ext_modules`, we need to copy the extension
481 file from the build directory to the correct location in the local
482 directory.
483
484 This should only be triggered when inplace mode (editable mode) is enabled.
485
486 Args:
487
488 Returns:
489 """
490 for ext in self.extensions:
491 if not ext.is_cmake_artifact_used(self):
492 continue
493
494 package_dir = ext.inplace_dir(self)
495
496 # Ensure that the destination directory exists.
497 self.mkpath(os.fspath(package_dir))
498
499 regular_file = ext.src_path(self)
500 inplace_file = os.path.join(
501 package_dir, os.path.basename(ext.dst_path(self))
502 )
503
504 # Always copy, even if source is older than destination, to ensure
505 # that the right extensions for the current Python/platform are
506 # used.
507 if os.path.exists(regular_file) or not ext.optional:
508 self.copy_file(regular_file, inplace_file, level=self.verbose)
509
510 if ext._needs_stub:
511 inplace_stub = self._get_equivalent_stub(ext, inplace_file)
512 self._write_stub_file(inplace_stub, ext, compile=True)
513 # Always compile stub and remove the original (leave the cache behind)
514 # (this behaviour was observed in previous iterations of the code)
515
516 # TODO(dbort): Depend on the "build" command to ensure it runs first
517

Callers

nothing calls this directly

Calls 4

inplace_dirMethod · 0.45
src_pathMethod · 0.45
dst_pathMethod · 0.45

Tested by

no test coverage detected