JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.46k stars 187 forks source link

Set environment variables without package rebuild? #977

Open sairus7 opened 2 years ago

sairus7 commented 2 years ago

I have the following in my deps/build.jl file:

using PyCall
PyCall.Conda.add("wfdb")

And inside module:

module MyPackage
const WFDB = PyNULL()
function __init__()
   copy!(WFDB, pyimport("wfdb"))
end
end # module

But this doesn't work on Linux, because there are different paths for PyCall.libpython and PyCall.Conda.PYTHONDIR. As explained in the PyCall documentation, I should set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia.

So, in GH Actions I've added a custom run command for MyPackage:

      - name: "Set up Julia"
        uses: julia-actions/setup-julia@v1
        with:
          version: ${{ matrix.julia-version }}
          arch: ${{ matrix.julia-arch }}
      - uses: julia-actions/julia-buildpkg@v1
      - run: julia --project=@. -e 'import Pkg; ENV["PYTHON"]=""; Pkg.add("PyCall"); Pkg.build("PyCall")'
      - uses: julia-actions/julia-runtest@v1

But it breaks again in GH Actions for other packages, if they have MyPackage as a dependency.

So, should I really repeat this custom run command to all other packages that rely on MyPackage?

Or maybe I can somehow add scripts in my package, that will be run before build?