Пример #1
0
def test_coreclr(example_dll):
    from clr_loader import get_coreclr

    coreclr = get_coreclr(os.path.join(example_dll, "example.runtimeconfig.json"))
    asm = coreclr.get_assembly(os.path.join(example_dll, "example.dll"))

    run_tests(asm)
Пример #2
0
def pytest_configure(config):
    global bin_path
    if "clr" in sys.modules:
        # Already loaded (e.g. by the C# test runner), skip build
        import clr
        clr.AddReference("Python.Test")
        return

    runtime_opt = config.getoption("runtime")

    test_proj_path = os.path.join(cwd, "..", "src", "testing")

    if runtime_opt not in ["netcore", "netfx", "mono", "default"]:
        raise RuntimeError(f"Invalid runtime: {runtime_opt}")

    bin_path = mkdtemp()

    # tmpdir_factory.mktemp(f"pythonnet-{runtime_opt}")

    fw = "net6.0" if runtime_opt == "netcore" else "netstandard2.0"

    check_call(["dotnet", "publish", "-f", fw, "-o", bin_path, test_proj_path])

    sys.path.append(bin_path)

    if runtime_opt == "default":
        pass
    elif runtime_opt == "netfx":
        from clr_loader import get_netfx
        runtime = get_netfx()
        set_runtime(runtime)
    elif runtime_opt == "mono":
        from clr_loader import get_mono
        runtime = get_mono()
        set_runtime(runtime)
    elif runtime_opt == "netcore":
        from clr_loader import get_coreclr
        rt_config_path = os.path.join(bin_path, "Python.Test.runtimeconfig.json")
        runtime = get_coreclr(rt_config_path)
        set_runtime(runtime)

    import clr
    clr.AddReference("Python.Test")

    soft_mode = False
    try:
        os.environ['PYTHONNET_SHUTDOWN_MODE'] == 'Soft'
    except: pass

    if config.getoption("--runtime") == "netcore" or soft_mode\
        :
        collect_ignore.append("domain_tests/test_domain_reload.py")
    else:
        domain_tests_dir = os.path.join(os.path.dirname(__file__), "domain_tests")
        bin_path = os.path.join(domain_tests_dir, "bin")
        build_cmd = ["dotnet", "build", domain_tests_dir, "-o", bin_path]
        is_64bits = sys.maxsize > 2**32
        if not is_64bits:
            build_cmd += ["/p:Prefer32Bit=True"]
        check_call(build_cmd)
Пример #3
0
def pythonnet_init():
    """correctly sets-up pythonnet for the typetree generator"""
    # prepare correct runtime
    from clr_loader import get_coreclr
    from pythonnet import set_runtime

    rt = get_coreclr(
        os.path.join(TYPETREE_GENERATOR_PATH,
                     "TypeTreeGenerator.runtimeconfig.json"))
    set_runtime(rt)
Пример #4
0
def _create_runtime_from_spec(
        spec: str,
        params: Optional[Dict[str, str]] = None) -> clr_loader.Runtime:
    if spec == "default":
        if sys.platform == "win32":
            spec = "netfx"
        else:
            spec = "mono"

    params = params or _get_params_from_env(spec)

    if spec == "netfx":
        return clr_loader.get_netfx(**params)
    elif spec == "mono":
        return clr_loader.get_mono(**params)
    elif spec == "coreclr":
        return clr_loader.get_coreclr(**params)
    else:
        raise RuntimeError(f"Invalid runtime name: '{spec}'")
Пример #5
0
# in order to reference QuantConnect assemblies
#
# Usage:
# %run "start.py"

import clr_loader
import os
from pythonnet import set_runtime

# The runtimeconfig.json is stored alongside start.py, but start.py may be a
# symlink and the directory start.py is stored in is not necessarily the
# current working directory. We therefore construct the absolute path to the
# start.py file, and find the runtimeconfig.json relative to that.
set_runtime(
    clr_loader.get_coreclr(
        os.path.join(os.path.dirname(os.path.realpath(__file__)),
                     "QuantConnect.Lean.Launcher.runtimeconfig.json")))

from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Api")
AddReference("QuantConnect.Common")
AddReference("QuantConnect.Configuration")
AddReference("QuantConnect.Research")
AddReference("QuantConnect.Indicators")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Api import *
Пример #6
0
from clr_loader import get_coreclr
from pythonnet import set_runtime

import sys
import clr

rt = get_coreclr(r"/usr/local/bin/REnv.runtimeconfig.json")
set_runtime(rt)

sys.path.append(r"/usr/local/bin/")
sys.path.append(r"/etc/r_env/library/ggplot/lib/assembly/")

clr.AddReference(r"REnv.dll")

# test R# engine
from REnv import ExportsClr

renv = ExportsClr()
print(renv.__class__.__name__)
result = renv.HelloWorld()
print(result)
Пример #7
0
from PIL import Image
from pythonnet import set_runtime
from clr_loader import get_coreclr
from PIL.Image import FLOYDSTEINBERG, MEDIANCUT

if os.sys.platform == "linux" and os.geteuid() != 0:
    os.sys.exit("This program must run as root")

# setup path for dll files when it is a pyinstaller executable
if getattr(os.sys, 'frozen', False):
    basedir = os.sys._MEIPASS
else:
    basedir = os.path.dirname(os.path.abspath(__file__))
    basedir = str(basedir)

rt = get_coreclr(f"{basedir}/Calc2KeyCE.runtimeconfig.json")
set_runtime(rt)

import clr

clr.AddReference("Calc2KeyCE.Compression")

from Calc2KeyCE.Compression import *

run = True


@atexit.register
def onexit():
    run = False
    if dev is not None: