Open dingraha opened 1 year ago
Yeah CondaPkg/JuliaPkg doesn't support recursive Julia -> Python -> Julia dependencies. It's too hard.
I think the best solution right now is to add OpenMDAOCore as a dependency to OpenMDAO.
Gotcha, thanks. To be clear, OpenMDAOCore.jl was always a dependency of OpenMDAO.jl. The error occurs when installing OpenMDAO.jl in an environment where OpenMDAOCore.jl isn't explicitly installed (i.e., where OpenMDAOCore.jl isn't in the environment's Project.toml). The solution I came up with was adding this to OpenMDAO.jl:
function __init__()
PythonCall.pycopy!(om, PythonCall.pyimport("openmdao.api"))
Pkg.add("OpenMDAOCore")
PythonCall.pycopy!(omjlcomps, PythonCall.pyimport("omjlcomps"))
end
which I think installs OpenMDAOCore.jl in the current environment just before attempting to import the python package omjlcomps.
I'm fine with that solution, just want to make sure that's what you're suggesting.
Oh I see! Even though OpenMDAOCore is a dep of OpenMDAO, if you install OpenMDAO into some other project, then import OpenMDAOCore
fails because it's not a direct dependency in the project. That is annoying. I'm not sure there's anything I could change in PythonCall to make this work, but will have a think.
You could use Base.require
to import OpenMDAOCore
instead. This circumvents these checks.
Edit: I'd recommend against stuff like calling Pkg
from __init__
.
Also, is it important to have these 3 separate packages. Could you instead have one OpenMDAO
package with all of this stuff in?
You could use Base.require to import OpenMDAOCore instead. This circumvents these checks.
Interesting, I haven't heard of Base.require
. How would I do that? I see it takes a module and a symbol (the name of the module I want to load, :OpenMDAOCore
in this case?) https://docs.julialang.org/en/v1/base/base/#Base.require. What would the first argument be, and where would I put it? At the top of OpenMDAO.jl?
Also, is it important to have these 3 separate packages. Could you instead have one OpenMDAO package with all of this stuff in?
That's how it was set up originally, but it wasn't great for a couple of reasons. First, I think putting it all in one package would lead to a circular dependency:
omjlcomps
needs access to the methods defined in OpenMDAOCore.jl, so it's a dependency.omjlcomps
.So if all the Julia code was in just one package, omjlcomps would need OpenMDAO.jl, and OpenMDAO.jl would need omjlcomps. That actually seemed to work, though I would get scary warnings re: the OpenMDAO.jl module being loaded twice.
Also, with the way things are right now, OpenMDAOCore.jl is a very lightweight dependency—actually has no dependencies other than Julia itself. So it allows Julia package developers to support OpenMDAO without messing around with the omjlcomps Python package, or Python at all, which is nice.
All valid reasons.
I think you can do something like
Base.require(Base.PkgId("name", "uuid"))
to import a specific package.
Gotcha, I tried
Base.require(Base.PkgId(Base.UUID("24d19c10-6eee-420f-95df-4537264b2753"), "OpenMDAOCore"))
at both the top level of the "parent" package OpenMDAO
and inside OpenMDAO
's __init__()
, but still get the same error.
Big fan of PythonCall.jl, JuliaCall.jl, etc.. Thanks so much for these packages.
In my application, I have a chain of tools like this:
The problem: if I create a clean Julia environment and try to install OpenMDAO.jl, I get an error when I attempt to import OpenMDAO.jl. For some reason omjlcomps can't find OpenMDAOCore.jl. Here's what that looks like:
You also might be able to see the error from the AutoMerge workflow for the Julia General registry: https://github.com/JuliaRegistries/General/actions/runs/5244999369/jobs/9471800986?pr=85376.
I was able to work around this by just explicitly adding OpenMDAOCore.jl using Pkg in OpenMDAO.jl's
__init__()
: https://github.com/byuflowlab/OpenMDAO.jl/blob/892afe54b78dca25a6b66237ed24a584f5dc1c47/julia/OpenMDAO.jl/src/OpenMDAO.jl#L15 But I wonder if I'm doing something wrong, or if there's a better way?