Export FLOWS and build from the top-level fluksio package
A test of the declarations had to import them from fluksio.sdk while the guide teaches `from fluksio import ...`. The worker's inert module gets the same two names so a module importing them still loads inside a node. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QgG6TJw5qBZzaLghQSRVrq
This commit is contained in:
@@ -4,7 +4,8 @@ Two audiences, one import name. In a research repository, ``from fluksio
|
|||||||
import Port, node, Flow`` is the authoring API: it says which of your existing
|
import Port, node, Flow`` is the authoring API: it says which of your existing
|
||||||
functions are nodes and which nodes make up a flow, and ``fluksio sync``
|
functions are nodes and which nodes make up a flow, and ``fluksio sync``
|
||||||
uploads what it finds. Those names come from :mod:`fluksio.sdk`, which imports
|
uploads what it finds. Those names come from :mod:`fluksio.sdk`, which imports
|
||||||
nothing but the standard library.
|
nothing but the standard library. ``FLOWS`` and ``build`` come with them, so a
|
||||||
|
test can check the declarations without an engine.
|
||||||
|
|
||||||
Inside a node, ``import fluksio`` is not this package at all: the worker
|
Inside a node, ``import fluksio`` is not this package at all: the worker
|
||||||
installs a reporter of its own under that name before any node code runs, so
|
installs a reporter of its own under that name before any node code runs, so
|
||||||
@@ -24,7 +25,7 @@ from importlib.metadata import PackageNotFoundError
|
|||||||
from importlib.metadata import version as _version
|
from importlib.metadata import version as _version
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fluksio.sdk import Flow, Port, node, use
|
from fluksio.sdk import FLOWS, Flow, Port, build, node, use
|
||||||
|
|
||||||
try:
|
try:
|
||||||
__version__ = _version("fluksio")
|
__version__ = _version("fluksio")
|
||||||
@@ -32,8 +33,10 @@ except PackageNotFoundError: # pragma: no cover - a checkout that was never ins
|
|||||||
__version__ = "0.0.0+unknown"
|
__version__ = "0.0.0+unknown"
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
"FLOWS",
|
||||||
"Flow",
|
"Flow",
|
||||||
"Port",
|
"Port",
|
||||||
|
"build",
|
||||||
"emit",
|
"emit",
|
||||||
"load_artifact",
|
"load_artifact",
|
||||||
"node",
|
"node",
|
||||||
|
|||||||
@@ -364,3 +364,15 @@ def test_a_node_in_a_script_run_directly_is_refused_at_sync_not_at_import():
|
|||||||
flow.document()
|
flow.document()
|
||||||
with pytest.raises(SyncError, match="run directly"):
|
with pytest.raises(SyncError, match="run directly"):
|
||||||
flow.shims()
|
flow.shims()
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_registry_and_the_builder_come_with_the_authoring_import():
|
||||||
|
"""A test of the declarations needs no second import path."""
|
||||||
|
import fluksio
|
||||||
|
import fluksio.sdk
|
||||||
|
|
||||||
|
flow = a_flow()
|
||||||
|
|
||||||
|
assert fluksio.FLOWS is fluksio.sdk.FLOWS
|
||||||
|
assert fluksio.FLOWS["train"] is flow
|
||||||
|
assert fluksio.build(flow) == fluksio.sdk.build(flow)
|
||||||
|
|||||||
@@ -415,6 +415,10 @@ finetune = Flow(
|
|||||||
different message, keyword arguments override settings, and `id=` tells two
|
different message, keyword arguments override settings, and `id=` tells two
|
||||||
uses of one function apart. `train` above is unaffected by any of it.
|
uses of one function apart. `train` above is unaffected by any of it.
|
||||||
|
|
||||||
|
A test can check the declarations without an engine. Importing the module
|
||||||
|
registers its flows in `fluksio.FLOWS`, and `fluksio.build(flow)` returns the
|
||||||
|
document `sync` would upload, refusing what the engine would refuse.
|
||||||
|
|
||||||
## Sync it
|
## Sync it
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ class _Reporter(ModuleType):
|
|||||||
#: The same name the SDK exports at top level, so a node written against
|
#: The same name the SDK exports at top level, so a node written against
|
||||||
#: one surface finds it on the other. Set by ``_install_reporter``.
|
#: one surface finds it on the other. Set by ``_install_reporter``.
|
||||||
logger: logging.Logger
|
logger: logging.Logger
|
||||||
|
#: The registry `fluksio sync` reads, empty here: nothing registers into
|
||||||
|
#: it inside a node. Set by ``_install_reporter``.
|
||||||
|
FLOWS: dict[str, Any]
|
||||||
|
|
||||||
def emit(self, **ports: Any) -> None:
|
def emit(self, **ports: Any) -> None:
|
||||||
"""Publish on this node's output ports without returning yet.
|
"""Publish on this node's output ports without returning yet.
|
||||||
@@ -174,6 +177,10 @@ class _Reporter(ModuleType):
|
|||||||
"""A flow declaration, already read by `fluksio sync`."""
|
"""A flow declaration, already read by `fluksio sync`."""
|
||||||
return _Declared()
|
return _Declared()
|
||||||
|
|
||||||
|
def build(self, *args: Any, **kwargs: Any) -> Any:
|
||||||
|
"""A flow document, already built by `fluksio sync`."""
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class _LogHandler(logging.Handler):
|
class _LogHandler(logging.Handler):
|
||||||
"""Writes to whatever ``sys.stderr`` is at the time of the record.
|
"""Writes to whatever ``sys.stderr`` is at the time of the record.
|
||||||
@@ -409,6 +416,7 @@ def _install_reporter() -> None:
|
|||||||
# its own logging installs a root handler on the same stream.
|
# its own logging installs a root handler on the same stream.
|
||||||
logger.propagate = False
|
logger.propagate = False
|
||||||
module.logger = logger
|
module.logger = logger
|
||||||
|
module.FLOWS = {}
|
||||||
sys.modules["fluksio"] = module
|
sys.modules["fluksio"] = module
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user