Skip to content

Commit 4f766dd

Browse files
authored
fix: Simplify build (#107)
* fix: Some renaming going on * fix: Format * fix: Add scripts to debug builds, and clean env * fix: gitgnore * fix: Update makefile comments * fix: verbose debug logs * fix: Only keep the scripts we need * fix: Improve makefile
1 parent 9b9d35f commit 4f766dd

File tree

5 files changed

+62
-98
lines changed

5 files changed

+62
-98
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__/
44
*$py.class
55

66
/artifacts
7+
scripts/artifacts
78

89

910
# C extensions
@@ -108,3 +109,4 @@ target/
108109
*.dylib
109110
*.dll
110111
*.so
112+
src/c2pa/libs/

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,35 @@
33
# Start from clean env: Delete `.venv`, then `python3 -m venv .venv`
44
# Pre-requisite: Python virtual environment is active (source .venv/bin/activate)
55

6+
clean:
7+
rm -rf artifacts/ build/ dist/
8+
9+
clean-c2pa-env:
10+
python3 -m pip uninstall -y c2pa
11+
python3 -m pip cache purge
12+
613
build-python:
7-
python3 -m pip uninstall -y maturin
814
python3 -m pip install -r requirements.txt
915
python3 -m pip install -r requirements-dev.txt
1016
pip install -e .
1117

1218
test:
1319
python3 ./tests/test_unit_tests.py
1420

21+
test-local-wheel-build:
22+
# Clean any existing builds
23+
rm -rf build/ dist/
24+
# Download artifacts and place them where they should go
25+
python scripts/download_artifacts.py c2pa-v0.49.5
26+
# Install Python
27+
python3 -m pip install -r requirements.txt
28+
python3 -m pip install -r requirements-dev.txt
29+
python setup.py bdist_wheel
30+
# Install local build in venv
31+
pip install $$(ls dist/*.whl)
32+
# Verify installation in local venv
33+
python -c "import c2pa; print('C2PA package installed at:', c2pa.__file__)"
34+
1535
publish: release
1636
python3 -m pip install twine
1737
python3 -m twine upload dist/*

scripts/download_artifacts.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from pathlib import Path
66
import zipfile
77
import io
8+
import shutil
89

910
# Constants
1011
REPO_OWNER = "contentauth"
1112
REPO_NAME = "c2pa-rs"
1213
GITHUB_API_BASE = "https://api.github.com"
13-
ARTIFACTS_DIR = Path("artifacts")
14+
SCRIPTS_ARTIFACTS_DIR = Path("scripts/artifacts")
15+
ROOT_ARTIFACTS_DIR = Path("artifacts")
1416

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

2830
response = requests.get(url)
@@ -31,12 +33,28 @@ def download_and_extract_libs(url, platform_name):
3133
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
3234
# Extract only files inside the libs/ directory
3335
for member in zip_ref.namelist():
36+
print(f" Processing zip member: {member}")
3437
if member.startswith("lib/") and not member.endswith("/"):
38+
print(f" Processing lib file from downloadedzip: {member}")
3539
target_path = platform_dir / os.path.relpath(member, "lib")
40+
print(f" Moving file to target path: {target_path}")
3641
target_path.parent.mkdir(parents=True, exist_ok=True)
3742
with zip_ref.open(member) as source, open(target_path, "wb") as target:
3843
target.write(source.read())
39-
print(f"Successfully downloaded and extracted libraries for {platform_name}")
44+
45+
print(f"Done downloading and extracting libraries for {platform_name}")
46+
47+
def copy_artifacts_to_root():
48+
"""Copy the artifacts folder from scripts/artifacts to the root of the repository."""
49+
if not SCRIPTS_ARTIFACTS_DIR.exists():
50+
print("No artifacts found in scripts/artifacts")
51+
return
52+
53+
print("Copying artifacts from scripts/artifacts to root...")
54+
if ROOT_ARTIFACTS_DIR.exists():
55+
shutil.rmtree(ROOT_ARTIFACTS_DIR)
56+
shutil.copytree(SCRIPTS_ARTIFACTS_DIR, ROOT_ARTIFACTS_DIR)
57+
print("Done copying artifacts")
4058

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

4765
release_tag = sys.argv[1]
4866
try:
49-
ARTIFACTS_DIR.mkdir(exist_ok=True)
67+
SCRIPTS_ARTIFACTS_DIR.mkdir(exist_ok=True)
5068
print(f"Fetching release information for tag {release_tag}...")
5169
release = get_release_by_tag(release_tag)
5270
print(f"Found release: {release['tag_name']}")
5371

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

6584
download_and_extract_libs(asset['browser_download_url'], platform_name)
85+
artifacts_downloaded = True
6686

67-
print("\nAll artifacts have been downloaded and extracted successfully!")
87+
if artifacts_downloaded:
88+
print("\nAll artifacts have been downloaded and extracted successfully!")
89+
copy_artifacts_to_root()
6890

6991
except requests.exceptions.RequestException as e:
70-
print(f"Error downloading artifacts: {e}", file=sys.stderr)
92+
print(f"Error: {e}")
7193
sys.exit(1)
7294
except Exception as e:
73-
print(f"Unexpected error: {e}", file=sys.stderr)
95+
print(f"Error: {e}")
7496
sys.exit(1)
7597

7698
if __name__ == "__main__":

setup.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,29 @@ def get_current_platform():
3636

3737
def copy_platform_libraries(platform_name, clean_first=False):
3838
"""Copy libraries for a specific platform to the package libs directory.
39-
39+
4040
Args:
4141
platform_name: The platform to copy libraries for
4242
clean_first: If True, remove existing files in PACKAGE_LIBS_DIR first
4343
"""
4444
platform_dir = ARTIFACTS_DIR / platform_name
45-
45+
4646
# Ensure the platform directory exists and contains files
4747
if not platform_dir.exists():
4848
raise ValueError(f"Platform directory not found: {platform_dir}")
49-
49+
5050
# Get list of all files in the platform directory
5151
platform_files = list(platform_dir.glob('*'))
5252
if not platform_files:
5353
raise ValueError(f"No files found in platform directory: {platform_dir}")
54-
54+
5555
# Clean and recreate the package libs directory if requested
5656
if clean_first and PACKAGE_LIBS_DIR.exists():
5757
shutil.rmtree(PACKAGE_LIBS_DIR)
58-
58+
5959
# Ensure the package libs directory exists
6060
PACKAGE_LIBS_DIR.mkdir(parents=True, exist_ok=True)
61-
61+
6262
# Copy files from platform-specific directory to the package libs directory
6363
for file in platform_files:
6464
if file.is_file():
@@ -85,10 +85,10 @@ def find_available_platforms():
8585
platform_dir = ARTIFACTS_DIR / platform_name
8686
if platform_dir.exists() and any(platform_dir.iterdir()):
8787
available_platforms.append(platform_name)
88-
88+
8989
if not available_platforms:
9090
raise ValueError("No platform-specific libraries found in artifacts directory")
91-
91+
9292
return available_platforms
9393

9494
# For development installation
@@ -100,13 +100,13 @@ def find_available_platforms():
100100
if 'bdist_wheel' in sys.argv:
101101
available_platforms = find_available_platforms()
102102
print(f"Found libraries for platforms: {', '.join(available_platforms)}")
103-
103+
104104
for platform_name in available_platforms:
105105
print(f"\nBuilding wheel for {platform_name}...")
106106
try:
107107
# Copy libraries for this platform (cleaning first)
108108
copy_platform_libraries(platform_name, clean_first=True)
109-
109+
110110
# Build the wheel
111111
setup(
112112
name="c2pa",

src/c2pa/build.py

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

0 commit comments

Comments
 (0)