1# Copyright 2015-2017 the openage authors. See copying.md for legal info.
2
3"""
4Contains the function that initializes the C++ interface.
5"""
6
7from ..util.decorators import run_once
8
9from ..log import dbg
10
11from ..log.log_cpp import enable_log_translation
12
13
14@run_once
15def setup(args):
16    """
17    After a call to setup(), the C++ interface is in a usable state.
18
19    setup() automatically checks whether there are any remaining un-initialized
20    PyFunc objects, and raises an Exception if so.
21
22    Must be invoked before any functions from libopenage are invoked.
23    Runs only once; any subsequent invocations are a no-op, so don't hesitate
24    to call this method whenever likely.
25
26    Do _not_ invoke from a .pyx extension module that itself provides
27    a setup method (circular imports)!
28    """
29    dbg("initializing libopenage...")
30
31    # this is where calls to the setup methods of all other modules belong.
32    from .exctranslate import setup as exctranslate_setup
33    exctranslate_setup(args)
34
35    from .exctranslate_tests import setup as exctranslate_tests_setup
36    exctranslate_tests_setup()
37
38    from .pyobject import setup as pyobject_setup
39    pyobject_setup()
40
41    from ..util.filelike.cpp import setup as filelike_setup
42    filelike_setup()
43
44    from ..util.fslike.cpp import setup as fslike_setup
45    fslike_setup()
46
47    from ..cvar.cvar import setup as cvar_setup
48    cvar_setup()
49
50    # verify that everything has been properly initialized.
51    from .setup_checker import check
52    check()
53
54    enable_log_translation()
55
56    dbg("C++ <-> Python interface has been initialized")
57