JuliaPy / PythonCall.jl

Python and Julia in harmony.
https://juliapy.github.io/PythonCall.jl/stable/
MIT License
732 stars 61 forks source link

Is there a systematic way to check whether julia code is called via JuliaCall versus normal Julia? #517

Open schlichtanders opened 3 weeks ago

schlichtanders commented 3 weeks ago

motivation: build juliacode which has some specific behaviour when run via JuliaCall reusing the same code simplifies the interface as well as the code size

cjdoris commented 2 weeks ago

There is no API for this. The only way I can think of is to first check if PythonCall is in Base.loaded_modules (or just import PythonCall) then check PythonCall.C.CTX.is_embedded which is true if you are in JuliaCall.

cjdoris commented 2 weeks ago

(This is relying on internals of both Base and PythonCall.)

cjdoris commented 2 weeks ago

Oh another way is to do exactly what PythonCall itself does: hasproperty(Base.Main, :__PythonCall_libptr) is true if you are in JuliaCall.

Again, this relies on internals.

schlichtanders commented 2 weeks ago

thank you very much. Great that at least there is way which kind of works. I guess it is fine for me to rely on internals for now.