Exemplo n.º 1
0
    def cached_module_file(self, do_cache_namespaces, cached_module_ns,
                           make_new_module):
        file_path = ("importer", "namespace", "using_cache.lpy")
        make_new_module(*file_path, ns_name=cached_module_ns)

        # Import the module out of the current process to avoid having to
        # monkeypatch sys.modules
        p = Process(target=_import_module, args=(munge(cached_module_ns), ))
        p.start()
        p.join()
        return os.path.join(*file_path)
Exemplo n.º 2
0
def bootstrap(target: str,
              opts: Optional[CompilerOpts] = None) -> None:  # pragma: no cover
    """
    Import a Basilisp namespace or function identified by `target`.

    Basilisp only needs to be bootstrapped once per Python VM invocation. Subsequent
    imports of Basilisp namespaces will work using Python's standard `import` statement
    and `importlib.import_module` function.

    `target` must be a string naming a Basilisp namespace. Namespace references may
    be given exactly as they are found in Basilisp code. `target` may optionally
    include a trailing function reference, delimited by ":", which will be executed
    after the target namespace is imported. If a function reference is given, the
    function will be called with no arguments.

    `opts` is a mapping of compiler options that may be supplied for bootstrapping.
    This setting should be left alone unless you know what you are doing.
    """
    init(opts=opts)
    pkg_name, *rest = target.split(":", maxsplit=1)
    mod = importlib.import_module(munge(pkg_name))
    if rest:
        fn_name = munge(rest[0])
        getattr(mod, fn_name)()
Exemplo n.º 3
0
 def _load_namespace(ns_name: str):
     """Load the named Namespace and return it."""
     namespaces.append(ns_name)
     importlib.import_module(munge(ns_name))
     return runtime.Namespace.get(sym.symbol(ns_name))
Exemplo n.º 4
0
def test_munge_disallows_python_kws():
    for kw in keyword.kwlist:
        assert f"{kw}_" == munge(kw)
Exemplo n.º 5
0
def test_munge_disallows_python_builtins():
    for name in builtins.__dict__.keys():
        assert f"{name}_" == munge(name)
Exemplo n.º 6
0
def test_munge_disallows_syms(expected, input):
    assert expected == munge(input)