__init__.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """pm: the hermes package system.
  2. Everything hermes depends on — tool binaries, the python venv, node_modules
  3. dirs, plugins — is a package in one dependency tree. Package definitions
  4. (pm/packages.py) say what a package IS. The lockfile (pm/lock.json,
  5. machine-written) says exactly which versions and hashes. The installed-state
  6. file (facts.json, per install) says what is actually on this machine.
  7. ensure(name) makes the installed state match the lockfile and returns a
  8. Runner with the composed environment. env_for(*names) composes already-installed
  9. packages' env without installing anything.
  10. The facade resolves lazily (PEP 562): ``pm.environments`` runs at process boot,
  11. before any dependency is importable, and must not drag the downloader/ensure
  12. machinery in with it.
  13. """
  14. from __future__ import annotations
  15. import sys
  16. _EXPORTS = {
  17. "pm.install": (
  18. "activate", "check", "drift", "enabled_extras", "env_for", "is_installed",
  19. "installed_package", "lazy_installs_allowed", "store_first_path", "uv_launcher",
  20. ),
  21. "pm.client": (
  22. "ensure", "sync_venv", "build_environment", "lock_project", "stage_manager_runtime",
  23. "ensure_environment", "ensure_project_environment", "ensure_python_tool", "venv_is_current", "check_project_lock",
  24. "export_requirements", "build_requirements_environment", "prune_cache", "stage_tools",
  25. "prepare_tools",
  26. ),
  27. "pm.operations": ("environment_python", "python_tool"),
  28. "pm.extras": ("available", "ensure_import", "install_hint"),
  29. "pm.lock": ("Facts", "Lockfile"),
  30. "pm.package": ("InstallError", "Package", "Runner", "compose_env"),
  31. "pm.registry": ("all_packages", "get_package", "register", "walk"),
  32. "pm.store": ("Store", "current_target"),
  33. }
  34. _HOME = {name: module for module, names in _EXPORTS.items() for name in names}
  35. __all__ = list(_HOME)
  36. def __getattr__(name: str):
  37. module = _HOME.get(name)
  38. if module is None:
  39. raise AttributeError(f"module 'pm' has no attribute {name!r}")
  40. # Not importlib.import_module: tests patch that globally and the facade must keep resolving.
  41. __import__(module)
  42. value = getattr(sys.modules[module], name)
  43. globals()[name] = value
  44. return value
  45. def __dir__():
  46. return sorted(set(globals()) | set(_HOME))