mirror of https://github.com/m-labs/artiq.git
inject fake module for experiments submitted by content
This commit is contained in:
parent
34d0ba9563
commit
28c9de3e25
|
@ -102,7 +102,11 @@ class Core:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
if not self.analyzed:
|
if not self.analyzed:
|
||||||
self.compiler.analyze(core_language._registered_functions, core_language._registered_classes)
|
self.compiler.analyze(
|
||||||
|
core_language._registered_functions,
|
||||||
|
core_language._registered_classes,
|
||||||
|
core_language._registered_modules
|
||||||
|
)
|
||||||
self.analyzed = True
|
self.analyzed = True
|
||||||
|
|
||||||
if hasattr(method, "__self__"):
|
if hasattr(method, "__self__"):
|
||||||
|
|
|
@ -56,6 +56,7 @@ def ceil64(x):
|
||||||
# Delay NAC3 analysis until all referenced variables are supposed to exist on the CPython side.
|
# Delay NAC3 analysis until all referenced variables are supposed to exist on the CPython side.
|
||||||
_registered_functions = set()
|
_registered_functions = set()
|
||||||
_registered_classes = set()
|
_registered_classes = set()
|
||||||
|
_registered_modules = set()
|
||||||
|
|
||||||
def _register_function(fun):
|
def _register_function(fun):
|
||||||
import_cache.add_module_to_cache(getmodule(fun))
|
import_cache.add_module_to_cache(getmodule(fun))
|
||||||
|
@ -65,6 +66,11 @@ def _register_class(cls):
|
||||||
import_cache.add_module_to_cache(getmodule(cls))
|
import_cache.add_module_to_cache(getmodule(cls))
|
||||||
_registered_classes.add(cls)
|
_registered_classes.add(cls)
|
||||||
|
|
||||||
|
def register_content_module(module):
|
||||||
|
# for kernels sent by content, they have no modules
|
||||||
|
# thus their source must be analyzed instead
|
||||||
|
_registered_modules.add(module)
|
||||||
|
|
||||||
|
|
||||||
def extern(function):
|
def extern(function):
|
||||||
"""Decorates a function declaration defined by the core device runtime."""
|
"""Decorates a function declaration defined by the core device runtime."""
|
||||||
|
|
|
@ -30,7 +30,9 @@ from artiq.master.worker_db import DeviceManager, DatasetManager, DummyDevice
|
||||||
from artiq.language.environment import (
|
from artiq.language.environment import (
|
||||||
is_public_experiment, TraceArgumentManager, ProcessArgumentManager
|
is_public_experiment, TraceArgumentManager, ProcessArgumentManager
|
||||||
)
|
)
|
||||||
from artiq.language.core import set_watchdog_factory, TerminationRequested
|
from artiq.language.core import (
|
||||||
|
register_content_module, set_watchdog_factory, TerminationRequested
|
||||||
|
)
|
||||||
from artiq.language import import_cache
|
from artiq.language import import_cache
|
||||||
from artiq import __version__ as artiq_version
|
from artiq import __version__ as artiq_version
|
||||||
|
|
||||||
|
@ -166,6 +168,7 @@ def get_experiment_from_content(content, class_name):
|
||||||
StringLoader(fake_filename, content)
|
StringLoader(fake_filename, content)
|
||||||
)
|
)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
register_content_module(module)
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
linecache.lazycache(fake_filename, module.__dict__)
|
linecache.lazycache(fake_filename, module.__dict__)
|
||||||
return tools.get_experiment(module, class_name)
|
return tools.get_experiment(module, class_name)
|
||||||
|
|
Loading…
Reference in New Issue