Skip to content

Commit

Permalink
Merge pull request #6 from contentauth/linux_c2pa_fix
Browse files Browse the repository at this point in the history
Multi-platform publish with import name change to c2pa
  • Loading branch information
gpeacock authored Jan 28, 2024
2 parents 5723a25 + b2373b3 commit e53f873
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 87 deletions.
172 changes: 130 additions & 42 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,139 @@ on:
push:
branches:
- main
pull_request:
tags:
- "*"
workflow_dispatch:

permissions:
contents: read

jobs:
build-nightly-only:
name: Build nightly only
linux:
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
strategy:
matrix:
target: [x86_64, aarch64]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- run: pip install -r requirements.txt
- name: Setup QEMU
uses: docker/setup-qemu-action@v1
if: ${{ matrix.target == 'aarch64' }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
maturin-version: "1.2.0"
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: ${{ matrix.target == 'aarch64' && 'manylinux_2_28' || 'auto' }}
before-script-linux: "pip install uniffi-bindgen==0.24.1"
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

windows:
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v1
- name: Install nightly rust
run: curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
# Insert steps here to install you other dependencies. Note that you're running inside of cent os 7, not ubuntu
- name: Installing custom dependency
run: echo "Installing custom dependency"
- name: Build
run: |
source $HOME/.cargo/env
for PYBIN in /opt/python/cp3[6789]*/bin; do
"${PYBIN}/pip" install maturin
"${PYBIN}/maturin" build -m nightly-only/Cargo.toml -i "${PYBIN}/python" --release --manylinux 2014
done
# Auditwheel isn't generally necessary. This is only shown as refernce for cases where you link
# external libraries, in which case you have to set manylinux to off and then use auditwheel repair
- name: Auditwheel repair
run: |
for wheel in nightly-only/target/wheels/*.whl; do
auditwheel repair "${wheel}"
done
# This is similar to the above, except we're only using the lowest supported python version to build a single
# abi3 wheel
build-nightly-only-abi3:
name: Build nightly only abi3
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: ${{ matrix.target }}
cache: "pip"
- run: pip install -r requirements.txt
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

macos_x86:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: "pip"
- run: pip install -r requirements.txt
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: x86_64
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

macos_aarch64:
runs-on: macos-latest-large
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: "pip"
- run: pip install -r requirements.txt
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: aarch64
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, windows, macos_x86, macos_aarch64, sdist]
steps:
- uses: actions/checkout@v1
- name: Install nightly rust
run: curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
- name: Install maturin
run: /opt/python/cp36-cp36m/bin/pip install maturin
- name: Build with maturin
run: |
source $HOME/.cargo/env
/opt/python/cp36-cp36m/bin/maturin build -m nightly-only-abi3/Cargo.toml -i /opt/python/cp36-cp36m/bin/python --release --manylinux 2014
- name: Auditwheel repair
run: auditwheel repair nightly-only-abi3/target/wheels/*.whl
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
[package]
name = "c2pa-python"
version = "0.3.2"
version = "0.4.0"
edition = "2021"
authors = ["Gavin Peacock <[email protected]"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "c2pa_python"
name = "c2pa"
crate-type = ["cdylib"]

[dependencies]
c2pa-c = { git = "https://github.com/contentauth/c2pa-c.git", branch = "main"}
c2pa-c = { git = "https://github.com/contentauth/c2pa-c.git", branch = "main" }
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
thiserror = "1.0.49"
thiserror = "1.0.49"
uniffi = "0.24.1"

[build-dependencies]
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ see the development section for info on how to build from source.
Import the C2PA module as follows:
```py
import c2pa_python as c2pa
import c2pa
```

### Read and validate C2PA data in a file
Expand Down Expand Up @@ -139,6 +139,25 @@ pip install -U pytest
python3 -m build --wheel
```

### ManyLinux build
```
docker run -it quay.io/pypa/manylinux_2_28_aarch64 bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
export PATH=/opt/python/cp312-cp312/bin:$PATH
pip install maturin
pip install venv
pip install build
pip install -U pytest
cd home
git clone https://github.com/contentauth/c2pa-python.git
cd c2pa-python
python3 -m build --wheel
auditwheel repair target/wheels/c2pa_python-0.4.0-py3-none-linux_aarch64.whl
```

### Testing

We use [PyTest](https://docs.pytest.org/) for testing.
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[build-system]
requires = ["maturin>=1.2,<2.0"]
requires = ["maturin>=1.2,<2.0","uniffi_bindgen>=0.24,<0.25"]
build-backend = "maturin"

[project]
name = "c2pa-python"
dependencies = ["cffi"]
requires-python = ">=3.7"
description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library"
readme = { file = "README.md", content-type = "text/markdown" }
Expand All @@ -13,7 +14,7 @@ classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: Implementation :: PyPy"
]
authors = [
{name = "Gavin Peacock", email = "[email protected]"}
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
maturin==1.2.0
uniffi-bindgen==0.24.1
34 changes: 0 additions & 34 deletions tests/example.py

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test_c2pa.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# specific language governing permissions and limitations under
# each license.

import c2pa_python as c2pa
import c2pa
import pytest
import json
import tempfile
Expand All @@ -24,10 +24,10 @@ def getitem(d, key):
return reduce(operator.getitem, key, d)

def test_version():
assert c2pa.version() == "0.3.2"
assert c2pa.version() == "0.4.0"

def test_sdk_version():
assert c2pa.sdk_version() == "0.28.3"
assert c2pa.sdk_version() == "0.28.4"


def test_verify_from_file():
Expand Down
2 changes: 1 addition & 1 deletion tests/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import os
import sys
import c2pa_python as c2pa;
import c2pa

# set up paths to the files we we are using
PROJECT_PATH = os.getcwd()
Expand Down

0 comments on commit e53f873

Please sign in to comment.