Skip to content

Commit 0b22cea

Browse files
authored
fix: docs & more tests (#111)
* fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: Update test setup * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: upload of wheels * fix: Test * fix: Add test * fix: Refactor tests * fix: Reader test * fix: Update readme * fix: Docs * fix: Refactor * fix: benchmark * fix: CLeaning up * fix: Stream tests * fix: Reader tests * fix: Builder double close test * fix: Remove debug logs * fix: Fix typo * fix: Stream exception
1 parent 84a6103 commit 0b22cea

45 files changed

Lines changed: 823 additions & 303 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@
44
# Pre-requisite: Python virtual environment is active (source .venv/bin/activate)
55
# Run Pytest tests in virtualenv: .venv/bin/pytest tests/test_unit_tests.py -v
66

7+
# Removes build artifacts, distribution files, and other generated content
78
clean:
89
rm -rf artifacts/ build/ dist/
910

11+
# Performs a complete cleanup including uninstalling the c2pa package and clearing pip cache
1012
clean-c2pa-env: clean
1113
python3 -m pip uninstall -y c2pa
1214
python3 -m pip cache purge
1315

16+
# Installs all required dependencies from requirements.txt and requirements-dev.txt
1417
install-deps:
1518
python3 -m pip install -r requirements.txt
1619
python3 -m pip install -r requirements-dev.txt
1720
pip install -e .
1821

22+
# Installs the package in development mode
1923
build-python:
2024
pip install -e .
2125

26+
# Performs a complete rebuild of the development environment
2227
rebuild: clean-c2pa-env install-deps download-native-artifacts build-python
2328
@echo "Development rebuild done!"
2429

30+
# Runs the unit tests
2531
test:
2632
python3 ./tests/test_unit_tests.py
2733

34+
# Tests building and installing a local wheel package
35+
# Downloads required artifacts, builds the wheel, installs it, and verifies the installation
2836
test-local-wheel-build:
2937
# Clean any existing builds
3038
rm -rf build/ dist/
@@ -41,6 +49,8 @@ test-local-wheel-build:
4149
# Verify wheel structure
4250
twine check dist/*
4351

52+
# Tests building and installing a local source distribution package
53+
# Downloads required artifacts, builds the sdist, installs it, and verifies the installation
4454
test-local-sdist-build:
4555
# Clean any existing builds
4656
rm -rf build/ dist/
@@ -58,17 +68,21 @@ test-local-sdist-build:
5868
# Verify sdist structure
5969
twine check dist/*
6070

71+
# Verifies the wheel build process and checks the built package and its metadata
6172
verify-wheel-build:
6273
rm -rf build/ dist/ src/*.egg-info/
6374
python -m build
6475
twine check dist/*
6576

77+
# Manually publishes the package to PyPI after creating a release
6678
publish: release
6779
python3 -m pip install twine
6880
python3 -m twine upload dist/*
6981

82+
# Formats Python source code using autopep8 with aggressive settings
7083
format:
7184
autopep8 --aggressive --aggressive --in-place src/c2pa/*.py
7285

86+
# Downloads the required native artifacts for the specified version
7387
download-native-artifacts:
7488
python3 scripts/download_artifacts.py c2pa-v0.55.0

README.md

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,29 @@ This project provides a Python API for working with [C2PA](https://c2pa.org/) (C
1212
## Project Structure
1313

1414
```bash
15-
python_api/
16-
├── examples/ # Example scripts demonstrating usage
17-
├── src/ # Source code for the C2PA Python API
18-
│ └── c2pa/ # Main package directory
19-
│ └── libs/ # Platform-specific libraries
20-
├── tests/ # Unit tests and benchmarks
21-
├── artifacts/ # Platform-specific libraries for building
22-
│ ├── win_amd64/ # Windows x64 libraries
23-
│ ├── win_arm64/ # Windows ARM64 libraries
24-
│ ├── macosx_x86_64/ # macOS x64 libraries
25-
│ ├── macosx_arm64/ # macOS ARM64 libraries
26-
│ ├── linux_x86_64/ # Linux x64 libraries
27-
│ └── linux_aarch64/ # Linux ARM64 libraries
28-
├── requirements.txt # Python dependencies
29-
└── README.md # Project documentation
15+
.
16+
├── .github/ # GitHub configuration files
17+
├── artifacts/ # Platform-specific libraries for building (per subfolder)
18+
│ └── linux_x86_64/ # Linux ARM64 libraries
19+
├── docs/ # Project documentation
20+
├── examples/ # Example scripts demonstrating usage
21+
├── scripts/ # Utility scripts (eg. artifacts download)
22+
├── src/ # Source code
23+
│ └── c2pa/ # Main package directory
24+
│ └── libs/ # Platform-specific libraries
25+
├── tests/ # Unit tests and benchmarks
26+
├── .gitignore # Git ignore rules
27+
├── Makefile # Build and development commands
28+
├── pyproject.toml # Python project configuration
29+
├── requirements.txt # Python dependencies
30+
├── requirements-dev.txt # Development dependencies
31+
└── setup.py # Package setup script
3032
```
3133

3234
## Development Setup
3335

3436
1. Create and activate a virtual environment:
37+
3538
```bash
3639
# Create virtual environment
3740
python -m venv .venv
@@ -43,19 +46,20 @@ python -m venv .venv
4346
source .venv/bin/activate
4447

4548
# load project dependencies
46-
pip install -r requirements.txt
49+
pip install -r requirements.txt
4750

48-
# download library artifacts for the current version you want
49-
python scripts/download_artifacts.py c2pa-v0.49.5
51+
# download library artifacts for the current version you want, eg v0.55.0
52+
python scripts/download_artifacts.py c2pa-v0.55.0
5053
```
5154

52-
5355
2. Install the package in development mode:
56+
5457
```bash
5558
pip install -e .
5659
```
5760

5861
This will:
62+
5963
- Copy the appropriate libraries for your platform from `artifacts/` to `src/c2pa/libs/`
6064
- Install the package in development mode, allowing you to make changes to the Python code without reinstalling
6165

@@ -67,26 +71,42 @@ To build wheels for all platforms that have libraries in the `artifacts/` direct
6771
python setup.py bdist_wheel
6872
```
6973

74+
You can use `twine` to verify the wheels have correct metadata:
75+
76+
```bash
77+
twine check dist/*
78+
```
79+
7080
This will create platform-specific wheels in the `dist/` directory.
7181

7282
## Running Tests
7383

74-
Install pytest (if not already installed):
84+
Run the tests:
85+
86+
```bash
87+
make test
88+
```
89+
90+
Alternatively, install pytest (if not already installed):
91+
7592
```bash
7693
pip install pytest
7794
```
7895

79-
Run the tests:
96+
And run:
97+
8098
```bash
8199
pytest
82100
```
83101

84102
## Examples
85103

86104
### Adding a "Do Not Train" Assertion
105+
87106
The `examples/training.py` script demonstrates how to add a "Do Not Train" assertion to an asset and verify it.
88107

89108
### Signing and Verifying Assets
109+
90110
The `examples/test.py` script shows how to sign an asset with a C2PA manifest and verify it.
91111

92112
## Contributing
@@ -95,4 +115,4 @@ Contributions are welcome! Please fork the repository and submit a pull request.
95115

96116
## License
97117

98-
This project is licensed under the Apache License 2.0 or the MIT License. See the LICENSE-MIT and LICENSE-APACHE files for details.
118+
This project is licensed under the Apache License 2.0 or the MIT License. See the LICENSE-MIT and LICENSE-APACHE files for details.

README_saved.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ build==1.0.3 # For building packages using PEP 517/518
55
toml==0.10.2 # For reading pyproject.toml files
66

77
# Testing dependencies
8-
pytest==7.4.0
8+
pytest>=8.1.0
9+
pytest-benchmark>=5.1.0
910

1011
# for downloading the library artifacts
1112
requests>=2.0.0

setup.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,13 @@ def copy_platform_libraries(platform_name, clean_first=False):
103103
clean_first: If True, remove existing files in PACKAGE_LIBS_DIR first
104104
"""
105105
platform_dir = ARTIFACTS_DIR / platform_name
106-
print(" ")
107-
print('##### Found platform dir: ', platform_dir)
108-
print(" ")
109106

110107
# Ensure the platform directory exists and contains files
111108
if not platform_dir.exists():
112109
raise ValueError(f"Platform directory not found: {platform_dir}")
113110

114111
# Get list of all files in the platform directory
115112
platform_files = list(platform_dir.glob('*'))
116-
print(" ")
117-
print('##### Platform files: ', platform_files)
118-
print(" ")
119113
if not platform_files:
120114
raise ValueError(f"No files found in platform directory: {platform_dir}")
121115

@@ -124,9 +118,6 @@ def copy_platform_libraries(platform_name, clean_first=False):
124118
shutil.rmtree(PACKAGE_LIBS_DIR)
125119

126120
# Ensure the package libs directory exists
127-
print(" ")
128-
print('##### Package libs dir will be in: ', PACKAGE_LIBS_DIR)
129-
print(" ")
130121
PACKAGE_LIBS_DIR.mkdir(parents=True, exist_ok=True)
131122

132123
# Copy files from platform-specific directory to the package libs directory
@@ -189,9 +180,6 @@ def find_available_platforms():
189180
print(f"\nBuilding wheel for {platform_name}...")
190181
try:
191182
# Copy libraries for this platform (cleaning first)
192-
print(" ")
193-
print('##### Preparing to copy libraries to where they belong')
194-
print(" ")
195183
copy_platform_libraries(platform_name, clean_first=True)
196184

197185
# Build the wheel

src/c2pa/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
C2paSigningAlg,
88
C2paSignerInfo,
99
Signer,
10+
Stream,
1011
sdk_version
1112
) # NOQA
1213

@@ -18,5 +19,6 @@
1819
'C2paSigningAlg',
1920
'C2paSignerInfo',
2021
'Signer',
22+
'Stream',
2123
'sdk_version'
22-
]
24+
]

src/c2pa/build.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
GITHUB_API_BASE = "https://api.github.com"
1414
ARTIFACTS_DIR = Path("artifacts")
1515

16+
1617
def get_latest_release() -> dict:
1718
"""Get the latest release information from GitHub."""
1819
url = f"{GITHUB_API_BASE}/repos/{REPO_OWNER}/{REPO_NAME}/releases/latest"
1920
response = requests.get(url)
2021
response.raise_for_status()
2122
return response.json()
2223

24+
2325
def download_artifact(url: str, platform_name: str) -> None:
2426
"""Download and extract an artifact to the appropriate platform directory."""
2527
print(f"Downloading artifact for {platform_name}...")
@@ -37,7 +39,9 @@ def download_artifact(url: str, platform_name: str) -> None:
3739
# Extract all files to the platform directory
3840
zip_ref.extractall(platform_dir)
3941

40-
print(f"Successfully downloaded and extracted artifacts for {platform_name}")
42+
print(f"Successfully downloaded and extracted artifacts for {
43+
platform_name}")
44+
4145

4246
def download_artifacts() -> None:
4347
"""Main function to download artifacts. Can be called as a script or from hatch."""
@@ -72,11 +76,22 @@ def download_artifacts() -> None:
7276
print(f"Unexpected error: {e}", file=sys.stderr)
7377
sys.exit(1)
7478

79+
7580
def inject_version():
7681
"""Inject the version from pyproject.toml into src/c2pa/__init__.py as __version__."""
7782
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"))
83+
pyproject_path = os.path.abspath(
84+
os.path.join(
85+
os.path.dirname(__file__),
86+
"..",
87+
"..",
88+
"pyproject.toml"))
89+
init_path = os.path.abspath(
90+
os.path.join(
91+
os.path.dirname(__file__),
92+
"..",
93+
"c2pa",
94+
"__init__.py"))
8095
with open(pyproject_path, "r") as f:
8196
pyproject = toml.load(f)
8297
version = pyproject["project"]["version"]
@@ -89,11 +104,13 @@ def inject_version():
89104
with open(init_path, "w") as f:
90105
f.writelines(lines)
91106

107+
92108
def initialize_build() -> None:
93109
"""Initialize the build process by downloading artifacts."""
94110
inject_version()
95111
download_artifacts()
96112

113+
97114
if __name__ == "__main__":
98115
inject_version()
99-
download_artifacts()
116+
download_artifacts()

0 commit comments

Comments
 (0)