Skip to content
Snippets Groups Projects
Commit 0f0624b4 authored by Daniel Sali's avatar Daniel Sali
Browse files

Lazy initialization of the Julia environment on dynare() call

parent 24fb1814
No related branches found
No related tags found
1 merge request!9RC 0.2.0
import logging
import os # Added import
import os
import functools
from juliacall import Main as jl
from .dynare import dynare
......@@ -42,6 +43,16 @@ def setup_logging(
def check_julia_and_dynare():
"""
Check Julia installation and report on Dynare package status.
If you wish to use an existing conda environment with Julia and Dynare,
please set the environment variables appropriate for your setup as described at:
https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#pythoncall-config
Julia configuration can be customized as described at:
https://juliapy.github.io/PythonCall.jl/stable/juliacall/#julia-config
"""
# Check Julia
julia_path = jl.seval("Sys.BINDIR")
_ = jl.seval("Base.active_project()")
......@@ -55,14 +66,33 @@ def check_julia_and_dynare():
_has_run = False
def _run_once():
def ensure_initialized():
"""
Ensure Julia and Dynare packages are initialized.
This can be called explicitly by users who want to control when initialization happens.
"""
global _has_run
if not _has_run:
check_julia_and_dynare()
jl.seval("using Pkg")
_has_run = True
logger.debug("Julia environment initialized")
def lazy_init(func):
"""
Decorator to ensure initialization before calling a function.
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
ensure_initialized()
return func(*args, **kwargs)
return wrapper
_run_once()
# Make dynare function lazy-initialized
dynare = lazy_init(dynare)
__all__ = ["dynare", "setup_logging"]
__all__ = ["dynare", "setup_logging", "ensure_initialized"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment