Files
BrowserOS/packages/browseros/build/common/paths.py
Nikhil 2901e73547 patches & fixes for 0.31.1 release (#219)
* chore: new browseros-server binaries

* bugfix: was writing chromium_patches/ in wrong location

* patch: ntp footer disabled by default

* patch: browseros alpha flag

* patch: add log for port saving

* chore: increment PATCH

* feat: use packages/browseros as root_dir properly in context.py
2025-12-05 16:39:56 -08:00

46 lines
1.4 KiB
Python
Generated

#!/usr/bin/env python3
"""
Package root detection for BrowserOS build system
This module provides a single function to find the browseros package root
directory, regardless of the current working directory.
IMPORTANT: This module must have NO local imports to avoid circular dependencies.
It is imported by both context.py and env.py at module load time.
"""
import re
from functools import lru_cache
from pathlib import Path
@lru_cache(maxsize=1)
def get_package_root() -> Path:
"""Find browseros package root by walking up looking for pyproject.toml.
Walks up from this file's location looking for a pyproject.toml that
contains the browseros package definition.
Returns:
Path to the browseros package root (e.g., packages/browseros/)
Raises:
RuntimeError: If package root cannot be found
"""
current = Path(__file__).resolve().parent
while current != current.parent:
pyproject = current / "pyproject.toml"
if pyproject.exists():
content = pyproject.read_text()
# Match name = "browseros" with flexible whitespace
if re.search(r'^name\s*=\s*["\']browseros["\']', content, re.MULTILINE):
return current
current = current.parent
raise RuntimeError(
"Could not find browseros package root. "
"Expected to find pyproject.toml with name = 'browseros' "
f"in ancestors of {Path(__file__).resolve()}"
)