@@ -96,6 +96,16 @@ def path_option(name, default=None, check_exists=False, **kw):
9696 raise ValueError (f'{ s } : path does not exist' )
9797 return os .path .abspath (path ), s
9898 return default , s
99+
100+ def executable_option (name , default = None , ** kw ):
101+ import shutil
102+ _path , s = option (name , ** kw )
103+ if _path is not None :
104+ path = shutil .which (_path )
105+ if path is None :
106+ raise ValueError (f'{ s } : executable not found' )
107+ return os .path .abspath (path ), s
108+ return default , s
99109
100110 def int_option (name , * , accept_auto = False , ** kw ):
101111 val , s = option (name , ** kw )
@@ -147,18 +157,31 @@ def args_from_config(config):
147157 CONFIG ['opt_handle_signals' ] = choice ('handle_signals' , ['yes' , 'no' ])[0 ]
148158 CONFIG ['opt_startup_file' ] = choice ('startup_file' , ['yes' , 'no' ])[0 ]
149159 CONFIG ['opt_heap_size_hint' ] = option ('heap_size_hint' )[0 ]
160+ CONFIG ['project' ] = path_option ('project' , check_exists = True )[0 ]
161+ CONFIG ['exepath' ] = executable_option ('exe' )[0 ]
150162
151163 # Stop if we already initialised
152164 if CONFIG ['inited' ]:
153165 return
154166
155- # we don't import this at the top level because it is not required when juliacall is
156- # loaded by PythonCall and won't be available
157- import juliapkg
167+ have_exepath = CONFIG ['exepath' ] is not None
168+ have_project = CONFIG ['project' ] is not None
169+ if have_exepath and have_project :
170+ pass
171+ elif (not have_exepath ) and (not have_project ):
172+ # we don't import this at the top level because it is not required when
173+ # juliacall is loaded by PythonCall and won't be available, or if both
174+ # `exepath` and `project` are set by the user.
175+ import juliapkg
176+
177+ # Find the Julia executable and project
178+ CONFIG ['exepath' ] = juliapkg .executable ()
179+ CONFIG ['project' ] = juliapkg .project ()
180+ else :
181+ raise Exception ("Both PYTHON_JULIACALL_PROJECT and PYTHON_JULIACALL_EXE must be set together, not only one of them." )
158182
159- # Find the Julia executable and project
160- CONFIG ['exepath' ] = exepath = juliapkg .executable ()
161- CONFIG ['project' ] = project = juliapkg .project ()
183+ exepath = CONFIG ['exepath' ]
184+ project = CONFIG ['project' ]
162185
163186 # Find the Julia library
164187 cmd = [exepath , '--project=' + project , '--startup-file=no' , '-O0' , '--compile=min' ,
0 commit comments