Skip to main content

Sema4AI Build Common

Project description

⚡️ sema4ai-build-common

A Python library containing common utilities for building Sema4AI projects.

-- it deals with things such as building and signing executables.

Notes on how it works:

  • The sema4ai.build_common.workflows module contains the entry points that should be called by other projects.

  • build_and_sign_executable should be called to actually build the executable and sign it.

  • This function handles building and signing an executable, with these main steps:

    • Build: Uses PyInstaller to create an executable from Python code. It always builds in "not onefile" mode, meaning it creates a directory containing the executable and its dependencies.

    • Signing (Optional): If the sign parameter is True:

      • On macOS: Signs using macOS code signing and properly notarizes afterwards
      • On Windows: Signs using Windows code signing
    • Go Wrapper (Optional): If go_wrapper is True:

      • Zips the PyInstaller-built application assets
      • Builds a Go wrapper around the application
      • Creates a final executable that combines both
      • Signs the final executable if signing is enabled
  • Requirements for build:

    • A <project-name>.spec file must be available in the root of the project with the pyinstaller spec to build the executable (the build process will use it to build with pyinstaller)

    • The go-wrapper for the app must also be in the root of the project (at this point, each app needs its own, although in the future a common base should probably be used). The build utilities will put a version.txt and an assets.zip in /go-wrapper/assets (if the /go-wrapper directory does not exist the build will fail).

Example of integration in sai-server -- note that sai-server uses typer to create a command line instead of invoke:

import typer

app = typer.Typer()

@app.command()
def build_executable(
    debug: bool = typer.Option(False, help="Build in debug mode"),
    ci: bool = typer.Option(
        True, help="Build in CI mode, disabling interactive prompts"
    ),
    dist_path: Path = typer.Option("dist", help="Path to the dist directory"),
    sign: bool = typer.Option(False, help="Sign the executable"),
    go_wrapper: bool = typer.Option(False, help="Build the Go wrapper too"),
    version: str | None = typer.Option(
        None, help="Version of the executable (gotten from github tag/pr if not passed)"
    ),
) -> None:
    """Build the project executable via PyInstaller."""
    from sema4ai.build_common.root_dir import get_root_dir
    from sema4ai.build_common.workflows import build_and_sign_executable

    from sema4ai.action_server import __version__

    if version is None:
        version = __version__  # Get version from the project...

    root_dir = get_root_dir()
    build_and_sign_executable(
        root_dir=root_dir,
        name="action-server",
        debug=debug,
        ci=ci,
        dist_path=root_dir / dist_path,
        sign=sign,
        go_wrapper=go_wrapper,
        version=__version__,
    )

The job that integrates it needs several environment variables for the signing and version gathering -- Note that the version is gotten from the tag or pr or branch name (based on the GITUB_EVENT_NAME, GITHUB_REF_NAME and GITHUB_PR_NUMBER), but applications that handle the version differently could pass the version in the command-line or call to build_and_sign_executable.

- name: Build SAI Server binary
  run: uv run python -m sai_tasks build-executable --sign --go-wrapper
  env:
    MACOS_SIGNING_CERT: ${{ secrets.MACOS_SIGNING_CERT_SEMA4AI }}
    MACOS_SIGNING_CERT_PASSWORD: ${{ secrets.MACOS_SIGNING_CERT_PASSWORD_SEMA4AI }}
    MACOS_SIGNING_CERT_NAME: ${{ secrets.MACOS_SIGNING_CERT_NAME_SEMA4AI }}

    APPLEID: ${{ secrets.MACOS_APP_ID_FOR_NOTARIZATION_SEMA4AI }}
    APPLETEAMID: ${{ secrets.MACOS_TEAM_ID_FOR_NOTARIZATION_SEMA4AI }}
    APPLEIDPASS: ${{ secrets.MACOS_APP_ID_PASSWORD_FOR_NOTARIZATION_SEMA4AI }}

    VAULT_URL: ${{ secrets.WIN_SIGN_AZURE_KEY_VAULT_URL_SEMA4AI }}
    CLIENT_ID: ${{ secrets.WIN_SIGN_AZURE_KEY_VAULT_CLIENT_ID_SEMA4AI }}
    TENANT_ID: ${{ secrets.WIN_SIGN_AZURE_KEY_VAULT_TENANT_ID_SEMA4AI }}
    CLIENT_SECRET: ${{ secrets.WIN_SIGN_AZURE_KEY_VAULT_CLIENT_SECRET_SEMA4AI }}
    CERTIFICATE_NAME: ${{ secrets.WIN_SIGN_AZURE_KEY_VAULT_CERTIFICATE_NAME_SEMA4AI }}

    GITHUB_EVENT_NAME: ${{ github.event_name }}
    GITHUB_REF_NAME: ${{ github.ref_name }}
    GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sema4ai_build_common-0.0.3.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sema4ai_build_common-0.0.3-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file sema4ai_build_common-0.0.3.tar.gz.

File metadata

  • Download URL: sema4ai_build_common-0.0.3.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1014-azure

File hashes

Hashes for sema4ai_build_common-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7515feeee078d1ba99d2be0dda0a24171a816eed1989d6f0caf384c63d69a9a7
MD5 b08dc921f091bff32d1e572465660bce
BLAKE2b-256 a8c9f8cad5455f30a2502d46c14f34ad74cbbc9c240e00ed2d29eafd5eaed8be

See more details on using hashes here.

File details

Details for the file sema4ai_build_common-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: sema4ai_build_common-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1014-azure

File hashes

Hashes for sema4ai_build_common-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0d3713684e6f3608ef8d1b243e8d1f28df46cfbe6e75d052420d81dc784dbca
MD5 9987cc622c67aeedf457137b4fa71a8c
BLAKE2b-256 f1fec7ad51c8e4ecfa3fbced576186c9a5bbc799eed13bbf25e3d76feb68285c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page