def test_pandamodels_installation():
    
    from julia import Main
    from julia import Pkg
    from julia import Base

    if Base.find_package("PandaModels"):  
        # remove PandaModels to reinstall it
        Pkg.rm("PandaModels")
        Pkg.resolve()

    else:
        print("PandaModels is not installed yet!")  
      
    Pkg.Registry.update()
    Pkg.add("PandaModels")  
    Pkg.build()
    Pkg.resolve()
    print("PandaModels is added to julia packages")

    try:
        Main.using("PandaModels")
        print("using PandaModels in its base mode!")
    except ImportError:
        raise ImportError("cannot use PandaModels in its base mode")
def test_pandamodels_dev_mode(): 
    
    from julia import Main
    from julia import Pkg
    from julia import Base

    if Base.find_package("PandaModels"):  
        # remove PandaModels to reinstall it
        Pkg.rm("PandaModels")
        Pkg.resolve()
        
    Pkg.Registry.update()
    Pkg.add("PandaModels")  
    print("installing dev mode is a slow process!")  
    Pkg.resolve()
    Pkg.develop("PandaModels")
    # add pandamodels dependencies: slow process
    Pkg.instantiate()            
    Pkg.build()
    Pkg.resolve()
    print("dev mode of PandaModels is added to julia packages")

    try:
        Pkg.activate("PandaModels")
        Main.using("PandaModels")
        print("using PandaModels in its dev mode!")
    except ImportError:
        # assert False
        raise ImportError("cannot use PandaModels in its dev mode")
      
    # activate julia base mode
    Pkg.activate()
    Pkg.free("PandaModels")
    Pkg.resolve()
Пример #3
0
def _call_pandamodels(buffer_file, julia_file, dev_mode):  # pragma: no cover

    try:
        import julia
        from julia import Main
        from julia import Pkg
        from julia import Base
    except ImportError:
        raise ImportError(
            "Please install pyjulia properly to run pandapower with PandaModels.jl."
        )

    try:
        julia.Julia()
    except:
        raise UserWarning(
            "Could not connect to julia, please check that Julia is installed and pyjulia is correctly configured"
        )

    if not Base.find_package("PandaModels"):
        logger.info(
            "PandaModels.jl is not installed in julia. It is added now!")
        Pkg.Registry.update()
        Pkg.add("PandaModels")

        if dev_mode:
            logger.info("installing dev mode is a slow process!")
            Pkg.resolve()
            Pkg.develop("PandaModels")
            # add pandamodels dependencies: slow process
            Pkg.instantiate()

        Pkg.build()
        Pkg.resolve()
        logger.info("Successfully added PandaModels")

    if dev_mode:
        Pkg.develop("PandaModels")
        Pkg.build()
        Pkg.resolve()
        Pkg.activate("PandaModels")

    try:
        Main.using("PandaModels")
    except ImportError:
        raise ImportError("cannot use PandaModels")

    Main.buffer_file = buffer_file
    result_pm = Main.eval(julia_file + "(buffer_file)")

    # if dev_mode:
    #     Pkg.activate()
    #     Pkg.free("PandaModels")
    #     Pkg.resolve()
    return result_pm