Skip to content

Commit

Permalink
feat: move to PythonCall.jl and refactor testing (#48)
Browse files Browse the repository at this point in the history
* move to PythonCall.jl and refactor testing

* fix CI
  • Loading branch information
Moelf authored Nov 28, 2023
1 parent 9f125f1 commit 41db204
Show file tree
Hide file tree
Showing 8 changed files with 3,651 additions and 3,688 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
env:
JULIA_CONDAPKG_BACKEND: "Null"
strategy:
fail-fast: false
matrix:
version:
- '1.8'
- '1.9'
- 'nightly'
os:
Expand All @@ -32,6 +33,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
run: |
python -m pip install -r requirements/pycall.txt
- name: Set up Julia
uses: julia-actions/setup-julia@v1
with:
Expand All @@ -44,26 +49,11 @@ jobs:
path: ~/.julia
key: julia-deps-${{ hashFiles('**/*.toml') }}

- name: Install Julia dependencies
run: julia -e 'import Pkg; Pkg.instantiate()'

- name: Build Julia package
uses: julia-actions/julia-buildpkg@v1

- name: Run Julia tests
uses: julia-actions/julia-runtest@v1
with:
project: .

- name: Install Python dependencies
run: |
python -m pip install -r requirements/pycall.txt
- name: Install PyCall dependencies
run: julia -e 'import Pkg; Pkg.add("PyCall"); Pkg.build("PyCall")'

- name: Run PyCall tests
run: julia --code-coverage --project=tests test/runpytests.jl

- name: Generate and upload code coverage
uses: julia-actions/julia-processcoverage@v1
Expand Down
11 changes: 9 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ version = "0.1.0"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[weakdeps]
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

[extensions]
AwkwardPythonCallExt = "PythonCall"

[compat]
julia = "1.8"
julia = "1.9"

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

[targets]
test = ["Test"]
test = ["Test", "PythonCall"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module AwkwardPyCall
using PyCall
module AwkwardPythonCallExt
using PythonCall
using JSON
using AwkwardArray
import AwkwardArray

function _as_numpy(array::AbstractVector{UInt8})
py_array = PyObject(array)
pyimport("numpy").asarray(py_array, dtype = pyimport("numpy").uint8)
np = pyimport("numpy")
np.asarray(array, dtype = np.uint8)
end

function julia_array_to_python(array)
function AwkwardArray.julia_array_to_python(array)
form, len, containers = AwkwardArray.to_buffers(array)

py_buffers = Dict{String,Any}()
Expand All @@ -25,15 +25,16 @@ function _as_julia(py_buffer)
return uint8_buffer
end

function python_array_to_julia(py_array)
form, len, containers = pyimport("awkward").to_buffers(py_array)
function AwkwardArray.python_array_to_julia(py_array)
form, len, _containers = pyimport("awkward").to_buffers(py_array)
containers = pyconvert(Dict, _containers)

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

return AwkwardArray.from_buffers(form.to_json(), len, julia_buffers)
return AwkwardArray.from_buffers(pyconvert(String, form.to_json()), pyconvert(Int, len), julia_buffers)
end

end # module
File renamed without changes.
Loading

0 comments on commit 41db204

Please sign in to comment.