Skip to content

Commit addbb9f

Browse files
committed
ensure PythonCall is imported after installs
1 parent cd9b25c commit addbb9f

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/ReactionMechanismSimulator.jl

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
module ReactionMechanismSimulator
2-
using PythonCall
32
using CondaPkg
43
using Logging
4+
packages = keys(CondaPkg.current_packages())
5+
6+
if !("rmg" in packages) && !("rmgmolecule" in packages)
7+
@info "missing rmg and rmgmolecule installing rmgmolecule..."
8+
if !(v"3.7" <= PythonCall.C.python_version() && PythonCall.C.python_version() <= v"3.9")
9+
@info "python version was not in 3.7-3.9 changing python version"
10+
CondaPkg.add("python"; version="3.9")
11+
end
12+
CondaPkg.add("rmgmolecule"; version=">=0.3.0", channel="mjohnson541")
13+
CondaPkg.add("matplotlib", channel="conda-forge")
14+
CondaPkg.add("rdkit", channel="conda-forge")
15+
CondaPkg.add("pydot", channel="conda-forge")
16+
17+
Pkgc = Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
18+
Pkgc.build("PythonCall")
19+
end
20+
21+
using PythonCall
522
const Chem = PythonCall.pynew()
623
const Desc = PythonCall.pynew()
724
const molecule = PythonCall.pynew()
@@ -18,22 +35,7 @@ const fragment = PythonCall.pynew()
1835
const pydot = PythonCall.pynew()
1936

2037
function __init__()
21-
packages = keys(CondaPkg.current_packages())
22-
23-
if !("rmg" in packages) && !("rmgmolecule" in packages)
24-
@info "missing rmg and rmgmolecule installing rmgmolecule..."
25-
if !(v"3.7" <= PythonCall.C.python_version() && PythonCall.C.python_version() <= v"3.9")
26-
@info "python version was not in 3.7-3.9 changing python version"
27-
CondaPkg.add("python"; version="3.9")
28-
end
29-
CondaPkg.add("rmgmolecule"; version=">=0.3.0", channel="mjohnson541")
30-
CondaPkg.add("matplotlib", channel="conda-forge")
31-
CondaPkg.add("rdkit", channel="conda-forge")
32-
CondaPkg.add("pydot", channel="conda-forge")
33-
34-
Pkgc = Base.require(Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg"))
35-
Pkgc.build("PythonCall")
36-
end
38+
3739
@error "packages"
3840
@error keys(CondaPkg.current_packages())
3941
PythonCall.pycopy!(Chem, pyimport("rdkit.Chem"))

src/rmstest.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import Logging
22
Logging.disable_logging(Logging.Warn)
3-
4-
using PythonCall
5-
using CondaPkg
6-
const Chem = PythonCall.pynew()
7-
const molecule = PythonCall.pynew()
8-
const fragment = PythonCall.pynew()
9-
const pydot = PythonCall.pynew()
3+
using CondaPkg
104

115
packages = keys(CondaPkg.current_packages())
126

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

22+
using PythonCall
23+
24+
const Chem = PythonCall.pynew()
25+
const molecule = PythonCall.pynew()
26+
const fragment = PythonCall.pynew()
27+
const pydot = PythonCall.pynew()
28+
2829
PythonCall.pycopy!(Chem, pyimport("rdkit.Chem"))
2930
try
3031
PythonCall.pycopy!(molecule, pyimport("rmgpy.molecule"))

0 commit comments

Comments
 (0)