Skip to content

Commit 5117abc

Browse files
Christopher DorisMilesCranmer
authored andcommitted
Merge remote-tracking branch 'origin/main' into less-getptr
2 parents 96bd228 + c84c059 commit 5117abc

File tree

5 files changed

+60
-17
lines changed

5 files changed

+60
-17
lines changed

.github/workflows/tests-nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
jobs:
1212
tests:
13-
name: Test (${{ matrix.os }}-${{ matrix.arch }}, julia ${{ matrix.jlversion }})
13+
name: Test Julia (${{ matrix.jlversion }}, ${{ matrix.os }}-${{ matrix.arch }})
1414
runs-on: ${{ matrix.os }}
1515
strategy:
1616
fail-fast: false

.github/workflows/tests.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,70 +12,88 @@ on:
1212

1313
jobs:
1414
julia:
15-
name: Test (${{ matrix.os }}, julia ${{ matrix.jlversion }})
15+
name: Test Julia (${{ matrix.jlversion }}, ${{ matrix.os }})
1616
runs-on: ${{ matrix.os }}
1717
strategy:
18-
fail-fast: true
18+
fail-fast: false
1919
matrix:
2020
arch: [x64] # x86 unsupported by MicroMamba
2121
os: [ubuntu-latest, windows-latest, macos-latest]
2222
jlversion: ['1','1.9']
23+
2324
steps:
2425
- uses: actions/checkout@v4
26+
2527
- name: Set up Julia ${{ matrix.jlversion }}
2628
uses: julia-actions/setup-julia@v2
2729
with:
2830
version: ${{ matrix.jlversion }}
2931
arch: ${{ matrix.arch }}
32+
3033
- uses: julia-actions/cache@v2
34+
3135
- name: Build package
3236
uses: julia-actions/julia-buildpkg@v1
37+
3338
- name: Run tests
3439
uses: julia-actions/julia-runtest@v1
3540
env:
3641
JULIA_DEBUG: PythonCall
3742
JULIA_NUM_THREADS: '2'
43+
3844
- name: Process coverage
3945
uses: julia-actions/julia-processcoverage@v1
46+
4047
- name: Upload coverage to Codecov
4148
uses: codecov/codecov-action@v5
4249
env:
4350
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
51+
4452
python:
45-
name: Test (${{ matrix.os }}, python ${{ matrix.pyversion }})
53+
name: Test Python (${{ matrix.pyversion }}, ${{ matrix.os }})
4654
runs-on: ${{ matrix.os }}
4755
strategy:
48-
fail-fast: true
56+
fail-fast: false
4957
matrix:
5058
os: [ubuntu-latest, windows-latest, macos-latest]
51-
pyversion: ["3.x", "3.8"]
59+
pyversion: ["3", "3.8"]
60+
5261
steps:
5362
- uses: actions/checkout@v4
63+
5464
- name: Set up Python ${{ matrix.pyversion }}
5565
uses: actions/setup-python@v5
5666
with:
5767
python-version: ${{ matrix.pyversion }}
68+
69+
- name: Set up uv
70+
uses: astral-sh/setup-uv@v6
71+
with:
72+
python-version: ${{ matrix.pyversion }}
73+
5874
- name: Set up Julia
5975
uses: julia-actions/setup-julia@v2
6076
with:
6177
version: '1'
78+
6279
- name: Install dependencies
6380
run: |
64-
python -m pip install --upgrade pip
65-
pip install flake8 pytest pytest-cov nbval numpy
6681
cp pysrc/juliacall/juliapkg-dev.json pysrc/juliacall/juliapkg.json
67-
pip install -e .
82+
uv sync --dev
83+
6884
- name: Lint with flake8
6985
run: |
7086
# stop the build if there are Python syntax errors or undefined names
71-
flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 --show-source --statistics
87+
uv run flake8 ./pysrc ./pytest --count --select=E9,F63,F7,F82 --ignore=F821 --show-source --statistics
7288
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
73-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
89+
uv run flake8 ./pysrc ./pytest --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
90+
7491
- name: Run tests
7592
run: |
76-
pytest -s --nbval --cov=pysrc ./pytest/
93+
uv run pytest -s --nbval --cov=pysrc ./pytest/
7794
env:
7895
PYTHON_JULIACALL_THREADS: '2'
96+
7997
- name: Upload coverage to Codecov
8098
uses: codecov/codecov-action@v5
8199
env:

docs/src/faq.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,17 @@ Related issues: [#255](https://github.com/JuliaPy/PythonCall.jl/issues/255)
8989
Yes, it may be possible. A good example of that is having Julia running inside the Python that is running inside Blender, as presented in [this Discourse post](https://discourse.julialang.org/t/running-julia-inside-blender-through-vscode-using-pythoncall-juliacall/96838/6).
9090
From the point that one has JuliaCall running inside Python, if it has access to the terminal, one can even launch a Julia REPL there, and if needed connect with VSCode Julia extension to it.
9191
The full Python script to install, launch JuliaCall, and launch a Julia REPL in Blender is [here](https://gist.github.com/cdsousa/d820d27174238c0d48e5252355584172).
92+
93+
## Using PythonCall.jl and CondaPkg.jl in a script
94+
95+
If running from a script, make sure that [CondaPkg.jl](https://github.com/JuliaPy/CondaPkg.jl) is used before [PythonCall.jl](https://github.com/JuliaPy/PythonCall.jl) to ensure proper loading of Python packages in your path. E.g.,
96+
97+
```julia
98+
using CondaPkg
99+
100+
CondaPkg.add("numpy")
101+
102+
using PythonCall
103+
104+
np = pyimport("numpy")
105+
```

pyproject.toml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ classifiers = [
1212
"License :: OSI Approved :: MIT License",
1313
"Operating System :: OS Independent",
1414
]
15-
requires-python = ">=3.8"
16-
dependencies = ["juliapkg ~=0.1.17"]
15+
requires-python = ">=3.8, <4"
16+
dependencies = ["juliapkg >=0.1.17, <0.2"]
17+
18+
[dependency-groups]
19+
dev = [
20+
"flake8>=5.0",
21+
"nbval>=0.11.0",
22+
"numpy>=1.24",
23+
"pytest>=8.3",
24+
"pytest-cov>=5.0",
25+
]
1726

1827
[tool.hatch.build.targets.wheel]
1928
packages = ["pysrc/juliacall"]

src/JlWrap/objectarray.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ end
4242

4343
@propagate_inbounds function Base.getindex(x::PyObjectArray, i::Integer...)
4444
@boundscheck checkbounds(x, i...)
45-
@inbounds ptr = x.ptrs[i...]
46-
ptr == C_NULL && throw(UndefRefError())
47-
return pynew(incref(ptr))
45+
Base.GC.@preserve x begin
46+
@inbounds ptr = x.ptrs[i...]
47+
ptr == C_NULL && throw(UndefRefError())
48+
return pynew(incref(ptr))
49+
end
4850
end
4951

5052
@propagate_inbounds function Base.setindex!(x::PyObjectArray, v, i::Integer...)

0 commit comments

Comments
 (0)