Runtime
plateforme.core.runtime
This module provides runtime utilities for the Plateforme framework.
AppMap
module-attribute
A dictionary mapping the application names to their respective application instance.
NamespaceMap
module-attribute
A dictionary mapping the namespace names to their respective namespace instance.
PackageMap
module-attribute
A dictionary mapping the package module names to their respective package instance.
ResourceMap
module-attribute
A dictionary mapping the resource fully qualified names to either their
respective resource type, or None
if the resource is not yet resolved.
ResourceLinkMap
module-attribute
A dictionary mapping the resource fully qualified names to their respective set of resource linked fields.
ResolvedState
module-attribute
ResolvedState = Literal[
RESOLVED,
INITIALIZING,
LOADING,
BUILDING,
FINALIZING,
READY,
]
A literal type the for the resolved lifecycle states of a resource.
ReversibleState
module-attribute
ReversibleState = Literal[
RESOLVED, INITIALIZING, LOADING, BUILDING, FINALIZING
]
A literal type for the reversible lifecycle states of a resource.
SchedulableState
module-attribute
SchedulableState = Literal[
INITIALIZING, LOADING, BUILDING, FINALIZING, READY
]
A literal type for the lifecycle states of a resource where tasks can be scheduled for execution.
Task
module-attribute
A task to be scheduled for execution.
apps
module-attribute
apps: AppMap
The applications initialized in the runtime environment.
A read-only module property that returns a dictionary mapping the application names to their respective application instances.
dependencies
module-attribute
dependencies: ResourceLinkMap
The resource dependencies initialized in the runtime environment.
A read-only module property that returns a dictionary mapping the fully
qualified names of all resources to their weak sets of linked resource fields
they rely on ("dependencies"). Essentially, this attribute tracks what linked
fields each resource needs to function properly, with each linked field owner
attribute being the resource itself and its name the mapping entry.
dependents
module-attribute
dependents: ResourceLinkMap
The resource dependents initialized in the runtime environment.
A read-only module property that returns a dictionary mapping the fully
qualified names of all resources to a weak sets of linked resource fields that
rely on those ("dependents"). Essentially, this attribute tracks what linked
fields will be affected if a resource is modified or made unavailable, with
each linked field target
attribute being the resource itself and its name the
mapping entry.
namespaces
module-attribute
namespaces: NamespaceMap
The namespaces initialized in the runtime environment.
A read-only module property that returns a dictionary mapping the namespace aliases to their respective namespace instances.
packages
module-attribute
packages: PackageMap
The packages initialized in the runtime environment.
A read-only module property that returns a dictionary mapping the package module names to their respective package instances.
resources
module-attribute
resources: ResourceMap
The resources initialized in the runtime environment.
A read-only module property that returns a weak dictionary mapping the
resource fully qualified names to their respective resource type, or None
if the resource is not yet resolved.
Action
dataclass
Action(
*,
func: Callable[..., Any],
bound: bool = False,
args: tuple[Any, ...] = tuple(),
kwargs: dict[str, Any] = dict(),
)
A class that represents an action.
This class is used to store a function with specific arguments and keyword arguments for later execution.
func
class-attribute
instance-attribute
The function to be executed.
bound
class-attribute
instance-attribute
Whether the function should be bound to the first argument.
args
class-attribute
instance-attribute
The positional arguments to be passed to the function.
Lifecycle
Bases: IntEnum
An enumeration of resources lifecycle states in the runtime.
UNKNOWN
class-attribute
instance-attribute
The resource status is unknown and has not been set. This status is returned when the resource state of a dependency is not yet resolved.
RESOLVED
class-attribute
instance-attribute
The resource is resolved and waiting for initialization. This is the default state of a resource when it has been first visited and before it is initializing, i.e. when not all its resource dependencies are resolved.
INITIALIZING
class-attribute
instance-attribute
The resource is in its initializing transition state, its base model is built and declarative model set up, and all the resource dependencies are resolved. It will transition to the next state when all its dependencies are also in their initializing state.
LOADING
class-attribute
instance-attribute
The resource is in its loading transition state, its objects and schemas are loaded, i.e. the resource own defined route endpoint methods, and the specifications, schema models and services defined in its configuration are loaded. This state is set when all resource dependencies are at least in their initializing state, and will transition to the next state when all its dependencies are also in their loading state.
BUILDING
class-attribute
instance-attribute
The resource is in its building transition state, its model, objects, and schemas are built. The resource is waiting for all its dependencies to be also built before finalizing its schema models and type adapter setup, and be ready for use. This step is necessary to ensure that all the resource dependencies schemas are fully loaded before building its own schema models.
FINALIZING
class-attribute
instance-attribute
The resource is in its finalizing transition state, its schema models and type adapter build are finalized. The resource is waiting for all its dependencies to be also finalized before transitioning to the ready state.
READY
class-attribute
instance-attribute
The resource is built and ready for use. Tasks scheduled in this state should not make changes that could disrupt dependent resources, as this is considered a stable state where the resource is available for use.
previous
previous() -> ReversibleState
Return the previous state of the current resource status.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
next
next() -> SchedulableState
Return the next state of the current resource status.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
lower
lower() -> tuple[ReversibleState, ...]
Return the lower states of the current resource status.
higher
higher() -> tuple[SchedulableState, ...]
Return the higher states of the current resource status.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
RegistryLock
Registry
The runtime environment registry internal class.
Attributes:
Name | Type | Description |
---|---|---|
instance |
Self | None
|
A reference to the singleton instance of the runtime environment registry. |
lock |
A lock object to ensure that managed class instances in the runtime registry are accessed and created in a thread-safe manner. |
Note
It enforce a singleton pattern to ensure that only one instance of the runtime environment registry is created and managed throughout the program. Additionally, it provides a thread-safe mechanism to create and access managed class instances in the runtime registry.
Initialize the runtime environment registry.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
get_dependencies
get_dependencies(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["links"],
status: tuple[Lifecycle, ...] | None = None,
max_depth: int | None = 1,
) -> set[ResourceFieldInfo]
get_dependencies(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["resources"],
status: tuple[ResolvedState, ...],
max_depth: int | None = 1,
) -> set[ResourceType]
get_dependencies(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["resources"],
status: tuple[Literal[UNKNOWN], ...],
max_depth: int | None = 1,
) -> set[str]
get_dependencies(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["resources"],
status: tuple[Lifecycle, ...] | None = None,
max_depth: int | None = 1,
) -> set[ResourceType | str]
get_dependencies(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["links", "resources", "packages"],
status: tuple[Lifecycle, ...] | None = None,
max_depth: int | None = 1,
) -> (
set[ResourceFieldInfo]
| set[ResourceType | str]
| set[ResourceType]
| set[str]
| set[Package]
)
Collect the dependencies from the provided scope.
This method returns the dependencies of the provided scope based on the
specified kind. It filters the runtime dependencies
class dictionary to
return only the dependencies of the scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scope
|
ResourceType | Package | Sequence[ResourceType | Package]
|
The scope to retrieve the dependencies from. It can be a single resource class, a package, or a sequence of resource classes or packages. If a package is provided, it retrieves the dependencies of all the resource classes within the package. |
required |
kind
|
Literal['links', 'resources', 'packages']
|
The kind of dependencies to retrieve. It can be one of the
following values
- |
required |
_guard
|
set[str] | None
|
A set of fully qualified names of resources to guard against cyclic dependencies. It is used internally to prevent infinite recursion. Defaults to an empty set. |
None
|
status
|
tuple[Lifecycle, ...] | None
|
The tuple of dependencies lifecycle status to filter. Note that
only the |
None
|
max_depth
|
int | None
|
The maximum depth of dependencies to retrieve. If set to
|
1
|
Returns:
Type | Description |
---|---|
set[ResourceFieldInfo] | set[ResourceType | str] | set[ResourceType] | set[str] | set[Package]
|
The specified kind dependencies of the provided scope. |
Raises:
Type | Description |
---|---|
ValueError
|
If the lifecycle status is invalid, i.e. when the
filter includes |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
get_dependents
get_dependents(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["links"],
status: tuple[ResolvedState, ...] | None = None,
max_depth: int | None = 1,
) -> set[ResourceFieldInfo]
get_dependents(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["resources"],
status: tuple[ResolvedState, ...] | None = None,
max_depth: int | None = 1,
) -> set[ResourceType]
get_dependents(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["packages"],
status: tuple[ResolvedState, ...] | None = None,
max_depth: int | None = 1,
) -> set[Package]
get_dependents(
scope: ResourceType
| Package
| Sequence[ResourceType | Package],
_guard: set[str] | None = None,
*,
kind: Literal["links", "resources", "packages"],
status: tuple[ResolvedState, ...] | None = None,
max_depth: int | None = 1,
) -> (
set[ResourceFieldInfo]
| set[ResourceType]
| set[Package]
)
Collect the dependents from the provided scope.
This method returns the dependents of the provided scope based on the
specified kind. It filters the runtime dependents
class dictionary to
return only the dependents of the scope.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scope
|
ResourceType | Package | Sequence[ResourceType | Package]
|
The scope to retrieve the dependents from. It can be a single resource class, a package, or a sequence of resource classes or packages. If a package is provided, it retrieves the dependents of all the resource classes within the package. |
required |
kind
|
Literal['links', 'resources', 'packages']
|
The kind of dependents to retrieve. It can be one of the
following values
- |
required |
_guard
|
set[str] | None
|
A set of fully qualified names of resources to guard against cyclic dependents. It is used internally to prevent infinite recursion. Defaults to an empty set. |
None
|
status
|
tuple[ResolvedState, ...] | None
|
The tuple of dependents lifecycle status to filter. Note that
the |
None
|
max_depth
|
int | None
|
The maximum depth of dependents to retrieve. If set to
|
1
|
Returns:
Type | Description |
---|---|
set[ResourceFieldInfo] | set[ResourceType] | set[Package]
|
The specified kind dependents of the provided scope. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 |
|
get_resources
get_resources(
scope: Package | Sequence[Package] | None = None,
) -> set[ResourceType]
Collect the resources within the specified scope.
A method that filters the runtime resources
class dictionary with the
provided scope to return only the matching resources.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scope
|
Package | Sequence[Package] | None
|
The scope to retrieve the resources from. It can be a package,
a sequence of packages, or |
None
|
Returns:
Type | Description |
---|---|
set[ResourceType]
|
The resources within the specified scope. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
import_namespace
Import a namespace.
It resolves the namespace name to either an existing namespace instance, or
creates a new namespace with the specified name if it is not available in
the runtime environment and create_if_missing
flag is set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the namespace to be resolved. |
required |
create_if_missing
|
bool
|
When set to |
False
|
Returns:
Type | Description |
---|---|
Namespace
|
The namespace instance associated with the specified name. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
import_namespace_impl
import_namespace_impl(
name: str, context: Plateforme | None = None
) -> NamespaceImpl
Import a namespace implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the namespace implementation to be resolved. |
required |
context
|
Plateforme | None
|
The application context to use for the namespace
implementation. Defaults to |
None
|
Returns:
Type | Description |
---|---|
NamespaceImpl
|
The namespace implementation associated with the specified name and |
NamespaceImpl
|
application context. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
import_package
import_package(
name: str,
module: str | None = None,
*,
force_resolution: bool = False,
raise_warnings: bool = True,
) -> Package
Import the package from the specified module name.
When the module name is not recognized as a valid package module name, it raises an error if the resolution is not forced. Otherwise, it tries to resolve the specified module name to a valid one (i.e. a parent module that defines a project configuration file).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The exact name of the package module to be resolved. |
required |
module
|
str | None
|
The module to use as the anchor point for relative imports. |
None
|
force_resolution
|
bool
|
When set to |
False
|
raise_warnings
|
bool
|
Whether to log warnings when invalid package
configurations are encountered. Defaults to |
True
|
Returns:
Type | Description |
---|---|
Package
|
The package instance associated with the specified module name. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
|
import_package_impl
import_package_impl(
name: str, context: Plateforme | None = None
) -> PackageImpl
Import a package module name implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The exact name of the package module to be resolved. |
required |
context
|
Plateforme | None
|
The application context to use for the package implementation.
Defaults to |
None
|
Returns:
Type | Description |
---|---|
PackageImpl
|
The package implementation associated with the specified module name |
PackageImpl
|
and application context. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
clear_cache
Clear the runtime cache for debugging and testing purposes.
Source code in .venv/lib/python3.12/site-packages/plateforme/core/runtime.py
info
info() -> str
Prints detailed information about the runtime environment.