@@ -64,7 +64,7 @@ def init():
6464 "For updates, see https://github.com/pytorch/pytorch/issues/78829."
6565 )
6666
67- def option (name , default = None , xkey = None , envkey = None ):
67+ def option (name , default = None , xkey = None , envkey = None , allowflag = False ):
6868 """Get an option.
6969
7070 Options can be set as command line arguments '-X juliacall-{name}={value}' or as
@@ -73,13 +73,28 @@ def option(name, default=None, xkey=None, envkey=None):
7373 k = xkey or 'juliacall-' + name .lower ().replace ('_' , '-' )
7474 v = sys ._xoptions .get (k )
7575 if v is not None :
76+ if v is True :
77+ if not allowflag :
78+ raise ValueError (f'-X{ k } : expecting an argument' )
79+ return True , f'-X{ k } '
7680 return v , f'-X{ k } ={ v } '
7781 k = envkey or 'PYTHON_JULIACALL_' + name .upper ()
7882 v = os .getenv (k )
7983 if v is not None :
8084 return v , f'{ k } ={ v } '
8185 return default , f'<default>={ default } '
8286
87+ def flag (name , default = None , ** kw ):
88+ v , s = option (name , allowflag = True , ** kw )
89+ if v is None :
90+ return default , s
91+ elif v is True or v == 'yes' :
92+ return True , s
93+ elif v == 'no' :
94+ return False , s
95+ else :
96+ raise ValueError (f'{ s } : expecting yes or no' )
97+
8398 def choice (name , choices , default = None , ** kw ):
8499 v , s = option (name , ** kw )
85100 if v is None :
@@ -128,7 +143,11 @@ def args_from_config(config):
128143 val = 'no'
129144 else :
130145 continue
131- argv .append ('--' + opt [4 :].replace ('_' , '-' ) + '=' + val )
146+ arg = '--' + opt [4 :].replace ('_' , '-' )
147+ if val is True :
148+ argv .append (arg )
149+ elif val is not None :
150+ argv .append (f"{ arg } ={ val } " )
132151 argv = [s .encode ("utf-8" ) for s in argv ]
133152
134153 argc = len (argv )
@@ -145,6 +164,8 @@ def args_from_config(config):
145164 CONFIG ['opt_home' ] = bindir = path_option ('home' , check_exists = True , envkey = 'PYTHON_JULIACALL_BINDIR' )[0 ]
146165 CONFIG ['opt_check_bounds' ] = choice ('check_bounds' , ['yes' , 'no' , 'auto' ])[0 ]
147166 CONFIG ['opt_compile' ] = choice ('compile' , ['yes' , 'no' , 'all' , 'min' ])[0 ]
167+ CONFIG ["opt_trace_compile" ] = option ('trace_compile' )[0 ]
168+ CONFIG ["opt_trace_compile_timing" ] = flag ('trace_compile_timing' )[0 ]
148169 CONFIG ['opt_compiled_modules' ] = choice ('compiled_modules' , ['yes' , 'no' ])[0 ]
149170 CONFIG ['opt_depwarn' ] = choice ('depwarn' , ['yes' , 'no' , 'error' ])[0 ]
150171 CONFIG ['opt_inline' ] = choice ('inline' , ['yes' , 'no' ])[0 ]
0 commit comments