e7299b17e9
Stack installed: - netfox v1.35.3 (core + extras + noray + internals) - godot-jolt v0.16.0-stable Architecture: - Server: ENet transport (works headless, no netfox deps) - Client/Editor: netfox rollback (RollbackSynchronizer, TickInterpolator) New/modified: - docs/migration-netfox-plan.md — migration architecture - scripts/network/network_manager.gd — netfox-aware ENet fallback - scripts/network/player.gd — clean base player - client/characters/player_netfox.gd — rollback player w/ WeaponManager - client/characters/input/player_net_input.gd — BaseNetInput subclass - client/characters/character/fps_character_controller.gd — netfox input feed - client/weapons/ — weapon data, registry, TacticalWeaponHitscan, WeaponManager - client/scripts/round_replicator.gd — client-side round state bridge - server/scripts/round_manager.gd — improved state machine - server/scripts/plugin_api/plugin_manager.gd — refined plugin system - config: enemy_tag, ally_tag for meatball targeting Removed: old C++ SimulationServer GDExtension (replaced by netfox rollback)
101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
import warnings
|
|
from collections.abc import Iterable
|
|
from typing import Any
|
|
|
|
|
|
__all__ = ["lazy_import"]
|
|
|
|
|
|
def import_name(name: str, source: str, namespace: dict[str, Any]) -> Any:
|
|
"""
|
|
Import ``name`` from ``source`` in ``namespace``.
|
|
|
|
There are two use cases:
|
|
|
|
- ``name`` is an object defined in ``source``;
|
|
- ``name`` is a submodule of ``source``.
|
|
|
|
Neither :func:`__import__` nor :func:`~importlib.import_module` does
|
|
exactly this. :func:`__import__` is closer to the intended behavior.
|
|
|
|
"""
|
|
level = 0
|
|
while source[level] == ".":
|
|
level += 1
|
|
assert level < len(source), "importing from parent isn't supported"
|
|
module = __import__(source[level:], namespace, None, [name], level)
|
|
return getattr(module, name)
|
|
|
|
|
|
def lazy_import(
|
|
namespace: dict[str, Any],
|
|
aliases: dict[str, str] | None = None,
|
|
deprecated_aliases: dict[str, str] | None = None,
|
|
) -> None:
|
|
"""
|
|
Provide lazy, module-level imports.
|
|
|
|
Typical use::
|
|
|
|
__getattr__, __dir__ = lazy_import(
|
|
globals(),
|
|
aliases={
|
|
"<name>": "<source module>",
|
|
...
|
|
},
|
|
deprecated_aliases={
|
|
...,
|
|
}
|
|
)
|
|
|
|
This function defines ``__getattr__`` and ``__dir__`` per :pep:`562`.
|
|
|
|
"""
|
|
if aliases is None:
|
|
aliases = {}
|
|
if deprecated_aliases is None:
|
|
deprecated_aliases = {}
|
|
|
|
namespace_set = set(namespace)
|
|
aliases_set = set(aliases)
|
|
deprecated_aliases_set = set(deprecated_aliases)
|
|
|
|
assert not namespace_set & aliases_set, "namespace conflict"
|
|
assert not namespace_set & deprecated_aliases_set, "namespace conflict"
|
|
assert not aliases_set & deprecated_aliases_set, "namespace conflict"
|
|
|
|
package = namespace["__name__"]
|
|
|
|
def __getattr__(name: str) -> Any:
|
|
assert aliases is not None # mypy cannot figure this out
|
|
try:
|
|
source = aliases[name]
|
|
except KeyError:
|
|
pass
|
|
else:
|
|
return import_name(name, source, namespace)
|
|
|
|
assert deprecated_aliases is not None # mypy cannot figure this out
|
|
try:
|
|
source = deprecated_aliases[name]
|
|
except KeyError:
|
|
pass
|
|
else:
|
|
warnings.warn(
|
|
f"{package}.{name} is deprecated",
|
|
DeprecationWarning,
|
|
stacklevel=2,
|
|
)
|
|
return import_name(name, source, namespace)
|
|
|
|
raise AttributeError(f"module {package!r} has no attribute {name!r}")
|
|
|
|
namespace["__getattr__"] = __getattr__
|
|
|
|
def __dir__() -> Iterable[str]:
|
|
return sorted(namespace_set | aliases_set | deprecated_aliases_set)
|
|
|
|
namespace["__dir__"] = __dir__
|