Skip to content

Commit 41db204

Browse files
authored
feat: move to PythonCall.jl and refactor testing (#48)
* move to PythonCall.jl and refactor testing * fix CI
1 parent 9f125f1 commit 41db204

File tree

8 files changed

+3651
-3688
lines changed

8 files changed

+3651
-3688
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ jobs:
1717
test:
1818
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
1919
runs-on: ${{ matrix.os }}
20+
env:
21+
JULIA_CONDAPKG_BACKEND: "Null"
2022
strategy:
2123
fail-fast: false
2224
matrix:
2325
version:
24-
- '1.8'
2526
- '1.9'
2627
- 'nightly'
2728
os:
@@ -32,6 +33,10 @@ jobs:
3233
steps:
3334
- uses: actions/checkout@v4
3435

36+
- name: Set up Python
37+
run: |
38+
python -m pip install -r requirements/pycall.txt
39+
3540
- name: Set up Julia
3641
uses: julia-actions/setup-julia@v1
3742
with:
@@ -44,26 +49,11 @@ jobs:
4449
path: ~/.julia
4550
key: julia-deps-${{ hashFiles('**/*.toml') }}
4651

47-
- name: Install Julia dependencies
48-
run: julia -e 'import Pkg; Pkg.instantiate()'
49-
5052
- name: Build Julia package
5153
uses: julia-actions/julia-buildpkg@v1
5254

5355
- name: Run Julia tests
5456
uses: julia-actions/julia-runtest@v1
55-
with:
56-
project: .
57-
58-
- name: Install Python dependencies
59-
run: |
60-
python -m pip install -r requirements/pycall.txt
61-
62-
- name: Install PyCall dependencies
63-
run: julia -e 'import Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")'
64-
65-
- name: Run PyCall tests
66-
run: julia --code-coverage --project=tests test/runpytests.jl
6757

6858
- name: Generate and upload code coverage
6959
uses: julia-actions/julia-processcoverage@v1

Project.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ version = "0.1.0"
77
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
88
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
99

10+
[weakdeps]
11+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
12+
13+
[extensions]
14+
AwkwardPythonCallExt = "PythonCall"
15+
1016
[compat]
11-
julia = "1.8"
17+
julia = "1.9"
1218

1319
[extras]
20+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
1421
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1522

1623
[targets]
17-
test = ["Test"]
24+
test = ["Test", "PythonCall"]
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
module AwkwardPyCall
2-
using PyCall
1+
module AwkwardPythonCallExt
2+
using PythonCall
33
using JSON
4-
using AwkwardArray
4+
import AwkwardArray
55

66
function _as_numpy(array::AbstractVector{UInt8})
7-
py_array = PyObject(array)
8-
pyimport("numpy").asarray(py_array, dtype = pyimport("numpy").uint8)
7+
np = pyimport("numpy")
8+
np.asarray(array, dtype = np.uint8)
99
end
1010

11-
function julia_array_to_python(array)
11+
function AwkwardArray.julia_array_to_python(array)
1212
form, len, containers = AwkwardArray.to_buffers(array)
1313

1414
py_buffers = Dict{String,Any}()
@@ -25,15 +25,16 @@ function _as_julia(py_buffer)
2525
return uint8_buffer
2626
end
2727

28-
function python_array_to_julia(py_array)
29-
form, len, containers = pyimport("awkward").to_buffers(py_array)
28+
function AwkwardArray.python_array_to_julia(py_array)
29+
form, len, _containers = pyimport("awkward").to_buffers(py_array)
30+
containers = pyconvert(Dict, _containers)
3031

3132
julia_buffers = Dict{String,AbstractVector{UInt8}}()
3233
for (key, buffer) in containers
3334
julia_buffers[key] = _as_julia(buffer)
3435
end
3536

36-
return AwkwardArray.from_buffers(form.to_json(), len, julia_buffers)
37+
return AwkwardArray.from_buffers(pyconvert(String, form.to_json()), pyconvert(Int, len), julia_buffers)
3738
end
3839

3940
end # module
File renamed without changes.

0 commit comments

Comments
 (0)