Skip to content

Commit 22688ee

Browse files
committed
Add options for the Julia binary and project path
This makes using JuliaPkg optional.
1 parent f7fa4c2 commit 22688ee

File tree

6 files changed

+64
-14
lines changed

6 files changed

+64
-14
lines changed

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ jobs:
2323
- run: |
2424
julia --project=docs -e '
2525
using Pkg
26-
Pkg.develop(PackageSpec(path=pwd()))
2726
Pkg.instantiate()'
2827
- run: |
2928
julia --project=docs -e '

.github/workflows/tests.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,23 @@ jobs:
6060
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6161

6262
python:
63-
name: Test Python (${{ matrix.pyversion }}, ${{ matrix.os }})
63+
name: Test Python (${{ matrix.pyversion }}, ${{ matrix.os }}, ${{ matrix.juliaexe }})
6464
runs-on: ${{ matrix.os }}
6565
strategy:
6666
fail-fast: false
6767
matrix:
6868
os: [ubuntu-latest, windows-latest, macos-latest]
6969
pyversion: ["3", "3.9"]
70+
juliaexe: ["@JuliaPkg"]
71+
include:
72+
- arch: x64
73+
os: ubuntu-latest
74+
pyversion: 3
75+
juliaexe: julia
76+
env:
77+
MANUAL_TEST_PROJECT: /tmp/juliacall-test-project
78+
PYTHON_JULIACALL_THREADS: '2'
79+
PYTHON_JULIACALL_HANDLE_SIGNALS: 'yes'
7080

7181
steps:
7282
- uses: actions/checkout@v5
@@ -82,10 +92,18 @@ jobs:
8292
python-version: ${{ matrix.pyversion }}
8393

8494
- name: Set up Julia
95+
id: setup_julia
96+
if: ${{ matrix.juliaexe == 'julia' }}
8597
uses: julia-actions/setup-julia@v2
8698
with:
8799
version: '1'
88100

101+
- name: Set up test Julia project
102+
if: ${{ matrix.juliaexe == 'julia' }}
103+
run: |
104+
mkdir ${{ env.MANUAL_TEST_PROJECT }}
105+
julia --project=${{ env.MANUAL_TEST_PROJECT }} -e 'import Pkg; Pkg.develop(path="."); Pkg.instantiate()'
106+
89107
- name: Install dependencies
90108
run: |
91109
cp pysrc/juliacall/juliapkg-dev.json pysrc/juliacall/juliapkg.json
@@ -98,12 +116,18 @@ jobs:
98116
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
99117
uv run flake8 ./pysrc ./pytest --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
100118
101-
- name: Run tests
119+
- name: Run tests (with JuliaPkg)
120+
if: ${{ matrix.juliaexe == '@JuliaPkg' }}
121+
run: |
122+
uv run pytest -s --nbval --cov=pysrc ./pytest/
123+
124+
- name: Run tests (without JuliaPkg)
125+
if: ${{ matrix.juliaexe == 'julia' }}
102126
run: |
103127
uv run pytest -s --nbval --cov=pysrc ./pytest/
104128
env:
105-
PYTHON_JULIACALL_THREADS: '2'
106-
PYTHON_JULIACALL_HANDLE_SIGNALS: 'yes'
129+
PYTHON_JULIACALL_EXE: "${{ steps.setup_julia.outputs.julia-bindir }}/julia"
130+
PYTHON_JULIACALL_PROJECT: ${{ env.MANUAL_TEST_PROJECT }}
107131

108132
- name: Upload coverage to Codecov
109133
uses: codecov/codecov-action@v5

docs/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
44

55
[compat]
66
Documenter = "1"
7+
8+
[sources]
9+
PythonCall = {path = ".."}

docs/src/juliacall.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ What to read next:
7373

7474
## [Managing Julia dependencies](@id julia-deps)
7575

76-
JuliaCall manages its Julia dependencies using [JuliaPkg](https://github.com/JuliaPy/PyJuliaPkg).
76+
By default JuliaCall manages its Julia dependencies using
77+
[JuliaPkg](https://github.com/JuliaPy/PyJuliaPkg).
7778

7879
It will automatically download a suitable version of Julia if required.
7980

@@ -100,6 +101,15 @@ Alternatively you can use `add`, `rm`, etc. from JuliaPkg to edit this file.
100101

101102
See [JuliaPkg](https://github.com/JuliaPy/PyJuliaPkg) for more details.
102103

104+
### Using existing environments
105+
106+
It's possible to override the defaults and disable JuliaPkg entirely by setting
107+
the `PYTHON_JULIACALL_EXE` and `PYTHON_JULIACALL_PROJECT` options (both must be
108+
set together). This is particularly useful when using shared environments on HPC
109+
systems that may be readonly. Note that the project set in
110+
`PYTHON_JULIACALL_PROJECT` *must* already have PythonCall.jl installed and it
111+
*must* match the JuliaCall version, otherwise loading Julia will fail.
112+
103113
## [Configuration](@id julia-config)
104114

105115
Some features of the Julia process, such as the optimization level or number of threads, may
@@ -125,6 +135,8 @@ be configured in two ways:
125135
| `-X juliacall-warn-overwrite=<yes\|no>` | `PYTHON_JULIACALL_WARN_OVERWRITE=<yes\|no>` | Enable or disable method overwrite warnings. |
126136
| `-X juliacall-autoload-ipython-extension=<yes\|no>` | `PYTHON_JULIACALL_AUTOLOAD_IPYTHON_EXTENSION=<yes\|no>` | Enable or disable IPython extension autoloading. |
127137
| `-X juliacall-heap-size-hint=<N>` | `PYTHON_JULIACALL_HEAP_SIZE_HINT=<N>` | Hint for initial heap size in bytes. |
138+
| `-X juliacall-exepath=<file>` | `PYTHON_JULIACALL_EXEPATH=<file>` | Path to Julia binary to use (overrides JuliaPkg). |
139+
| `-X juliacall-project=<dir>` | `PYTHON_JULIACALL_PROJECT=<dir>` | Path to the Julia project to use (overrides JuliaPkg). |
128140

129141
## [Multi-threading](@id py-multi-threading)
130142

docs/src/releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
* Bug fixes.
55
* Internal: switch from Requires.jl to package extensions.
6+
* Added support for specifying the Julia binary and project to override JuliaPkg.
67

78
## 0.9.27 (2025-08-19)
89
* Internal: Use heap-allocated types (PyType_FromSpec) to improve ABI compatibility.

pysrc/juliacall/__init__.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def int_option(name, *, accept_auto=False, **kw):
110110
raise ValueError(f'{s}: expecting an int'+(' or auto' if accept_auto else ""))
111111

112112
def args_from_config(config):
113-
argv = [config['exepath']]
113+
argv = [config['exe']]
114114
for opt, val in config.items():
115115
if opt.startswith('opt_'):
116116
if val is None:
@@ -147,21 +147,32 @@ def args_from_config(config):
147147
CONFIG['opt_handle_signals'] = choice('handle_signals', ['yes', 'no'])[0]
148148
CONFIG['opt_startup_file'] = choice('startup_file', ['yes', 'no'])[0]
149149
CONFIG['opt_heap_size_hint'] = option('heap_size_hint')[0]
150+
CONFIG['project'] = path_option('project', check_exists=True)[0]
151+
CONFIG['exe'] = path_option('exe', check_exists=True)[0]
150152

151153
# Stop if we already initialised
152154
if CONFIG['inited']:
153155
return
154156

155-
# we don't import this at the top level because it is not required when juliacall is
156-
# loaded by PythonCall and won't be available
157-
import juliapkg
157+
have_exe = CONFIG['exe'] is not None
158+
have_project = CONFIG['project'] is not None
159+
if not have_exe and not have_project:
160+
# we don't import this at the top level because it is not required when
161+
# juliacall is loaded by PythonCall and won't be available, or if both
162+
# `exe` and `project` are set by the user.
163+
import juliapkg
158164

159-
# Find the Julia executable and project
160-
CONFIG['exepath'] = exepath = juliapkg.executable()
161-
CONFIG['project'] = project = juliapkg.project()
165+
# Find the Julia executable and project
166+
CONFIG['exe'] = juliapkg.executable()
167+
CONFIG['project'] = juliapkg.project()
168+
elif (not have_exe and have_project) or (have_exe and not have_project):
169+
raise Exception("Both PYTHON_JULIACALL_PROJECT and PYTHON_JULIACALL_EXE must be set together, not only one of them.")
170+
171+
exe = CONFIG['exe']
172+
project = CONFIG['project']
162173

163174
# Find the Julia library
164-
cmd = [exepath, '--project='+project, '--startup-file=no', '-O0', '--compile=min',
175+
cmd = [exe, '--project='+project, '--startup-file=no', '-O0', '--compile=min',
165176
'-e', 'import Libdl; print(abspath(Libdl.dlpath("libjulia")), "\\0", Sys.BINDIR)']
166177
libpath, default_bindir = subprocess.run(cmd, check=True, capture_output=True, encoding='utf8').stdout.split('\0')
167178
assert os.path.exists(libpath)

0 commit comments

Comments
 (0)