Skip to content

Commit

Permalink
Add conda-skip logic to init.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
stillyslalom committed Jan 16, 2023
1 parent fafe29c commit 22fbf04
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.2.1"
[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
Expand Down
8 changes: 8 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ Documentation for [PyThermo](https://github.com/stillyslalom/PyThermo.jl).
Species
Mixture
```

## Interaction with Conda
PyThermo's Python dependencies are managed by CondaPkg.jl, which registers
a project's dependencies in CondaPkg.toml (similar to Julia's Project.toml).
These dependencies are installed automatically when PyThermo is first loaded.
To avoid Conda management overhead during subsequent initialization of PyThermo,
the `JULIA_CONDAPKG_OFFLINE` environment is set to `"true"` by default. This can
be overriden by setting `JULIA_CONDAPKG_OFFLINE` to `"false"` before loading PyThermo.
1 change: 1 addition & 0 deletions src/PyThermo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module PyThermo
using PythonCall
using Printf
using Unitful
using Pkg

import Base: convert, ==, isequal, hash, getindex, setindex!, haskey, keys, show

Expand Down
14 changes: 13 additions & 1 deletion src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ const PY_THERMO = PythonCall.pynew()
const PY_CHEM = PythonCall.pynew()
const PY_COPY = PythonCall.pynew()

# If the user has set JULIA_CONDAPKG_OFFLINE, use that value. Otherwise,
# if .CondaPkg exists in the current environment, use "true" to skip
# Conda pkg resolution. Otherwise, use "false" to allow Conda to
# resolve the pkg environment.
get!(ENV, "JULIA_CONDAPKG_OFFLINE") do
if ispath(joinpath(dirname(Pkg.project().path), ".CondaPkg"))
"true"
else
"false"
end
end

function __init__()
PythonCall.pycopy!(PY_THERMO, pyimport("thermo"))
PythonCall.pycopy!(PY_CHEM, PY_THERMO.chemical)
PythonCall.pycopy!(PY_COPY, pyimport("copy"))
end
end

0 comments on commit 22fbf04

Please sign in to comment.