c2pa-python 0.15.0__py3-none-macosx_10_9_universal2.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
c2pa/__init__.py ADDED
@@ -0,0 +1,30 @@
1
+ try:
2
+ from importlib.metadata import version
3
+ __version__ = version("c2pa-python")
4
+ except ImportError: # pragma: no cover
5
+ __version__ = "unknown"
6
+
7
+ from .c2pa import (
8
+ Builder,
9
+ C2paError,
10
+ Reader,
11
+ C2paSigningAlg,
12
+ C2paSignerInfo,
13
+ Signer,
14
+ Stream,
15
+ sdk_version,
16
+ read_ingredient_file
17
+ ) # NOQA
18
+
19
+ # Re-export C2paError and its subclasses
20
+ __all__ = [
21
+ 'Builder',
22
+ 'C2paError',
23
+ 'Reader',
24
+ 'C2paSigningAlg',
25
+ 'C2paSignerInfo',
26
+ 'Signer',
27
+ 'Stream',
28
+ 'sdk_version',
29
+ 'read_ingredient_file'
30
+ ]
c2pa/build.py ADDED
@@ -0,0 +1,119 @@
1
+ import os
2
+ import sys
3
+ import requests
4
+ from pathlib import Path
5
+ import zipfile
6
+ import io
7
+
8
+ # Constants
9
+ REPO_OWNER = "contentauth"
10
+ REPO_NAME = "c2pa-rs"
11
+ GITHUB_API_BASE = "https://api.github.com"
12
+ ARTIFACTS_DIR = Path("artifacts")
13
+
14
+
15
+ def get_latest_release() -> dict:
16
+ """Get the latest release information from GitHub."""
17
+ url = f"{GITHUB_API_BASE}/repos/{REPO_OWNER}/{REPO_NAME}/releases/latest"
18
+ response = requests.get(url)
19
+ response.raise_for_status()
20
+ return response.json()
21
+
22
+
23
+ def download_artifact(url: str, platform_name: str) -> None:
24
+ """
25
+ Download and extract an artifact
26
+ to the appropriate platform directory.
27
+ """
28
+ print(f"Downloading artifact for {platform_name}...")
29
+
30
+ # Create platform directory
31
+ platform_dir = ARTIFACTS_DIR / platform_name
32
+ platform_dir.mkdir(parents=True, exist_ok=True)
33
+
34
+ # Download the zip file
35
+ response = requests.get(url)
36
+ response.raise_for_status()
37
+
38
+ # Extract the zip file
39
+ with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
40
+ # Extract all files to the platform directory
41
+ zip_ref.extractall(platform_dir)
42
+
43
+ print(f"Successfully downloaded and extracted artifacts for {
44
+ platform_name}")
45
+
46
+
47
+ def download_artifacts() -> None:
48
+ """Main function to download artifacts.
49
+ Can be called as a script or from hatch."""
50
+ try:
51
+ # Create artifacts directory if it doesn't exist
52
+ ARTIFACTS_DIR.mkdir(exist_ok=True)
53
+
54
+ # Get latest release
55
+ print("Fetching latest release information...")
56
+ release = get_latest_release()
57
+ print(f"Found release: {release['tag_name']}")
58
+
59
+ # Download each asset
60
+ for asset in release['assets']:
61
+ # Skip non-zip files
62
+ if not asset['name'].endswith('.zip'):
63
+ continue
64
+
65
+ # Determine platform from asset name
66
+ # Example: c2pa-rs-v1.0.0-macosx-arm64.zip
67
+ platform_name = asset['name'].split('-')[-1].replace('.zip', '')
68
+
69
+ # Download and extract the artifact
70
+ download_artifact(asset['browser_download_url'], platform_name)
71
+
72
+ print("\nAll artifacts have been downloaded successfully!")
73
+
74
+ except requests.exceptions.RequestException as e:
75
+ print(f"Error downloading artifacts: {e}", file=sys.stderr)
76
+ sys.exit(1)
77
+ except Exception as e:
78
+ print(f"Unexpected error: {e}", file=sys.stderr)
79
+ sys.exit(1)
80
+
81
+
82
+ def inject_version():
83
+ """Inject the version from pyproject.toml
84
+ into src/c2pa/__init__.py as __version__."""
85
+ import toml
86
+ pyproject_path = os.path.abspath(
87
+ os.path.join(
88
+ os.path.dirname(__file__),
89
+ "..",
90
+ "..",
91
+ "pyproject.toml"))
92
+ init_path = os.path.abspath(
93
+ os.path.join(
94
+ os.path.dirname(__file__),
95
+ "..",
96
+ "c2pa",
97
+ "__init__.py"))
98
+ with open(pyproject_path, "r") as f:
99
+ pyproject = toml.load(f)
100
+ version = pyproject["project"]["version"]
101
+ # Read and update __init__.py
102
+ lines = []
103
+ if os.path.exists(init_path):
104
+ with open(init_path, "r") as f:
105
+ lines = [line for line in f if not line.startswith("__version__")]
106
+ lines.insert(0, f'__version__ = "{version}"\n')
107
+ with open(init_path, "w") as f:
108
+ f.writelines(lines)
109
+
110
+
111
+ def initialize_build() -> None:
112
+ """Initialize the build process by downloading artifacts."""
113
+ inject_version()
114
+ download_artifacts()
115
+
116
+
117
+ if __name__ == "__main__":
118
+ inject_version()
119
+ download_artifacts()