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

Class BuiltExtension

setup.py:377–458  ·  view source on GitHub ↗

An extension that installs a python extension that was built by cmake.

Source from the content-addressed store, hash-verified

375
376
377class BuiltExtension(_BaseExtension):
378 """An extension that installs a python extension that was built by cmake."""
379
380 def __init__(
381 self,
382 src: str,
383 modpath: str,
384 dependent_cmake_flags: List[str],
385 src_dir: Optional[str] = None,
386 ):
387 """Initializes a BuiltExtension.
388
389 Args:
390 src_dir: The directory of the file to install, relative to the cmake-out
391 directory. A placeholder %BUILD_TYPE% will be replaced with the build
392 type for multi-config generators (like Visual Studio) where the build
393 output is in a subdirectory named after the build type. For single-
394 config generators (like Makefile Generators or Ninja), this placeholder
395 will be removed.
396 src_name: The name of the file to install. If the path ends in `.so`,
397 modpath: The dotted path of the python module that maps to the
398 extension.
399 """
400 assert (
401 "/" not in modpath
402 ), f"modpath must be a dotted python module path: saw '{modpath}'"
403 full_src = src
404 if src_dir is None and _is_windows():
405 src_dir = "%BUILD_TYPE%/"
406 if src_dir is not None:
407 full_src = os.path.join(src_dir, src)
408 self.dependent_cmake_flags = dependent_cmake_flags
409 # This is a real extension, so use the modpath as the name.
410 super().__init__(
411 src=f"%CMAKE_CACHE_DIR%/{full_src}",
412 dst=modpath,
413 name=modpath,
414 dependent_cmake_flags=self.dependent_cmake_flags,
415 )
416
417 def src_path(self, installer: "InstallerBuildExt") -> Path:
418 """Returns the path to the source file, resolving globs.
419
420 Args:
421 installer: The InstallerBuildExt instance that is installing the
422 file.
423 """
424 try:
425 return super().src_path(installer)
426 except ValueError:
427 # Probably couldn't find the file. If the path ends with .so, try
428 # looking for a .dylib file instead, in case we're running on macos.
429 if self.src.endswith(".so"):
430 dylib_src = re.sub(r"\.so$", ".dylib", self.src)
431 return BuiltExtension(
432 src=dylib_src,
433 modpath=self.dst,
434 dependent_cmake_flags=self.dependent_cmake_flags,

Callers 2

src_pathMethod · 0.85
setup.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected