Skip to content

Commit 4b8e644

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

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
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 '

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_EXEPATH` and `PYTHON_JULIACALL_PROJECT` options. This is
108+
particularly useful when using shared environments on HPC systems that may be
109+
readonly. If `PYTHON_JULIACALL_PROJECT` is specified the project *must* already
110+
have PythonCall.jl already installed. If only one of these options is specified
111+
then JuliaPkg will still be loaded to get a default value for the other one.
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: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,29 @@ 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['opt_project'] = path_option('project', check_exists=True)[0]
151+
CONFIG['exepath'] = path_option('exepath', 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
158-
159-
# Find the Julia executable and project
160-
CONFIG['exepath'] = exepath = juliapkg.executable()
161-
CONFIG['project'] = project = juliapkg.project()
157+
no_exepath = CONFIG['exepath'] is None
158+
no_project = CONFIG['opt_project'] is None
159+
if no_exepath or no_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+
# `exepath` and `project` are set by the user.
163+
import juliapkg
164+
165+
# Find the Julia executable and project
166+
if no_exepath:
167+
CONFIG['exepath'] = juliapkg.executable()
168+
if no_project:
169+
CONFIG['opt_project'] = juliapkg.project()
170+
171+
exepath = CONFIG['exepath']
172+
project = CONFIG['opt_project']
162173

163174
# Find the Julia library
164175
cmd = [exepath, '--project='+project, '--startup-file=no', '-O0', '--compile=min',

0 commit comments

Comments
 (0)