Skip to content

Commit

Permalink
several updates
Browse files Browse the repository at this point in the history
  • Loading branch information
himoto committed Nov 19, 2024
1 parent e00b030 commit d6159c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Disabling Windows tests as it's known to not work:
# https://github.com/SciML/diffeqpy/pull/86#issuecomment-1011675735
# - windows-latest
python-version: ['3.10']
python-version: ['3.6', '3.12']
fail-fast: false
name: Test ${{ matrix.os }} ${{ matrix.architecture }}
Python ${{ matrix.python-version }}
Expand All @@ -28,10 +28,6 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox
- name: Install Julia using jill
run: |
python -m pip install --upgrade jill
python -c "from jill.install import install_julia; install_julia(version='1.10', confirm=True)"
- name: Run test
run: python -m tox -- --cov=diffeqpy -s
env:
Expand Down
38 changes: 20 additions & 18 deletions diffeqpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import shutil

from jill.install import install_julia

# juliacall must be loaded after `_ensure_julia_installed()` is run,
# so this import is in `load_julia_packages()`
# from juliacall import Main


def _find_julia():
# TODO: this should probably fallback to query jill
return shutil.which("julia")


def _ensure_julia_installed():
if not _find_julia():
print("No Julia version found. Installing Julia.")
install_julia(version="1.10")
if not _find_julia():
raise RuntimeError(
"Julia installed with jill but `julia` binary cannot be found in the path"
)
raise RuntimeError("Julia installed with jill but `julia` binary cannot be found in the path")


# TODO: upstream this function or an alternative into juliacall
def load_julia_packages(*names):
Expand All @@ -36,61 +38,62 @@ def load_julia_packages(*names):
Pkg.add([{1}])
import {0}
end
{0}""".format(", ".join(names), ", ".join(f'"{name}"' for name in names))
{0}""".format(
", ".join(names), ", ".join(f'"{name}"' for name in names)
)

# Unfortunately, `seval` doesn't support multi-line strings
# https://github.com/JuliaPy/PythonCall.jl/issues/433
script = script.replace("\n", ";")

# Must be loaded after `_ensure_julia_installed()`
from juliacall import Main
return Main.seval(script)

return Main.seval(script)


# Deprecated (julia and packages now auto-install)
import os
import subprocess
import sys

script_dir = os.path.dirname(os.path.realpath(__file__))


def install(*, confirm=False):
"""
Install Julia (if required) and Julia packages required for diffeqpy.
"""
julia = _find_julia()
if not julia:
print("No Julia version found. Installing Julia.")
install_julia(confirm=confirm)
install_julia(version="1.10", confirm=confirm)
julia = _find_julia()
if not julia:
raise RuntimeError(
"Julia installed with jill but `julia` binary cannot be found in the path"
)
raise RuntimeError("Julia installed with jill but `julia` binary cannot be found in the path")
env = os.environ.copy()
env["PYTHON"] = sys.executable
subprocess.check_call([julia, os.path.join(script_dir, "deprecated/install.jl")], env=env)


def install_cuda():
julia = _find_julia()
if not julia:
raise RuntimeError(
"Julia must be installed before adding CUDA. Please run `diffeqpy.install()` first"
)
raise RuntimeError("Julia must be installed before adding CUDA. Please run `diffeqpy.install()` first")
env = os.environ.copy()
env["PYTHON"] = sys.executable
subprocess.check_call([julia, os.path.join(script_dir, "deprecated/install_cuda.jl")], env=env)


def install_amdgpu():
julia = _find_julia()
if not julia:
raise RuntimeError(
"Julia must be installed before adding AMDGPU. Please run `diffeqpy.install()` first"
)
raise RuntimeError("Julia must be installed before adding AMDGPU. Please run `diffeqpy.install()` first")
env = os.environ.copy()
env["PYTHON"] = sys.executable
subprocess.check_call([julia, os.path.join(script_dir, "deprecated/install_amdgpu.jl")], env=env)


def install_metal():
julia = _find_julia()
if not julia:
Expand All @@ -101,12 +104,11 @@ def install_metal():
env["PYTHON"] = sys.executable
subprocess.check_call([julia, os.path.join(script_dir, "deprecated/install_metal.jl")], env=env)


def install_oneapi():
julia = _find_julia()
if not julia:
raise RuntimeError(
"Julia must be installed before adding oneAPI. Please run `diffeqpy.install()` first"
)
raise RuntimeError("Julia must be installed before adding oneAPI. Please run `diffeqpy.install()` first")
env = os.environ.copy()
env["PYTHON"] = sys.executable
subprocess.check_call([julia, os.path.join(script_dir, "deprecated/install_oneapi.jl")], env=env)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ deps =
pytest
pytest-cov
commands =
python -c 'import diffeqpy; diffeqpy._ensure_julia_installed()'
python -c 'import diffeqpy; diffeqpy.install()'
py.test \
--pyargs diffeqpy \
{posargs}
Expand Down

0 comments on commit d6159c1

Please sign in to comment.