arc-kernel 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
arc/__init__.py ADDED
@@ -0,0 +1,65 @@
1
+ """
2
+ ARC kernel — capability-based Python platform.
3
+
4
+ `import arc` is the only import application code ever needs (Architecture
5
+ §3.2). After `arc.boot()`, every enabled plugin's capability is reachable as
6
+ `arc.<capability>` via module-level `__getattr__` (PEP 562) — never
7
+ `import arc.psqldb`.
8
+
9
+ import arc
10
+
11
+ arc.boot()
12
+ user = await arc.psqldb.fetch_one(...)
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ from typing import Any
18
+
19
+ from . import codec, health # noqa: F401 - attaches arc.codec / arc.health as real submodules
20
+ from .kernel import ( # noqa: F401
21
+ ArcAdvisory,
22
+ Capability,
23
+ ExportError,
24
+ Kernel,
25
+ KernelError,
26
+ )
27
+ from .resolver import BootPlan, PluginSpec, ResolutionError # noqa: F401
28
+ from .runtime import BootError, boot, find_project_root, shutdown # noqa: F401
29
+
30
+ __version__ = "0.1.0"
31
+
32
+
33
+ def __getattr__(name: str) -> Any:
34
+ """PEP 562: resolve arc.<capability> against the booted kernel (§3.2).
35
+
36
+ Only consulted for names not found in the module dict — which is exactly
37
+ why capability names may never collide with the kernel's own namespace
38
+ (enforced at resolution and export time; see arc.kernel).
39
+ """
40
+ from . import _state
41
+
42
+ kernel = _state.get_kernel()
43
+ if kernel is not None and kernel.has(name):
44
+ return kernel.get(name)
45
+ if kernel is None:
46
+ raise AttributeError(
47
+ f"module 'arc' has no attribute {name!r}. If {name!r} is a plugin "
48
+ f"capability, call arc.boot() first — capabilities are only "
49
+ f"attached to `arc` after boot."
50
+ )
51
+ raise AttributeError(
52
+ f"module 'arc' has no attribute {name!r}, and no enabled plugin "
53
+ f"exports a capability with that name "
54
+ f"(booted capabilities: {sorted(kernel.capabilities()) or 'none'})."
55
+ )
56
+
57
+
58
+ def __dir__() -> list[str]:
59
+ from . import _state
60
+
61
+ names = set(globals())
62
+ kernel = _state.get_kernel()
63
+ if kernel is not None:
64
+ names.update(kernel.capabilities())
65
+ return sorted(names)
arc/_state.py ADDED
@@ -0,0 +1,31 @@
1
+ """
2
+ arc._state
3
+ -----------------
4
+ Process-wide runtime state: the single active Kernel for this process.
5
+
6
+ Deliberately tiny and dependency-free. It exists so that `arc/__init__.py`
7
+ (PEP 562 attribute lookup), `arc.runtime` (boot/shutdown) and `arc.settings`
8
+ (module-level runtime API) can all reach the active kernel without importing
9
+ each other in a circle.
10
+
11
+ Access goes through get_kernel()/set_kernel() — never `from ... import`
12
+ the variable itself, which would snapshot a stale binding.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import typing
18
+
19
+ if typing.TYPE_CHECKING:
20
+ from .kernel import Kernel
21
+
22
+ _active_kernel: "Kernel | None" = None
23
+
24
+
25
+ def get_kernel() -> "Kernel | None":
26
+ return _active_kernel
27
+
28
+
29
+ def set_kernel(kernel: "Kernel | None") -> None:
30
+ global _active_kernel
31
+ _active_kernel = kernel