diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 01e857d..1a8b09c 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 }} @@ -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: diff --git a/diffeqpy/__init__.py b/diffeqpy/__init__.py index 17f67f3..c8416e6 100644 --- a/diffeqpy/__init__.py +++ b/diffeqpy/__init__.py @@ -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): @@ -36,7 +38,9 @@ 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 @@ -44,16 +48,18 @@ def load_julia_packages(*names): # 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. @@ -61,36 +67,33 @@ def install(*, confirm=False): 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: @@ -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) diff --git a/tox.ini b/tox.ini index 738082d..e925450 100644 --- a/tox.ini +++ b/tox.ini @@ -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}