Skip to content

Commit 97ad247

Browse files
committed
build: work in progress on build updates
1 parent 2bb3def commit 97ad247

File tree

5 files changed

+41
-187
lines changed

5 files changed

+41
-187
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -42,153 +42,16 @@ jobs:
4242
- name: Checkout repository
4343
uses: actions/checkout@v4
4444

45-
- name: Install Rust toolchain
46-
uses: dtolnay/rust-toolchain@master
45+
- name: Set up Python
46+
uses: actions/setup-python@v5
4747
with:
48-
toolchain: ${{ matrix.rust_version }}
49-
components: llvm-tools-preview
50-
51-
- name: Cache Rust dependencies
52-
uses: Swatinem/rust-cache@v2
53-
54-
clippy_check:
55-
name: Clippy
56-
57-
if: |
58-
github.event_name != 'pull_request' ||
59-
github.event.pull_request.author_association == 'COLLABORATOR' ||
60-
github.event.pull_request.author_association == 'MEMBER' ||
61-
github.event.pull_request.user.login == 'dependabot[bot]' ||
62-
contains(github.event.pull_request.labels.*.name, 'safe to test')
63-
64-
runs-on: ubuntu-latest
65-
66-
steps:
67-
- name: Checkout repository
68-
uses: actions/checkout@v4
69-
70-
- name: Install Rust toolchain
71-
uses: dtolnay/rust-toolchain@stable
72-
with:
73-
components: clippy
74-
75-
- name: Cache Rust dependencies
76-
uses: Swatinem/rust-cache@v2
77-
78-
- name: Run Clippy
79-
run: cargo clippy --all-features --all-targets -- -Dwarnings
80-
81-
cargo_fmt:
82-
name: Enforce Rust code format
83-
84-
if: |
85-
github.event_name != 'pull_request' ||
86-
github.event.pull_request.author_association == 'COLLABORATOR' ||
87-
github.event.pull_request.author_association == 'MEMBER' ||
88-
github.event.pull_request.user.login == 'dependabot[bot]' ||
89-
contains(github.event.pull_request.labels.*.name, 'safe to test')
90-
91-
runs-on: ubuntu-latest
92-
93-
steps:
94-
- name: Checkout repository
95-
uses: actions/checkout@v4
96-
97-
- name: Install nightly toolchain
98-
uses: dtolnay/rust-toolchain@nightly
99-
with:
100-
components: rustfmt
101-
102-
- name: Check format
103-
run: cargo +nightly fmt --all -- --check
104-
105-
docs_rs:
106-
name: Preflight docs.rs build
107-
108-
if: |
109-
github.event_name != 'pull_request' ||
110-
github.event.pull_request.author_association == 'COLLABORATOR' ||
111-
github.event.pull_request.author_association == 'MEMBER' ||
112-
github.event.pull_request.user.login == 'dependabot[bot]' ||
113-
contains(github.event.pull_request.labels.*.name, 'safe to test')
114-
115-
runs-on: ubuntu-latest
116-
117-
steps:
118-
- name: Checkout repository
119-
uses: actions/checkout@v4
120-
121-
- name: Install nightly Rust toolchain
122-
# Nightly is used here because the docs.rs build
123-
# uses nightly and we use doc_cfg features that are
124-
# not in stable Rust as of this writing (Rust 1.76).
125-
uses: dtolnay/rust-toolchain@nightly
126-
127-
- name: Run cargo docs
128-
# This is intended to mimic the docs.rs build
129-
# environment. The goal is to fail PR validation
130-
# if the subsequent release would result in a failed
131-
# documentation build on docs.rs.
132-
run: cargo +nightly doc --workspace --all-features --no-deps
133-
env:
134-
RUSTDOCFLAGS: --cfg docsrs
135-
DOCS_RS: 1
136-
cargo-deny:
137-
name: License / vulnerability audit
138-
139-
if: |
140-
github.event_name != 'pull_request' ||
141-
github.event.pull_request.author_association == 'COLLABORATOR' ||
142-
github.event.pull_request.author_association == 'MEMBER' ||
143-
github.event.pull_request.user.login == 'dependabot[bot]' ||
144-
contains(github.event.pull_request.labels.*.name, 'safe to test')
145-
146-
runs-on: ubuntu-latest
147-
148-
strategy:
149-
fail-fast: false
150-
matrix:
151-
checks:
152-
- advisories
153-
- bans licenses sources
154-
155-
# Prevent sudden announcement of a new advisory from failing CI:
156-
continue-on-error: ${{ matrix.checks == 'advisories' }}
157-
158-
steps:
159-
- name: Checkout repository
160-
uses: actions/checkout@v4
161-
162-
- name: Audit crate dependencies
163-
uses: EmbarkStudios/cargo-deny-action@v2
164-
with:
165-
command: check ${{ matrix.checks }}
166-
167-
unused_deps:
168-
name: Check for unused dependencies
169-
170-
if: |
171-
github.event_name != 'pull_request' ||
172-
github.event.pull_request.author_association == 'COLLABORATOR' ||
173-
github.event.pull_request.author_association == 'MEMBER' ||
174-
github.event.pull_request.user.login == 'dependabot[bot]' ||
175-
contains(github.event.pull_request.labels.*.name, 'safe to test')
176-
177-
runs-on: ubuntu-latest
178-
179-
steps:
180-
- name: Checkout repository
181-
uses: actions/checkout@v4
182-
183-
- name: Install nightly Rust toolchain
184-
uses: dtolnay/rust-toolchain@nightly
185-
186-
- name: Run cargo-udeps
187-
uses: aig787/cargo-udeps-action@v1
188-
with:
189-
version: latest
190-
args: --all-targets --all-features
48+
python-version: "3.10"
49+
cache: "pip"
19150

51+
- run: python -m pip install --upgrade pip
52+
- run: python -m pip install -r requirements.txt
53+
- run: python -m pip install pytest
54+
- run: pytest
19255
linux:
19356
runs-on: ubuntu-latest
19457

@@ -208,35 +71,11 @@ jobs:
20871
with:
20972
python-version: "3.10"
21073
cache: "pip"
211-
- run: pip install -r requirements.txt
212-
- name: Setup QEMU
213-
uses: docker/setup-qemu-action@v1
214-
if: ${{ matrix.target == 'aarch64' }}
215-
- name: Build wheels
216-
uses: PyO3/maturin-action@v1
217-
with:
218-
target: ${{ matrix.target }}
219-
maturin-version: "1.2.0"
220-
args: --release --out dist --find-interpreter
221-
sccache: "true"
222-
manylinux: ${{ matrix.target == 'aarch64' && 'manylinux_2_28' || 'auto' }}
223-
before-script-linux: |
224-
pip install uniffi-bindgen==0.24.1
74+
- run:
75+
pip install -r requirements.txt
76+
python setup.py bdist_wheel
22577

226-
# ISSUE: https://github.com/sfackler/rust-openssl/issues/2036#issuecomment-1724324145
227-
# If we're running on rhel centos, install needed packages.
228-
if command -v yum &> /dev/null; then
229-
yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic
23078

231-
# If we're running on i686 we need to symlink libatomic
232-
# in order to build openssl with -latomic flag.
233-
if [[ ! -d "/usr/lib64" ]]; then
234-
ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so
235-
fi
236-
else
237-
# If we're running on debian-based system.
238-
apt update -y && apt-get install -y libssl-dev openssl pkg-config
239-
fi
24079
- name: Upload wheels
24180
uses: actions/upload-artifact@v4
24281
with:
@@ -263,13 +102,10 @@ jobs:
263102
python-version: '3.10'
264103
architecture: ${{ matrix.target }}
265104
cache: "pip"
266-
- run: pip install -r requirements.txt
267-
- name: Build wheels
268-
uses: PyO3/maturin-action@v1
269-
with:
270-
target: ${{ matrix.target }}
271-
args: --release --out dist --find-interpreter
272-
sccache: 'true'
105+
- run:
106+
pip install -r requirements.txt
107+
python setup.py bdist_wheel
108+
273109
- name: Upload wheels
274110
uses: actions/upload-artifact@v4
275111
with:
@@ -292,13 +128,9 @@ jobs:
292128
with:
293129
python-version: '3.10'
294130
cache: "pip"
295-
- run: pip install -r requirements.txt
296-
- name: Build wheels
297-
uses: PyO3/maturin-action@v1
298-
with:
299-
target: x86_64
300-
args: --release --out dist --find-interpreter
301-
sccache: 'true'
131+
- run:
132+
pip install -r requirements.txt
133+
python setup.py bdist_wheel
302134
- name: Upload wheels
303135
uses: actions/upload-artifact@v4
304136
with:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = "0.10.0"
88
requires-python = ">=3.8"
99
description = "Python bindings for the C2PA Content Authenticity Initiative (CAI) library"
1010
readme = { file = "README.md", content-type = "text/markdown" }
11-
license = {file = "LICENSE-MIT"}
11+
license-files = ["LICENSE-MIT", "LICENSE-APACHE"]
1212
authors = [{ name = "Gavin Peacock", email = "[email protected]" }]
1313
classifiers = [
1414
"Programming Language :: Python :: 3",

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
wheel==0.41.2 # For building wheels
33
setuptools==68.0.0 # For building packages
4+
toml ==0.10.2 # For reading pyproject.toml files
5+
46
# Testing dependencies
57
pytest==7.4.0
68
# only used in the training example

src/c2pa/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
__version__ = "0.10.0"
12

23
from .c2pa import * # NOQA

src/c2pa/build.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,28 @@ def download_artifacts() -> None:
7272
print(f"Unexpected error: {e}", file=sys.stderr)
7373
sys.exit(1)
7474

75+
def inject_version():
76+
"""Inject the version from pyproject.toml into src/c2pa/__init__.py as __version__."""
77+
import toml
78+
pyproject_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "pyproject.toml"))
79+
init_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "c2pa", "__init__.py"))
80+
with open(pyproject_path, "r") as f:
81+
pyproject = toml.load(f)
82+
version = pyproject["project"]["version"]
83+
# Read and update __init__.py
84+
lines = []
85+
if os.path.exists(init_path):
86+
with open(init_path, "r") as f:
87+
lines = [line for line in f if not line.startswith("__version__")]
88+
lines.insert(0, f'__version__ = "{version}"\n')
89+
with open(init_path, "w") as f:
90+
f.writelines(lines)
91+
7592
def initialize_build() -> None:
7693
"""Initialize the build process by downloading artifacts."""
94+
inject_version()
7795
download_artifacts()
7896

7997
if __name__ == "__main__":
98+
inject_version()
8099
download_artifacts()

0 commit comments

Comments
 (0)