Skip to content

Commit bb411e7

Browse files
author
Christopher Doris
committed
juliacall settings from -X arguments to python; change setting NOINIT to INIT
1 parent 6c07d4e commit bb411e7

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

pysrc/juliacall/__init__.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,55 @@ def init():
4747
import sys
4848
import subprocess
4949

50+
def option(name, default=None):
51+
"""Get an option.
52+
53+
Options can be set as command line arguments '-X juliacall_{name}={value}' or as
54+
environment variables 'PYTHON_JULIACALL_{NAME}={value}'.
55+
"""
56+
k = 'juliacall_'+name.lower()
57+
v = sys._xoptions.get(k)
58+
if v is not None:
59+
return v
60+
k = 'PYTHON_JULIACALL_'+name.upper()
61+
v = os.getenv(k)
62+
if v is not None:
63+
return v
64+
return default
65+
66+
def choice(name, choices, default=None):
67+
k = option(name)
68+
if k is None:
69+
return default
70+
if k in choices:
71+
if isinstance(k, dict):
72+
return choices[k]
73+
else:
74+
return k
75+
raise ValueError(f'invalid value for option: JULIACALL_{name.upper()}={k}, expecting one of {", ".join(choices)}')
76+
77+
def path_option(name, default=None):
78+
path = option(name)
79+
if path is not None:
80+
return os.path.abspath(path)
81+
return default
82+
5083
# Determine if we should skip initialising.
51-
CONFIG['noinit'] = os.getenv('PYTHON_JULIACALL_NOINIT', '') == 'yes'
52-
if CONFIG['noinit']:
84+
CONFIG['init'] = choice('init', ['yes', 'no'], default='yes') == 'yes'
85+
if not CONFIG['init']:
5386
return
5487

88+
# Parse some more options
89+
CONFIG['opt_bindir'] = path_option('bindir') # TODO
90+
CONFIG['opt_check_bounds'] = choice('check_bounds', ['yes', 'no']) # TODO
91+
CONFIG['opt_compile'] = choice('compile', ['yes', 'no', 'all', 'min']) # TODO
92+
CONFIG['opt_compiled_modules'] = choice('compiled_modules', ['yes', 'no']) # TODO
93+
CONFIG['opt_depwarn'] = choice('depwarn', ['yes', 'no', 'error']) # TODO
94+
CONFIG['opt_inline'] = choice('inline', ['yes', 'no']) # TODO
95+
CONFIG['opt_optimize'] = choice('optimize', ['0', '1', '2', '3']) # TODO
96+
CONFIG['opt_sysimage'] = path_option('sysimage') # TODO
97+
CONFIG['opt_warn_overwrite'] = choice('warn_overwrite', ['yes', 'no']) # TODO
98+
5599
# Stop if we already initialised
56100
if CONFIG['inited']:
57101
return

src/juliacall.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ function init_juliacall()
2020
# prepend the directory containing juliacall to sys.path
2121
sys.path.insert(0, joinpath(ROOT_DIR, "pysrc"))
2222
# prevent juliacall from initialising itself
23-
os.environ["PYTHON_JULIACALL_NOINIT"] = "yes"
23+
os.environ["PYTHON_JULIACALL_INIT"] = "no"
2424
# import juliacall
2525
pycopy!(jl, pyimport("juliacall"))
2626
# check the version
2727
@assert realpath(pystr_asstring(jl.__path__[0])) == realpath(joinpath(ROOT_DIR, "pysrc", "juliacall"))
2828
@assert pystr_asstring(jl.__version__) == string(VERSION)
29-
@assert pybool_asbool(jl.CONFIG["noinit"])
29+
@assert pybool_asbool(jl.CONFIG["init"])
3030
end
3131
end
3232

0 commit comments

Comments
 (0)