How to use julia - 10 common examples

To help you get started, we’ve selected a few julia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JuliaPy / pyjulia / test / test_python_jl.py View on Github external
import os
import shlex
import subprocess

import pytest

from julia.core import which
from julia.python_jl import parse_pyjl_args

is_windows = os.name == "nt"

PYJULIA_TEST_REBUILD = os.environ.get("PYJULIA_TEST_REBUILD", "no") == "yes"

python_jl_required = pytest.mark.skipif(
    os.environ.get("PYJULIA_TEST_PYTHON_JL_IS_INSTALLED", "no") != "yes"
    and not which("python-jl"),
    reason="python-jl command not found",
)


@pytest.mark.parametrize("args", [
    "-h",
    "-i --help",
    "--julia false -h",
    "--julia false -i --help",
])
def test_help_option(args, capsys):
    with pytest.raises(SystemExit) as exc_info:
        parse_pyjl_args(shlex.split(args))
    assert exc_info.value.code == 0

    captured = capsys.readouterr()
github thautwarm / restrain-jit / tests / bejl / test_array_op.py View on Github external
# print(test_repeat_append_jit())

# print(test_repeat_append_jit_foreach())
#
# for e in (test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs):
#     print(e)
# show_instrs(test_repeat_append_jit_foreach.__func_info__.r_codeinfo.instrs)
#
# %timeit test_repeat_append_jit()
# %timeit test_repeat_append_nojit()
# %timeit test_repeat_append_jit_foreach()

from julia import Main

tt = Main.eval("""
function tt()
    x = []
    for i in 0:9999
        push!(x, i)
    end
    x
end
""")
tt()

import timeit

print(timeit.timeit("tt()", globals=dict(tt=tt), number=1000))
print(timeit.timeit(
    "tt()", globals=dict(tt=test_repeat_append_nojit), number=1000))
github JuliaPy / pyjulia / test / test_juliainfo.py View on Github external
env_var = subprocess.check_output(
        [runtime, "--startup-file=no", "-e", """
        if VERSION < v"0.7-"
            println("JULIA_PKGDIR")
            print(ARGS[1])
        else
            paths = [ARGS[1], DEPOT_PATH[2:end]...]
            println("JULIA_DEPOT_PATH")
            print(join(paths, Sys.iswindows() ? ';' : ':'))
        end
        """, str(tmpdir)],
        env=_enviorn,
        universal_newlines=True)
    name, val = env_var.split("\n", 1)

    jlinfo = JuliaInfo.load(
        runtime,
        env=dict(_enviorn, **{name: val}))

    check_core_juliainfo(jlinfo)
    assert jlinfo.python is None
    assert jlinfo.libpython_path is None
github JuliaPy / pyjulia / test / test_pseudo_python_cli.py View on Github external
def test_help_option(args, capsys):
    with pytest.raises(SystemExit) as exc_info:
        parse_args(shlex.split(args))
    assert exc_info.value.code == 0

    captured = capsys.readouterr()
    assert "usage:" in captured.out
    assert not captured.err
github JuliaPy / pyjulia / test / test_pseudo_python_cli.py View on Github external
def test_valid_args(args, desired):
    ns = parse_args(shlex.split(args))
    actual = vars(ns)
    assert actual == desired
github JuliaPy / pyjulia / test / test_pseudo_python_cli.py View on Github external
def test_invalid_args(args, capsys):
    with pytest.raises(SystemExit) as exc_info:
        parse_args(shlex.split(args))
    assert exc_info.value.code != 0

    captured = capsys.readouterr()
    assert "usage:" in captured.err
    assert not captured.out
github JuliaPy / pyjulia / test / test_pseudo_python_cli.py View on Github external
def test_version_option(args, capsys):
    with pytest.raises(SystemExit) as exc_info:
        parse_args(shlex.split(args))
    assert exc_info.value.code == 0

    captured = capsys.readouterr()
    assert "Python " in captured.out
    assert not captured.err
github JuliaPy / pyjulia / test / test_juliainfo.py View on Github external
"""

    runtime = os.getenv("PYJULIA_TEST_RUNTIME", "julia")

    env_var = subprocess.check_output(
        [runtime, "--startup-file=no", "-e", """
        if VERSION < v"0.7-"
            println("JULIA_PKGDIR")
            print(ARGS[1])
        else
            paths = [ARGS[1], DEPOT_PATH[2:end]...]
            println("JULIA_DEPOT_PATH")
            print(join(paths, Sys.iswindows() ? ';' : ':'))
        end
        """, str(tmpdir)],
        env=_enviorn,
        universal_newlines=True)
    name, val = env_var.split("\n", 1)

    jlinfo = JuliaInfo.load(
        runtime,
        env=dict(_enviorn, **{name: val}))

    check_core_juliainfo(jlinfo)
    assert jlinfo.python is None
    assert jlinfo.libpython_path is None
github JuliaPy / pyjulia / test / test_juliainfo.py View on Github external
if VERSION < v"0.7-"
            println("JULIA_PKGDIR")
            print(ARGS[1])
        else
            paths = [ARGS[1], DEPOT_PATH[2:end]...]
            println("JULIA_DEPOT_PATH")
            print(join(paths, Sys.iswindows() ? ';' : ':'))
        end
        """, str(tmpdir)],
        env=_enviorn,
        universal_newlines=True)
    name, val = env_var.split("\n", 1)

    jlinfo = JuliaInfo.load(
        runtime,
        env=dict(_enviorn, **{name: val}))

    check_core_juliainfo(jlinfo)
    assert jlinfo.python is None
    assert jlinfo.libpython_path is None
github JuliaPy / pyjulia / test / test_compatible_exe.py View on Github external
Check if Python `executable` is (likely to be) dynamically linked.

    It returns three possible values:

    * `True`: Likely that it's dynamically linked.
    * `False`: Likely that it's statically linked.
    * `None`: Unsupported platform.

    It's only "likely" since the check is by simple occurrence of a
    some substrings like "libpython".  For example, if there is
    another library existing on the path containing "libpython", this
    function may return false-positive.
    """
    path = which(executable)
    assert os.path.exists(path)
    if is_linux and which("ldd"):
        proc = run(
            ["ldd", path], stdout=subprocess.PIPE, env=_enviorn, universal_newlines=True
        )
        print_completed_proc(proc)
        return "libpython" in proc.stdout
    elif is_apple and which("otool"):
        proc = run(
            ["otool", "-L", path],
            stdout=subprocess.PIPE,
            env=_enviorn,
            universal_newlines=True,
        )
        print_completed_proc(proc)
        return (
            "libpython" in proc.stdout
            or "/Python" in proc.stdout