@@ -47,11 +47,55 @@ def init():
47
47
import sys
48
48
import subprocess
49
49
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
+
50
83
# 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 ' ]:
53
86
return
54
87
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
+
55
99
# Stop if we already initialised
56
100
if CONFIG ['inited' ]:
57
101
return
0 commit comments