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.1.tar.gz (10.3 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.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sema4ai_build_common-0.0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-1021-azure

File hashes

Hashes for sema4ai_build_common-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b075b76fc65125ba35b48309053825633909a2fde28d8ddc389b8d2b92a855f6
MD5 42b77e1901af898e3d416bb91a4caf17
BLAKE2b-256 4080f501b67da999570fc5311898f930320075378aa5a78026669db8aad436a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sema4ai_build_common-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-1021-azure

File hashes

Hashes for sema4ai_build_common-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd7140f4afc9d1558b973a97b21e0a8735e531a7307af22ab66d66bfc8fa339a
MD5 2cd035f3239a5fb156e877a2698382e6
BLAKE2b-256 b07210302071e1910b8847b74aefca22cb6ef174c6684e9c45e2a329702c2ee8

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