MCPcopy Create free account
hub / github.com/pybind/pybind11 / intree_extensions

Function intree_extensions

pybind11/setup_helpers.py:290–329  ·  view source on GitHub ↗

Generate Pybind11Extensions from source files directly located in a Python source tree. ``package_dir`` behaves as in ``setuptools.setup``. If unset, the Python package root parent is determined as the first parent directory that does not contain an ``__init__.py`` file.

(
    paths: Iterable[str], package_dir: dict[str, str] | None = None
)

Source from the content-addressed store, hash-verified

288
289
290def intree_extensions(
291 paths: Iterable[str], package_dir: dict[str, str] | None = None
292) -> list[Pybind11Extension]:
293 """
294 Generate Pybind11Extensions from source files directly located in a Python
295 source tree.
296
297 ``package_dir`` behaves as in ``setuptools.setup``. If unset, the Python
298 package root parent is determined as the first parent directory that does
299 not contain an ``__init__.py`` file.
300 """
301 exts = []
302
303 if package_dir is None:
304 for path in paths:
305 parent, _ = os.path.split(path)
306 while os.path.exists(os.path.join(parent, "__init__.py")):
307 parent, _ = os.path.split(parent)
308 relname, _ = os.path.splitext(os.path.relpath(path, parent))
309 qualified_name = relname.replace(os.path.sep, ".")
310 exts.append(Pybind11Extension(qualified_name, [path]))
311 return exts
312
313 for path in paths:
314 for prefix, parent in package_dir.items():
315 if path.startswith(parent):
316 relname, _ = os.path.splitext(os.path.relpath(path, parent))
317 qualified_name = relname.replace(os.path.sep, ".")
318 if prefix:
319 qualified_name = prefix + "." + qualified_name
320 exts.append(Pybind11Extension(qualified_name, [path]))
321 break
322 else:
323 msg = (
324 f"path {path} is not a child of any of the directories listed "
325 f"in 'package_dir' ({package_dir})"
326 )
327 raise ValueError(msg)
328
329 return exts
330
331
332def naive_recompile(obj: str, src: str) -> bool:

Callers 2

test_intree_extensionsFunction · 0.90

Calls 4

Pybind11ExtensionClass · 0.85
joinMethod · 0.45
appendMethod · 0.45
itemsMethod · 0.45

Tested by 2

test_intree_extensionsFunction · 0.72