Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ __pycache__/
*$py.class

/artifacts
scripts/artifacts


# C extensions
Expand Down Expand Up @@ -108,3 +109,4 @@ target/
*.dylib
*.dll
*.so
src/c2pa/libs/
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,35 @@
# Start from clean env: Delete `.venv`, then `python3 -m venv .venv`
# Pre-requisite: Python virtual environment is active (source .venv/bin/activate)

clean:
rm -rf artifacts/ build/ dist/

clean-c2pa-env:
python3 -m pip uninstall -y c2pa
python3 -m pip cache purge

build-python:
python3 -m pip uninstall -y maturin
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt
pip install -e .

test:
python3 ./tests/test_unit_tests.py

test-local-wheel-build:
# Clean any existing builds
rm -rf build/ dist/
# Download artifacts and place them where they should go
python scripts/download_artifacts.py c2pa-v0.49.5
# Install Python
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt
python setup.py bdist_wheel
# Install local build in venv
pip install $$(ls dist/*.whl)
# Verify installation in local venv
python -c "import c2pa; print('C2PA package installed at:', c2pa.__file__)"

publish: release
python3 -m pip install twine
python3 -m twine upload dist/*
36 changes: 29 additions & 7 deletions scripts/download_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from pathlib import Path
import zipfile
import io
import shutil

# Constants
REPO_OWNER = "contentauth"
REPO_NAME = "c2pa-rs"
GITHUB_API_BASE = "https://api.github.com"
ARTIFACTS_DIR = Path("artifacts")
SCRIPTS_ARTIFACTS_DIR = Path("scripts/artifacts")
ROOT_ARTIFACTS_DIR = Path("artifacts")

def get_release_by_tag(tag):
"""Get release information for a specific tag from GitHub."""
Expand All @@ -22,7 +24,7 @@ def get_release_by_tag(tag):
def download_and_extract_libs(url, platform_name):
"""Download a zip artifact and extract only the libs folder."""
print(f"Downloading artifact for {platform_name}...")
platform_dir = ARTIFACTS_DIR / platform_name
platform_dir = SCRIPTS_ARTIFACTS_DIR / platform_name
platform_dir.mkdir(parents=True, exist_ok=True)

response = requests.get(url)
Expand All @@ -31,12 +33,28 @@ def download_and_extract_libs(url, platform_name):
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
# Extract only files inside the libs/ directory
for member in zip_ref.namelist():
print(f" Processing zip member: {member}")
if member.startswith("lib/") and not member.endswith("/"):
print(f" Processing lib file from downloadedzip: {member}")
target_path = platform_dir / os.path.relpath(member, "lib")
print(f" Moving file to target path: {target_path}")
target_path.parent.mkdir(parents=True, exist_ok=True)
with zip_ref.open(member) as source, open(target_path, "wb") as target:
target.write(source.read())
print(f"Successfully downloaded and extracted libraries for {platform_name}")

print(f"Done downloading and extracting libraries for {platform_name}")

def copy_artifacts_to_root():
"""Copy the artifacts folder from scripts/artifacts to the root of the repository."""
if not SCRIPTS_ARTIFACTS_DIR.exists():
print("No artifacts found in scripts/artifacts")
return

print("Copying artifacts from scripts/artifacts to root...")
if ROOT_ARTIFACTS_DIR.exists():
shutil.rmtree(ROOT_ARTIFACTS_DIR)
shutil.copytree(SCRIPTS_ARTIFACTS_DIR, ROOT_ARTIFACTS_DIR)
print("Done copying artifacts")

def main():
if len(sys.argv) < 2:
Expand All @@ -46,11 +64,12 @@ def main():

release_tag = sys.argv[1]
try:
ARTIFACTS_DIR.mkdir(exist_ok=True)
SCRIPTS_ARTIFACTS_DIR.mkdir(exist_ok=True)
print(f"Fetching release information for tag {release_tag}...")
release = get_release_by_tag(release_tag)
print(f"Found release: {release['tag_name']}")

artifacts_downloaded = False
for asset in release['assets']:
if not asset['name'].endswith('.zip'):
continue
Expand All @@ -63,14 +82,17 @@ def main():
platform_name = '-'.join(parts[3:]).replace('.zip', '')

download_and_extract_libs(asset['browser_download_url'], platform_name)
artifacts_downloaded = True

print("\nAll artifacts have been downloaded and extracted successfully!")
if artifacts_downloaded:
print("\nAll artifacts have been downloaded and extracted successfully!")
copy_artifacts_to_root()

except requests.exceptions.RequestException as e:
print(f"Error downloading artifacts: {e}", file=sys.stderr)
print(f"Error: {e}")
sys.exit(1)
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
print(f"Error: {e}")
sys.exit(1)

if __name__ == "__main__":
Expand Down
20 changes: 10 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,29 @@ def get_current_platform():

def copy_platform_libraries(platform_name, clean_first=False):
"""Copy libraries for a specific platform to the package libs directory.

Args:
platform_name: The platform to copy libraries for
clean_first: If True, remove existing files in PACKAGE_LIBS_DIR first
"""
platform_dir = ARTIFACTS_DIR / platform_name

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

# Get list of all files in the platform directory
platform_files = list(platform_dir.glob('*'))
if not platform_files:
raise ValueError(f"No files found in platform directory: {platform_dir}")

# Clean and recreate the package libs directory if requested
if clean_first and PACKAGE_LIBS_DIR.exists():
shutil.rmtree(PACKAGE_LIBS_DIR)

# Ensure the package libs directory exists
PACKAGE_LIBS_DIR.mkdir(parents=True, exist_ok=True)

# Copy files from platform-specific directory to the package libs directory
for file in platform_files:
if file.is_file():
Expand All @@ -85,10 +85,10 @@ def find_available_platforms():
platform_dir = ARTIFACTS_DIR / platform_name
if platform_dir.exists() and any(platform_dir.iterdir()):
available_platforms.append(platform_name)

if not available_platforms:
raise ValueError("No platform-specific libraries found in artifacts directory")

return available_platforms

# For development installation
Expand All @@ -100,13 +100,13 @@ def find_available_platforms():
if 'bdist_wheel' in sys.argv:
available_platforms = find_available_platforms()
print(f"Found libraries for platforms: {', '.join(available_platforms)}")

for platform_name in available_platforms:
print(f"\nBuilding wheel for {platform_name}...")
try:
# Copy libraries for this platform (cleaning first)
copy_platform_libraries(platform_name, clean_first=True)

# Build the wheel
setup(
name="c2pa",
Expand Down
80 changes: 0 additions & 80 deletions src/c2pa/build.py

This file was deleted.

Loading