Skip to content

[FEATURE] Environment Variable Configuration Module (- WIP #31 -) #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion multicast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""__package__""", """__module__""", """__name__""", """__version__""", """__prologue__""",
"""__doc__""", """exceptions""", """exceptions.CommandExecutionError""",
"""exceptions.get_exit_code_from_exception""", """exceptions.exit_on_exception""",
"""get_exit_code_from_exception""", """exit_on_exception""",
"""get_exit_code_from_exception""", """exit_on_exception""", """env""",
"""skt""", """skt.__package__""", """skt.__module__""", """skt.__name__""",
"""skt.__file__""", """skt.genSocket""", """skt.genSocket.__func__""", """genSocket""",
"""skt.endSocket""", """skt.endSocket.__func__""", """endSocket""",
Expand Down Expand Up @@ -368,17 +368,48 @@
# pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
from . import exceptions # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global exceptions # skipcq: PYL-W0604
exceptions = sys.modules["""multicast.exceptions"""]

EXIT_CODES = exceptions.EXIT_CODES
"""See multicast.exceptions.EXIT_CODES."""

EXCEPTION_EXIT_CODES = exceptions.EXCEPTION_EXIT_CODES
"""See multicast.exceptions.EXCEPTION_EXIT_CODES."""

CommandExecutionError = exceptions.CommandExecutionError
"""See multicast.exceptions.CommandExecutionError Class."""

get_exit_code_from_exception = exceptions.get_exit_code_from_exception
"""See multicast.exceptions.get_exit_code_from_exception function."""

exit_on_exception = exceptions.exit_on_exception
"""See multicast.exceptions.exit_on_exception function."""


if 'multicast.env' not in sys.modules:
# pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
from . import env # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global env # skipcq: PYL-W0604
env = sys.modules["""multicast.env"""]

_config = env.load_config()

if _config is None:
raise ImportError("FAIL: we could not import environment. ABORT.") from None
else:
_MCAST_DEFAULT_PORT = _config["port"]
_MCAST_DEFAULT_GROUP = _config["group"]
_MCAST_DEFAULT_TTL = _config["ttl"]
global _MCAST_DEFAULT_BIND_IP # skipcq: PYL-W0604
_MCAST_DEFAULT_BIND_IP = _config["bind_addr"]
global _MCAST_DEFAULT_GROUPS # skipcq: PYL-W0604
_MCAST_DEFAULT_GROUPS = _config["groups"]
global _MCAST_DEFAULT_BUFFER # skipcq: PYL-W0604
_MCAST_DEFAULT_BUFFER = _config["buffer_size"]

del _config # skipcq - cleanup any bootstrap/setup leaks early


class mtool(abc.ABC):
Expand Down Expand Up @@ -627,6 +658,7 @@ def doStep(self, *args, **kwargs): # pragma: no cover
if 'multicast.skt' not in sys.modules:
from . import skt as skt # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global skt # skipcq: PYL-W0604
skt = sys.modules["""multicast.skt"""]


Expand All @@ -641,23 +673,27 @@ def doStep(self, *args, **kwargs): # pragma: no cover
if 'multicast.recv' not in sys.modules:
from . import recv as recv # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global recv # skipcq: PYL-W0604
recv = sys.modules["""multicast.recv"""]


if 'multicast.send' not in sys.modules:
from . import send as send # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global send # skipcq: PYL-W0604
send = sys.modules["""multicast.send"""]


if 'multicast.hear' not in sys.modules:
from . import hear as hear # pylint: disable=cyclic-import - skipcq: PYL-R0401, PYL-C0414
else: # pragma: no branch
global hear # skipcq: PYL-W0604
hear = sys.modules["""multicast.hear"""]


try:
if """multicast.__main__""" in sys.modules: # pragma: no cover
global __main__ # skipcq: PYL-W0604
__main__ = sys.modules["""multicast.__main__"""]
except Exception:
import multicast.__main__ as __main__ # pylint: disable=cyclic-import - skipcq: PYL-R0401
Expand Down
Loading
Loading