Skip to content

Commit

Permalink
ensure PythonCall is imported after installs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjohnson541 committed Jun 30, 2024
1 parent cd9b25c commit addbb9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
36 changes: 19 additions & 17 deletions src/ReactionMechanismSimulator.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
module ReactionMechanismSimulator
using PythonCall
using CondaPkg
using Logging
packages = keys(CondaPkg.current_packages())

if !("rmg" in packages) && !("rmgmolecule" in packages)
@info "missing rmg and rmgmolecule installing rmgmolecule..."
if !(v"3.7" <= PythonCall.C.python_version() && PythonCall.C.python_version() <= v"3.9")
@info "python version was not in 3.7-3.9 changing python version"
CondaPkg.add("python"; version="3.9")
end
CondaPkg.add("rmgmolecule"; version=">=0.3.0", channel="mjohnson541")
CondaPkg.add("matplotlib", channel="conda-forge")
CondaPkg.add("rdkit", channel="conda-forge")
CondaPkg.add("pydot", channel="conda-forge")

Pkgc = Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
Pkgc.build("PythonCall")
end

using PythonCall
const Chem = PythonCall.pynew()
const Desc = PythonCall.pynew()
const molecule = PythonCall.pynew()
Expand All @@ -18,22 +35,7 @@ const fragment = PythonCall.pynew()
const pydot = PythonCall.pynew()

function __init__()
packages = keys(CondaPkg.current_packages())

if !("rmg" in packages) && !("rmgmolecule" in packages)
@info "missing rmg and rmgmolecule installing rmgmolecule..."
if !(v"3.7" <= PythonCall.C.python_version() && PythonCall.C.python_version() <= v"3.9")
@info "python version was not in 3.7-3.9 changing python version"
CondaPkg.add("python"; version="3.9")
end
CondaPkg.add("rmgmolecule"; version=">=0.3.0", channel="mjohnson541")
CondaPkg.add("matplotlib", channel="conda-forge")
CondaPkg.add("rdkit", channel="conda-forge")
CondaPkg.add("pydot", channel="conda-forge")

Pkgc = Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
Pkgc.build("PythonCall")
end

@error "packages"
@error keys(CondaPkg.current_packages())
PythonCall.pycopy!(Chem, pyimport("rdkit.Chem"))
Expand Down
15 changes: 8 additions & 7 deletions src/rmstest.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import Logging
Logging.disable_logging(Logging.Warn)

using PythonCall
using CondaPkg
const Chem = PythonCall.pynew()
const molecule = PythonCall.pynew()
const fragment = PythonCall.pynew()
const pydot = PythonCall.pynew()
using CondaPkg

packages = keys(CondaPkg.current_packages())

Expand All @@ -25,6 +19,13 @@ if !("rmg" in packages) && !("rmgmolecule" in packages)
Pkgc.build("PythonCall")
end

using PythonCall

const Chem = PythonCall.pynew()
const molecule = PythonCall.pynew()
const fragment = PythonCall.pynew()
const pydot = PythonCall.pynew()

PythonCall.pycopy!(Chem, pyimport("rdkit.Chem"))
try
PythonCall.pycopy!(molecule, pyimport("rmgpy.molecule"))
Expand Down

0 comments on commit addbb9f

Please sign in to comment.