MCPcopy Index your code
hub / github.com/plotly/dash / _import_layouts_from_pages

Function _import_layouts_from_pages

dash/_pages.py:416–439  ·  view source on GitHub ↗
(pages_folder)

Source from the content-addressed store, hash-verified

414
415
416def _import_layouts_from_pages(pages_folder):
417 for root, dirs, files in os.walk(pages_folder):
418 dirs[:] = [d for d in dirs if not d.startswith(".") and not d.startswith("_")]
419 for file in files:
420 if file.startswith("_") or file.startswith(".") or not file.endswith(".py"):
421 continue
422 page_path = os.path.join(root, file)
423 with open(page_path, encoding="utf-8") as f:
424 content = f.read()
425 if "register_page" not in content:
426 continue
427
428 module_name = _infer_module_name(page_path)
429 spec = importlib.util.spec_from_file_location(module_name, page_path)
430 page_module = importlib.util.module_from_spec(spec) # type: ignore[reportArgumentType]
431 spec.loader.exec_module(page_module) # type: ignore[reportOptionalMemberAccess]
432 sys.modules[module_name] = page_module
433
434 if (
435 module_name in PAGE_REGISTRY
436 and not PAGE_REGISTRY[module_name]["supplied_layout"]
437 ):
438 _validate.validate_pages_layout(module_name, page_module)
439 PAGE_REGISTRY[module_name]["layout"] = getattr(page_module, "layout")

Callers 1

enable_pagesMethod · 0.85

Calls 2

_infer_module_nameFunction · 0.85
walkMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…