From 7983884dddc5d8085e07e2b026fe06a5c18bca5f Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 13:56:54 -0700 Subject: [PATCH 1/8] fix: Some renaming going on --- MANIFEST.in | 2 +- Makefile | 2 +- requirements-dev.txt | 9 +++++++++ requirements.txt | 11 ++--------- src/c2pa/build.py | 22 +++++++++++----------- src/c2pa/lib.py | 4 ++-- 6 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 requirements-dev.txt diff --git a/MANIFEST.in b/MANIFEST.in index 5ded421c..08d9b5d5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ include src/c2pa/libs/*.dylib include src/c2pa/libs/*.dll -include src/c2pa/libs/*.so \ No newline at end of file +include src/c2pa/libs/*.so \ No newline at end of file diff --git a/Makefile b/Makefile index 809aa7ec..2938e3d5 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ 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 - python3 ./tests/test_api.py publish: release python3 -m pip install twine diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..31f36529 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,9 @@ +# Build dependencies +wheel==0.41.2 # For building wheels +setuptools==68.0.0 # For building packages + +# Testing dependencies +pytest==7.4.0 + +# for downloading the library artifacts +requests>=2.0.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6f937501..596f3d8e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,2 @@ - -wheel==0.41.2 # For building wheels -setuptools==68.0.0 # For building packages -# Testing dependencies -pytest==7.4.0 - # only used in the training example -cryptography>=41.0.0 -# for downloading the library artifacts -requests>=2.0.0 \ No newline at end of file +# only used in the training example +cryptography>=41.0.0 \ No newline at end of file diff --git a/src/c2pa/build.py b/src/c2pa/build.py index 2a252925..106dab9c 100644 --- a/src/c2pa/build.py +++ b/src/c2pa/build.py @@ -23,20 +23,20 @@ def get_latest_release() -> dict: def download_artifact(url: str, platform_name: str) -> None: """Download and extract an artifact to the appropriate platform directory.""" print(f"Downloading artifact for {platform_name}...") - + # Create platform directory platform_dir = ARTIFACTS_DIR / platform_name platform_dir.mkdir(parents=True, exist_ok=True) - + # Download the zip file response = requests.get(url) response.raise_for_status() - + # Extract the zip file with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref: # Extract all files to the platform directory zip_ref.extractall(platform_dir) - + print(f"Successfully downloaded and extracted artifacts for {platform_name}") def download_artifacts() -> None: @@ -44,27 +44,27 @@ def download_artifacts() -> None: try: # Create artifacts directory if it doesn't exist ARTIFACTS_DIR.mkdir(exist_ok=True) - + # Get latest release print("Fetching latest release information...") release = get_latest_release() print(f"Found release: {release['tag_name']}") - + # Download each asset for asset in release['assets']: # Skip non-zip files if not asset['name'].endswith('.zip'): continue - + # Determine platform from asset name # Example: c2pa-rs-v1.0.0-macosx-arm64.zip platform_name = asset['name'].split('-')[-1].replace('.zip', '') - + # Download and extract the artifact download_artifact(asset['browser_download_url'], platform_name) - + print("\nAll artifacts have been downloaded successfully!") - + except requests.exceptions.RequestException as e: print(f"Error downloading artifacts: {e}", file=sys.stderr) sys.exit(1) @@ -77,4 +77,4 @@ def initialize_build() -> None: download_artifacts() if __name__ == "__main__": - download_artifacts() \ No newline at end of file + download_artifacts() \ No newline at end of file diff --git a/src/c2pa/lib.py b/src/c2pa/lib.py index 880e9238..9b4bdb64 100644 --- a/src/c2pa/lib.py +++ b/src/c2pa/lib.py @@ -83,7 +83,7 @@ def dynamically_load_library(lib_name: Optional[str] = None) -> Optional[ctypes. # Package directory Path(__file__).parent, # Additional library directory - Path(__file__).parent / "lib", + Path(__file__).parent / "libs", # System library paths *[Path(p) for p in os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep) if p], ] @@ -95,7 +95,7 @@ def dynamically_load_library(lib_name: Optional[str] = None) -> Optional[ctypes. raise RuntimeError(f"Could not find {lib_name} in any of the search paths") return lib - # Default paht (no library name provided in the environment) + # Default path (no library name provided in the environment) c2pa_lib = _load_single_library(c2pa_lib_name, possible_paths) if not c2pa_lib: raise RuntimeError(f"Could not find {c2pa_lib_name} in any of the search paths") From 74940daf30354fdf8206eb18fbbe17b380d5bf02 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:29:27 -0700 Subject: [PATCH 2/8] fix: Format --- setup.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 18662687..bf70864c 100644 --- a/setup.py +++ b/setup.py @@ -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(): @@ -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 @@ -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", From cf90e91c86132c97be10f8881b09f8558f887091 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:41:08 -0700 Subject: [PATCH 3/8] fix: Add scripts to debug builds, and clean env --- .venv-test/bin/Activate.ps1 | 247 +++++++++++++++++++++++++++++++++++ .venv-test/bin/activate | 71 ++++++++++ .venv-test/bin/activate.csh | 27 ++++ .venv-test/bin/activate.fish | 69 ++++++++++ .venv-test/bin/pip | 8 ++ .venv-test/bin/pip3 | 8 ++ .venv-test/bin/pip3.12 | 8 ++ .venv-test/bin/python | 1 + .venv-test/bin/python3 | 1 + .venv-test/bin/python3.12 | 1 + .venv-test/pyvenv.cfg | 5 + Makefile | 14 +- 12 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 .venv-test/bin/Activate.ps1 create mode 100644 .venv-test/bin/activate create mode 100644 .venv-test/bin/activate.csh create mode 100644 .venv-test/bin/activate.fish create mode 100755 .venv-test/bin/pip create mode 100755 .venv-test/bin/pip3 create mode 100755 .venv-test/bin/pip3.12 create mode 120000 .venv-test/bin/python create mode 120000 .venv-test/bin/python3 create mode 120000 .venv-test/bin/python3.12 create mode 100644 .venv-test/pyvenv.cfg diff --git a/.venv-test/bin/Activate.ps1 b/.venv-test/bin/Activate.ps1 new file mode 100644 index 00000000..b49d77ba --- /dev/null +++ b/.venv-test/bin/Activate.ps1 @@ -0,0 +1,247 @@ +<# +.Synopsis +Activate a Python virtual environment for the current PowerShell session. + +.Description +Pushes the python executable for a virtual environment to the front of the +$Env:PATH environment variable and sets the prompt to signify that you are +in a Python virtual environment. Makes use of the command line switches as +well as the `pyvenv.cfg` file values present in the virtual environment. + +.Parameter VenvDir +Path to the directory that contains the virtual environment to activate. The +default value for this is the parent of the directory that the Activate.ps1 +script is located within. + +.Parameter Prompt +The prompt prefix to display when this virtual environment is activated. By +default, this prompt is the name of the virtual environment folder (VenvDir) +surrounded by parentheses and followed by a single space (ie. '(.venv) '). + +.Example +Activate.ps1 +Activates the Python virtual environment that contains the Activate.ps1 script. + +.Example +Activate.ps1 -Verbose +Activates the Python virtual environment that contains the Activate.ps1 script, +and shows extra information about the activation as it executes. + +.Example +Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv +Activates the Python virtual environment located in the specified location. + +.Example +Activate.ps1 -Prompt "MyPython" +Activates the Python virtual environment that contains the Activate.ps1 script, +and prefixes the current prompt with the specified string (surrounded in +parentheses) while the virtual environment is active. + +.Notes +On Windows, it may be required to enable this Activate.ps1 script by setting the +execution policy for the user. You can do this by issuing the following PowerShell +command: + +PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + +For more information on Execution Policies: +https://go.microsoft.com/fwlink/?LinkID=135170 + +#> +Param( + [Parameter(Mandatory = $false)] + [String] + $VenvDir, + [Parameter(Mandatory = $false)] + [String] + $Prompt +) + +<# Function declarations --------------------------------------------------- #> + +<# +.Synopsis +Remove all shell session elements added by the Activate script, including the +addition of the virtual environment's Python executable from the beginning of +the PATH variable. + +.Parameter NonDestructive +If present, do not remove this function from the global namespace for the +session. + +#> +function global:deactivate ([switch]$NonDestructive) { + # Revert to original values + + # The prior prompt: + if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { + Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt + Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT + } + + # The prior PYTHONHOME: + if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { + Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME + Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME + } + + # The prior PATH: + if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { + Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH + Remove-Item -Path Env:_OLD_VIRTUAL_PATH + } + + # Just remove the VIRTUAL_ENV altogether: + if (Test-Path -Path Env:VIRTUAL_ENV) { + Remove-Item -Path env:VIRTUAL_ENV + } + + # Just remove VIRTUAL_ENV_PROMPT altogether. + if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { + Remove-Item -Path env:VIRTUAL_ENV_PROMPT + } + + # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: + if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { + Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force + } + + # Leave deactivate function in the global namespace if requested: + if (-not $NonDestructive) { + Remove-Item -Path function:deactivate + } +} + +<# +.Description +Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the +given folder, and returns them in a map. + +For each line in the pyvenv.cfg file, if that line can be parsed into exactly +two strings separated by `=` (with any amount of whitespace surrounding the =) +then it is considered a `key = value` line. The left hand string is the key, +the right hand is the value. + +If the value starts with a `'` or a `"` then the first and last character is +stripped from the value before being captured. + +.Parameter ConfigDir +Path to the directory that contains the `pyvenv.cfg` file. +#> +function Get-PyVenvConfig( + [String] + $ConfigDir +) { + Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" + + # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). + $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue + + # An empty map will be returned if no config file is found. + $pyvenvConfig = @{ } + + if ($pyvenvConfigPath) { + + Write-Verbose "File exists, parse `key = value` lines" + $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath + + $pyvenvConfigContent | ForEach-Object { + $keyval = $PSItem -split "\s*=\s*", 2 + if ($keyval[0] -and $keyval[1]) { + $val = $keyval[1] + + # Remove extraneous quotations around a string value. + if ("'""".Contains($val.Substring(0, 1))) { + $val = $val.Substring(1, $val.Length - 2) + } + + $pyvenvConfig[$keyval[0]] = $val + Write-Verbose "Adding Key: '$($keyval[0])'='$val'" + } + } + } + return $pyvenvConfig +} + + +<# Begin Activate script --------------------------------------------------- #> + +# Determine the containing directory of this script +$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition +$VenvExecDir = Get-Item -Path $VenvExecPath + +Write-Verbose "Activation script is located in path: '$VenvExecPath'" +Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" +Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" + +# Set values required in priority: CmdLine, ConfigFile, Default +# First, get the location of the virtual environment, it might not be +# VenvExecDir if specified on the command line. +if ($VenvDir) { + Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" +} +else { + Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." + $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") + Write-Verbose "VenvDir=$VenvDir" +} + +# Next, read the `pyvenv.cfg` file to determine any required value such +# as `prompt`. +$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir + +# Next, set the prompt from the command line, or the config file, or +# just use the name of the virtual environment folder. +if ($Prompt) { + Write-Verbose "Prompt specified as argument, using '$Prompt'" +} +else { + Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" + if ($pyvenvCfg -and $pyvenvCfg['prompt']) { + Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" + $Prompt = $pyvenvCfg['prompt']; + } + else { + Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)" + Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" + $Prompt = Split-Path -Path $venvDir -Leaf + } +} + +Write-Verbose "Prompt = '$Prompt'" +Write-Verbose "VenvDir='$VenvDir'" + +# Deactivate any currently active virtual environment, but leave the +# deactivate function in place. +deactivate -nondestructive + +# Now set the environment variable VIRTUAL_ENV, used by many tools to determine +# that there is an activated venv. +$env:VIRTUAL_ENV = $VenvDir + +if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { + + Write-Verbose "Setting prompt to '$Prompt'" + + # Set the prompt to include the env name + # Make sure _OLD_VIRTUAL_PROMPT is global + function global:_OLD_VIRTUAL_PROMPT { "" } + Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT + New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt + + function global:prompt { + Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " + _OLD_VIRTUAL_PROMPT + } + $env:VIRTUAL_ENV_PROMPT = $Prompt +} + +# Clear PYTHONHOME +if (Test-Path -Path Env:PYTHONHOME) { + Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME + Remove-Item -Path Env:PYTHONHOME +} + +# Add the venv to the PATH +Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH +$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" diff --git a/.venv-test/bin/activate b/.venv-test/bin/activate new file mode 100644 index 00000000..16765578 --- /dev/null +++ b/.venv-test/bin/activate @@ -0,0 +1,71 @@ +# This file must be used with "source bin/activate" *from bash* +# You cannot run it directly + +deactivate () { + # reset old environment variables + if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then + PATH="${_OLD_VIRTUAL_PATH:-}" + export PATH + unset _OLD_VIRTUAL_PATH + fi + if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then + PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" + export PYTHONHOME + unset _OLD_VIRTUAL_PYTHONHOME + fi + + # Call hash to forget past locations. Without forgetting + # past locations the $PATH changes we made may not be respected. + # See "man bash" for more details. hash is usually a builtin of your shell + hash -r 2> /dev/null + + if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then + PS1="${_OLD_VIRTUAL_PS1:-}" + export PS1 + unset _OLD_VIRTUAL_PS1 + fi + + unset VIRTUAL_ENV + unset VIRTUAL_ENV_PROMPT + if [ ! "${1:-}" = "nondestructive" ] ; then + # Self destruct! + unset -f deactivate + fi +} + +# unset irrelevant variables +deactivate nondestructive + +# on Windows, a path can contain colons and backslashes and has to be converted: +if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then + # transform D:\path\to\venv to /d/path/to/venv on MSYS + # and to /cygdrive/d/path/to/venv on Cygwin + export VIRTUAL_ENV=$(cygpath /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test) +else + # use the path as-is + export VIRTUAL_ENV=/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test +fi + +_OLD_VIRTUAL_PATH="$PATH" +PATH="$VIRTUAL_ENV/"bin":$PATH" +export PATH + +# unset PYTHONHOME if set +# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) +# could use `if (set -u; : $PYTHONHOME) ;` in bash +if [ -n "${PYTHONHOME:-}" ] ; then + _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" + unset PYTHONHOME +fi + +if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then + _OLD_VIRTUAL_PS1="${PS1:-}" + PS1='(.venv-test) '"${PS1:-}" + export PS1 + VIRTUAL_ENV_PROMPT='(.venv-test) ' + export VIRTUAL_ENV_PROMPT +fi + +# Call hash to forget past commands. Without forgetting +# past commands the $PATH changes we made may not be respected +hash -r 2> /dev/null diff --git a/.venv-test/bin/activate.csh b/.venv-test/bin/activate.csh new file mode 100644 index 00000000..9d058967 --- /dev/null +++ b/.venv-test/bin/activate.csh @@ -0,0 +1,27 @@ +# This file must be used with "source bin/activate.csh" *from csh*. +# You cannot run it directly. + +# Created by Davide Di Blasi . +# Ported to Python 3.3 venv by Andrew Svetlov + +alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate' + +# Unset irrelevant variables. +deactivate nondestructive + +setenv VIRTUAL_ENV /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test + +set _OLD_VIRTUAL_PATH="$PATH" +setenv PATH "$VIRTUAL_ENV/"bin":$PATH" + + +set _OLD_VIRTUAL_PROMPT="$prompt" + +if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then + set prompt = '(.venv-test) '"$prompt" + setenv VIRTUAL_ENV_PROMPT '(.venv-test) ' +endif + +alias pydoc python -m pydoc + +rehash diff --git a/.venv-test/bin/activate.fish b/.venv-test/bin/activate.fish new file mode 100644 index 00000000..522083eb --- /dev/null +++ b/.venv-test/bin/activate.fish @@ -0,0 +1,69 @@ +# This file must be used with "source /bin/activate.fish" *from fish* +# (https://fishshell.com/). You cannot run it directly. + +function deactivate -d "Exit virtual environment and return to normal shell environment" + # reset old environment variables + if test -n "$_OLD_VIRTUAL_PATH" + set -gx PATH $_OLD_VIRTUAL_PATH + set -e _OLD_VIRTUAL_PATH + end + if test -n "$_OLD_VIRTUAL_PYTHONHOME" + set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME + set -e _OLD_VIRTUAL_PYTHONHOME + end + + if test -n "$_OLD_FISH_PROMPT_OVERRIDE" + set -e _OLD_FISH_PROMPT_OVERRIDE + # prevents error when using nested fish instances (Issue #93858) + if functions -q _old_fish_prompt + functions -e fish_prompt + functions -c _old_fish_prompt fish_prompt + functions -e _old_fish_prompt + end + end + + set -e VIRTUAL_ENV + set -e VIRTUAL_ENV_PROMPT + if test "$argv[1]" != "nondestructive" + # Self-destruct! + functions -e deactivate + end +end + +# Unset irrelevant variables. +deactivate nondestructive + +set -gx VIRTUAL_ENV /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test + +set -gx _OLD_VIRTUAL_PATH $PATH +set -gx PATH "$VIRTUAL_ENV/"bin $PATH + +# Unset PYTHONHOME if set. +if set -q PYTHONHOME + set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME + set -e PYTHONHOME +end + +if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" + # fish uses a function instead of an env var to generate the prompt. + + # Save the current fish_prompt function as the function _old_fish_prompt. + functions -c fish_prompt _old_fish_prompt + + # With the original prompt function renamed, we can override with our own. + function fish_prompt + # Save the return status of the last command. + set -l old_status $status + + # Output the venv prompt; color taken from the blue of the Python logo. + printf "%s%s%s" (set_color 4B8BBE) '(.venv-test) ' (set_color normal) + + # Restore the return status of the previous command. + echo "exit $old_status" | . + # Output the original/"old" prompt. + _old_fish_prompt + end + + set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" + set -gx VIRTUAL_ENV_PROMPT '(.venv-test) ' +end diff --git a/.venv-test/bin/pip b/.venv-test/bin/pip new file mode 100755 index 00000000..b73e4adc --- /dev/null +++ b/.venv-test/bin/pip @@ -0,0 +1,8 @@ +#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/.venv-test/bin/pip3 b/.venv-test/bin/pip3 new file mode 100755 index 00000000..b73e4adc --- /dev/null +++ b/.venv-test/bin/pip3 @@ -0,0 +1,8 @@ +#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/.venv-test/bin/pip3.12 b/.venv-test/bin/pip3.12 new file mode 100755 index 00000000..b73e4adc --- /dev/null +++ b/.venv-test/bin/pip3.12 @@ -0,0 +1,8 @@ +#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/.venv-test/bin/python b/.venv-test/bin/python new file mode 120000 index 00000000..11b9d885 --- /dev/null +++ b/.venv-test/bin/python @@ -0,0 +1 @@ +python3.12 \ No newline at end of file diff --git a/.venv-test/bin/python3 b/.venv-test/bin/python3 new file mode 120000 index 00000000..11b9d885 --- /dev/null +++ b/.venv-test/bin/python3 @@ -0,0 +1 @@ +python3.12 \ No newline at end of file diff --git a/.venv-test/bin/python3.12 b/.venv-test/bin/python3.12 new file mode 120000 index 00000000..a7a5fcca --- /dev/null +++ b/.venv-test/bin/python3.12 @@ -0,0 +1 @@ +/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 \ No newline at end of file diff --git a/.venv-test/pyvenv.cfg b/.venv-test/pyvenv.cfg new file mode 100644 index 00000000..8ff2b676 --- /dev/null +++ b/.venv-test/pyvenv.cfg @@ -0,0 +1,5 @@ +home = /Library/Frameworks/Python.framework/Versions/3.12/bin +include-system-site-packages = false +version = 3.12.8 +executable = /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 +command = /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv/bin/python -m venv /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test diff --git a/Makefile b/Makefile index 2938e3d5..7c9a98d3 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,11 @@ # Start from clean env: Delete `.venv`, then `python3 -m venv .venv` # Pre-requisite: Python virtual environment is active (source .venv/bin/activate) +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 . @@ -12,6 +15,15 @@ build-python: test: python3 ./tests/test_unit_tests.py +test-local-wheel-build: + # Clean any existing builds + rm -rf build/ dist/ + python3 -m pip install -r requirements.txt + python3 -m pip install -r requirements-dev.txt + python setup.py bdist_wheel + pip install $$(ls dist/*.whl) + python -c "import c2pa; print('C2PA package installed at:', c2pa.__file__)" + publish: release python3 -m pip install twine python3 -m twine upload dist/* From a60f6cb988ff7aea7f9ca9a8a7443d0ad6bab36f Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:43:36 -0700 Subject: [PATCH 4/8] fix: gitgnore --- .gitignore | 1 + .venv-test/bin/Activate.ps1 | 247 ----------------------------------- .venv-test/bin/activate | 71 ---------- .venv-test/bin/activate.csh | 27 ---- .venv-test/bin/activate.fish | 69 ---------- .venv-test/bin/pip | 8 -- .venv-test/bin/pip3 | 8 -- .venv-test/bin/pip3.12 | 8 -- .venv-test/bin/python | 1 - .venv-test/bin/python3 | 1 - .venv-test/bin/python3.12 | 1 - .venv-test/pyvenv.cfg | 5 - 12 files changed, 1 insertion(+), 446 deletions(-) delete mode 100644 .venv-test/bin/Activate.ps1 delete mode 100644 .venv-test/bin/activate delete mode 100644 .venv-test/bin/activate.csh delete mode 100644 .venv-test/bin/activate.fish delete mode 100755 .venv-test/bin/pip delete mode 100755 .venv-test/bin/pip3 delete mode 100755 .venv-test/bin/pip3.12 delete mode 120000 .venv-test/bin/python delete mode 120000 .venv-test/bin/python3 delete mode 120000 .venv-test/bin/python3.12 delete mode 100644 .venv-test/pyvenv.cfg diff --git a/.gitignore b/.gitignore index 8a4c8936..1a856fb1 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,4 @@ target/ *.dylib *.dll *.so +src/c2pa/libs/ diff --git a/.venv-test/bin/Activate.ps1 b/.venv-test/bin/Activate.ps1 deleted file mode 100644 index b49d77ba..00000000 --- a/.venv-test/bin/Activate.ps1 +++ /dev/null @@ -1,247 +0,0 @@ -<# -.Synopsis -Activate a Python virtual environment for the current PowerShell session. - -.Description -Pushes the python executable for a virtual environment to the front of the -$Env:PATH environment variable and sets the prompt to signify that you are -in a Python virtual environment. Makes use of the command line switches as -well as the `pyvenv.cfg` file values present in the virtual environment. - -.Parameter VenvDir -Path to the directory that contains the virtual environment to activate. The -default value for this is the parent of the directory that the Activate.ps1 -script is located within. - -.Parameter Prompt -The prompt prefix to display when this virtual environment is activated. By -default, this prompt is the name of the virtual environment folder (VenvDir) -surrounded by parentheses and followed by a single space (ie. '(.venv) '). - -.Example -Activate.ps1 -Activates the Python virtual environment that contains the Activate.ps1 script. - -.Example -Activate.ps1 -Verbose -Activates the Python virtual environment that contains the Activate.ps1 script, -and shows extra information about the activation as it executes. - -.Example -Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv -Activates the Python virtual environment located in the specified location. - -.Example -Activate.ps1 -Prompt "MyPython" -Activates the Python virtual environment that contains the Activate.ps1 script, -and prefixes the current prompt with the specified string (surrounded in -parentheses) while the virtual environment is active. - -.Notes -On Windows, it may be required to enable this Activate.ps1 script by setting the -execution policy for the user. You can do this by issuing the following PowerShell -command: - -PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - -For more information on Execution Policies: -https://go.microsoft.com/fwlink/?LinkID=135170 - -#> -Param( - [Parameter(Mandatory = $false)] - [String] - $VenvDir, - [Parameter(Mandatory = $false)] - [String] - $Prompt -) - -<# Function declarations --------------------------------------------------- #> - -<# -.Synopsis -Remove all shell session elements added by the Activate script, including the -addition of the virtual environment's Python executable from the beginning of -the PATH variable. - -.Parameter NonDestructive -If present, do not remove this function from the global namespace for the -session. - -#> -function global:deactivate ([switch]$NonDestructive) { - # Revert to original values - - # The prior prompt: - if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { - Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt - Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT - } - - # The prior PYTHONHOME: - if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { - Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME - Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME - } - - # The prior PATH: - if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { - Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH - Remove-Item -Path Env:_OLD_VIRTUAL_PATH - } - - # Just remove the VIRTUAL_ENV altogether: - if (Test-Path -Path Env:VIRTUAL_ENV) { - Remove-Item -Path env:VIRTUAL_ENV - } - - # Just remove VIRTUAL_ENV_PROMPT altogether. - if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) { - Remove-Item -Path env:VIRTUAL_ENV_PROMPT - } - - # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: - if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { - Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force - } - - # Leave deactivate function in the global namespace if requested: - if (-not $NonDestructive) { - Remove-Item -Path function:deactivate - } -} - -<# -.Description -Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the -given folder, and returns them in a map. - -For each line in the pyvenv.cfg file, if that line can be parsed into exactly -two strings separated by `=` (with any amount of whitespace surrounding the =) -then it is considered a `key = value` line. The left hand string is the key, -the right hand is the value. - -If the value starts with a `'` or a `"` then the first and last character is -stripped from the value before being captured. - -.Parameter ConfigDir -Path to the directory that contains the `pyvenv.cfg` file. -#> -function Get-PyVenvConfig( - [String] - $ConfigDir -) { - Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" - - # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). - $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue - - # An empty map will be returned if no config file is found. - $pyvenvConfig = @{ } - - if ($pyvenvConfigPath) { - - Write-Verbose "File exists, parse `key = value` lines" - $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath - - $pyvenvConfigContent | ForEach-Object { - $keyval = $PSItem -split "\s*=\s*", 2 - if ($keyval[0] -and $keyval[1]) { - $val = $keyval[1] - - # Remove extraneous quotations around a string value. - if ("'""".Contains($val.Substring(0, 1))) { - $val = $val.Substring(1, $val.Length - 2) - } - - $pyvenvConfig[$keyval[0]] = $val - Write-Verbose "Adding Key: '$($keyval[0])'='$val'" - } - } - } - return $pyvenvConfig -} - - -<# Begin Activate script --------------------------------------------------- #> - -# Determine the containing directory of this script -$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition -$VenvExecDir = Get-Item -Path $VenvExecPath - -Write-Verbose "Activation script is located in path: '$VenvExecPath'" -Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" -Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" - -# Set values required in priority: CmdLine, ConfigFile, Default -# First, get the location of the virtual environment, it might not be -# VenvExecDir if specified on the command line. -if ($VenvDir) { - Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" -} -else { - Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." - $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") - Write-Verbose "VenvDir=$VenvDir" -} - -# Next, read the `pyvenv.cfg` file to determine any required value such -# as `prompt`. -$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir - -# Next, set the prompt from the command line, or the config file, or -# just use the name of the virtual environment folder. -if ($Prompt) { - Write-Verbose "Prompt specified as argument, using '$Prompt'" -} -else { - Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" - if ($pyvenvCfg -and $pyvenvCfg['prompt']) { - Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" - $Prompt = $pyvenvCfg['prompt']; - } - else { - Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)" - Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" - $Prompt = Split-Path -Path $venvDir -Leaf - } -} - -Write-Verbose "Prompt = '$Prompt'" -Write-Verbose "VenvDir='$VenvDir'" - -# Deactivate any currently active virtual environment, but leave the -# deactivate function in place. -deactivate -nondestructive - -# Now set the environment variable VIRTUAL_ENV, used by many tools to determine -# that there is an activated venv. -$env:VIRTUAL_ENV = $VenvDir - -if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { - - Write-Verbose "Setting prompt to '$Prompt'" - - # Set the prompt to include the env name - # Make sure _OLD_VIRTUAL_PROMPT is global - function global:_OLD_VIRTUAL_PROMPT { "" } - Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT - New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt - - function global:prompt { - Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " - _OLD_VIRTUAL_PROMPT - } - $env:VIRTUAL_ENV_PROMPT = $Prompt -} - -# Clear PYTHONHOME -if (Test-Path -Path Env:PYTHONHOME) { - Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME - Remove-Item -Path Env:PYTHONHOME -} - -# Add the venv to the PATH -Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH -$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" diff --git a/.venv-test/bin/activate b/.venv-test/bin/activate deleted file mode 100644 index 16765578..00000000 --- a/.venv-test/bin/activate +++ /dev/null @@ -1,71 +0,0 @@ -# This file must be used with "source bin/activate" *from bash* -# You cannot run it directly - -deactivate () { - # reset old environment variables - if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then - PATH="${_OLD_VIRTUAL_PATH:-}" - export PATH - unset _OLD_VIRTUAL_PATH - fi - if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then - PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" - export PYTHONHOME - unset _OLD_VIRTUAL_PYTHONHOME - fi - - # Call hash to forget past locations. Without forgetting - # past locations the $PATH changes we made may not be respected. - # See "man bash" for more details. hash is usually a builtin of your shell - hash -r 2> /dev/null - - if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then - PS1="${_OLD_VIRTUAL_PS1:-}" - export PS1 - unset _OLD_VIRTUAL_PS1 - fi - - unset VIRTUAL_ENV - unset VIRTUAL_ENV_PROMPT - if [ ! "${1:-}" = "nondestructive" ] ; then - # Self destruct! - unset -f deactivate - fi -} - -# unset irrelevant variables -deactivate nondestructive - -# on Windows, a path can contain colons and backslashes and has to be converted: -if [ "${OSTYPE:-}" = "cygwin" ] || [ "${OSTYPE:-}" = "msys" ] ; then - # transform D:\path\to\venv to /d/path/to/venv on MSYS - # and to /cygdrive/d/path/to/venv on Cygwin - export VIRTUAL_ENV=$(cygpath /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test) -else - # use the path as-is - export VIRTUAL_ENV=/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test -fi - -_OLD_VIRTUAL_PATH="$PATH" -PATH="$VIRTUAL_ENV/"bin":$PATH" -export PATH - -# unset PYTHONHOME if set -# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) -# could use `if (set -u; : $PYTHONHOME) ;` in bash -if [ -n "${PYTHONHOME:-}" ] ; then - _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" - unset PYTHONHOME -fi - -if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then - _OLD_VIRTUAL_PS1="${PS1:-}" - PS1='(.venv-test) '"${PS1:-}" - export PS1 - VIRTUAL_ENV_PROMPT='(.venv-test) ' - export VIRTUAL_ENV_PROMPT -fi - -# Call hash to forget past commands. Without forgetting -# past commands the $PATH changes we made may not be respected -hash -r 2> /dev/null diff --git a/.venv-test/bin/activate.csh b/.venv-test/bin/activate.csh deleted file mode 100644 index 9d058967..00000000 --- a/.venv-test/bin/activate.csh +++ /dev/null @@ -1,27 +0,0 @@ -# This file must be used with "source bin/activate.csh" *from csh*. -# You cannot run it directly. - -# Created by Davide Di Blasi . -# Ported to Python 3.3 venv by Andrew Svetlov - -alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate' - -# Unset irrelevant variables. -deactivate nondestructive - -setenv VIRTUAL_ENV /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test - -set _OLD_VIRTUAL_PATH="$PATH" -setenv PATH "$VIRTUAL_ENV/"bin":$PATH" - - -set _OLD_VIRTUAL_PROMPT="$prompt" - -if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then - set prompt = '(.venv-test) '"$prompt" - setenv VIRTUAL_ENV_PROMPT '(.venv-test) ' -endif - -alias pydoc python -m pydoc - -rehash diff --git a/.venv-test/bin/activate.fish b/.venv-test/bin/activate.fish deleted file mode 100644 index 522083eb..00000000 --- a/.venv-test/bin/activate.fish +++ /dev/null @@ -1,69 +0,0 @@ -# This file must be used with "source /bin/activate.fish" *from fish* -# (https://fishshell.com/). You cannot run it directly. - -function deactivate -d "Exit virtual environment and return to normal shell environment" - # reset old environment variables - if test -n "$_OLD_VIRTUAL_PATH" - set -gx PATH $_OLD_VIRTUAL_PATH - set -e _OLD_VIRTUAL_PATH - end - if test -n "$_OLD_VIRTUAL_PYTHONHOME" - set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME - set -e _OLD_VIRTUAL_PYTHONHOME - end - - if test -n "$_OLD_FISH_PROMPT_OVERRIDE" - set -e _OLD_FISH_PROMPT_OVERRIDE - # prevents error when using nested fish instances (Issue #93858) - if functions -q _old_fish_prompt - functions -e fish_prompt - functions -c _old_fish_prompt fish_prompt - functions -e _old_fish_prompt - end - end - - set -e VIRTUAL_ENV - set -e VIRTUAL_ENV_PROMPT - if test "$argv[1]" != "nondestructive" - # Self-destruct! - functions -e deactivate - end -end - -# Unset irrelevant variables. -deactivate nondestructive - -set -gx VIRTUAL_ENV /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test - -set -gx _OLD_VIRTUAL_PATH $PATH -set -gx PATH "$VIRTUAL_ENV/"bin $PATH - -# Unset PYTHONHOME if set. -if set -q PYTHONHOME - set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME - set -e PYTHONHOME -end - -if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" - # fish uses a function instead of an env var to generate the prompt. - - # Save the current fish_prompt function as the function _old_fish_prompt. - functions -c fish_prompt _old_fish_prompt - - # With the original prompt function renamed, we can override with our own. - function fish_prompt - # Save the return status of the last command. - set -l old_status $status - - # Output the venv prompt; color taken from the blue of the Python logo. - printf "%s%s%s" (set_color 4B8BBE) '(.venv-test) ' (set_color normal) - - # Restore the return status of the previous command. - echo "exit $old_status" | . - # Output the original/"old" prompt. - _old_fish_prompt - end - - set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" - set -gx VIRTUAL_ENV_PROMPT '(.venv-test) ' -end diff --git a/.venv-test/bin/pip b/.venv-test/bin/pip deleted file mode 100755 index b73e4adc..00000000 --- a/.venv-test/bin/pip +++ /dev/null @@ -1,8 +0,0 @@ -#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 -# -*- coding: utf-8 -*- -import re -import sys -from pip._internal.cli.main import main -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) - sys.exit(main()) diff --git a/.venv-test/bin/pip3 b/.venv-test/bin/pip3 deleted file mode 100755 index b73e4adc..00000000 --- a/.venv-test/bin/pip3 +++ /dev/null @@ -1,8 +0,0 @@ -#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 -# -*- coding: utf-8 -*- -import re -import sys -from pip._internal.cli.main import main -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) - sys.exit(main()) diff --git a/.venv-test/bin/pip3.12 b/.venv-test/bin/pip3.12 deleted file mode 100755 index b73e4adc..00000000 --- a/.venv-test/bin/pip3.12 +++ /dev/null @@ -1,8 +0,0 @@ -#!/Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test/bin/python3.12 -# -*- coding: utf-8 -*- -import re -import sys -from pip._internal.cli.main import main -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) - sys.exit(main()) diff --git a/.venv-test/bin/python b/.venv-test/bin/python deleted file mode 120000 index 11b9d885..00000000 --- a/.venv-test/bin/python +++ /dev/null @@ -1 +0,0 @@ -python3.12 \ No newline at end of file diff --git a/.venv-test/bin/python3 b/.venv-test/bin/python3 deleted file mode 120000 index 11b9d885..00000000 --- a/.venv-test/bin/python3 +++ /dev/null @@ -1 +0,0 @@ -python3.12 \ No newline at end of file diff --git a/.venv-test/bin/python3.12 b/.venv-test/bin/python3.12 deleted file mode 120000 index a7a5fcca..00000000 --- a/.venv-test/bin/python3.12 +++ /dev/null @@ -1 +0,0 @@ -/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 \ No newline at end of file diff --git a/.venv-test/pyvenv.cfg b/.venv-test/pyvenv.cfg deleted file mode 100644 index 8ff2b676..00000000 --- a/.venv-test/pyvenv.cfg +++ /dev/null @@ -1,5 +0,0 @@ -home = /Library/Frameworks/Python.framework/Versions/3.12/bin -include-system-site-packages = false -version = 3.12.8 -executable = /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 -command = /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv/bin/python -m venv /Users/mathern/Desktop/git/@CAI/c2pa-python/.venv-test From 5b10400cf6dd228d4694103035c9f98c91c82bf2 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:45:09 -0700 Subject: [PATCH 5/8] fix: Update makefile comments --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 7c9a98d3..6d795e88 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,9 @@ test-local-wheel-build: 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 From 1a8d788fe353e9a1b5b202b8ea612ba60977b08c Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:50:34 -0700 Subject: [PATCH 6/8] fix: verbose debug logs --- scripts/download_artifacts.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/download_artifacts.py b/scripts/download_artifacts.py index a67fb11b..34e0fb0f 100644 --- a/scripts/download_artifacts.py +++ b/scripts/download_artifacts.py @@ -31,12 +31,16 @@ 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 main(): if len(sys.argv) < 2: From 1c754f707966758a66e75af8c291669e200c0246 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:57:52 -0700 Subject: [PATCH 7/8] fix: Only keep the scripts we need --- .gitignore | 1 + Makefile | 3 ++ scripts/download_artifacts.py | 30 ++++++++++--- src/c2pa/build.py | 80 ----------------------------------- 4 files changed, 28 insertions(+), 86 deletions(-) delete mode 100644 src/c2pa/build.py diff --git a/.gitignore b/.gitignore index 1a856fb1..d5252c32 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ __pycache__/ *$py.class /artifacts +scripts/artifacts # C extensions diff --git a/Makefile b/Makefile index 6d795e88..f5af8834 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ test: 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 diff --git a/scripts/download_artifacts.py b/scripts/download_artifacts.py index 34e0fb0f..a62b1b88 100644 --- a/scripts/download_artifacts.py +++ b/scripts/download_artifacts.py @@ -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.""" @@ -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) @@ -42,6 +44,18 @@ def download_and_extract_libs(url, 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: print("Usage: python download_artifacts.py ") @@ -50,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 @@ -67,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__": diff --git a/src/c2pa/build.py b/src/c2pa/build.py deleted file mode 100644 index 106dab9c..00000000 --- a/src/c2pa/build.py +++ /dev/null @@ -1,80 +0,0 @@ -import os -import sys -import json -import requests -from pathlib import Path -import zipfile -import io -from typing import Optional - -# Constants -REPO_OWNER = "contentauth" -REPO_NAME = "c2pa-rs" -GITHUB_API_BASE = "https://api.github.com" -ARTIFACTS_DIR = Path("artifacts") - -def get_latest_release() -> dict: - """Get the latest release information from GitHub.""" - url = f"{GITHUB_API_BASE}/repos/{REPO_OWNER}/{REPO_NAME}/releases/latest" - response = requests.get(url) - response.raise_for_status() - return response.json() - -def download_artifact(url: str, platform_name: str) -> None: - """Download and extract an artifact to the appropriate platform directory.""" - print(f"Downloading artifact for {platform_name}...") - - # Create platform directory - platform_dir = ARTIFACTS_DIR / platform_name - platform_dir.mkdir(parents=True, exist_ok=True) - - # Download the zip file - response = requests.get(url) - response.raise_for_status() - - # Extract the zip file - with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref: - # Extract all files to the platform directory - zip_ref.extractall(platform_dir) - - print(f"Successfully downloaded and extracted artifacts for {platform_name}") - -def download_artifacts() -> None: - """Main function to download artifacts. Can be called as a script or from hatch.""" - try: - # Create artifacts directory if it doesn't exist - ARTIFACTS_DIR.mkdir(exist_ok=True) - - # Get latest release - print("Fetching latest release information...") - release = get_latest_release() - print(f"Found release: {release['tag_name']}") - - # Download each asset - for asset in release['assets']: - # Skip non-zip files - if not asset['name'].endswith('.zip'): - continue - - # Determine platform from asset name - # Example: c2pa-rs-v1.0.0-macosx-arm64.zip - platform_name = asset['name'].split('-')[-1].replace('.zip', '') - - # Download and extract the artifact - download_artifact(asset['browser_download_url'], platform_name) - - print("\nAll artifacts have been downloaded successfully!") - - except requests.exceptions.RequestException as e: - print(f"Error downloading artifacts: {e}", file=sys.stderr) - sys.exit(1) - except Exception as e: - print(f"Unexpected error: {e}", file=sys.stderr) - sys.exit(1) - -def initialize_build() -> None: - """Initialize the build process by downloading artifacts.""" - download_artifacts() - -if __name__ == "__main__": - download_artifacts() \ No newline at end of file From bbe20d30168b8c3f3f5b33d6b10d795d542fe1ed Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Wed, 14 May 2025 14:59:22 -0700 Subject: [PATCH 8/8] fix: Improve makefile --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index f5af8834..8d6399e4 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ # 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