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.2.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.2-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sema4ai_build_common-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f800a78a744fdd9dda7e97b73a0ed52f2a4d2ff7dc545b22bd868c17a8ec91c4
MD5 26142499b4de8cea40a4d3165f84e494
BLAKE2b-256 7fbf266eb386f7bd444a240a055c8aa9a07431cf4d3018f325da7c09529ea7ed

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sema4ai_build_common-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79afcf64a8d77f3c1d485f9d6ce997be298275b4b5cf1ca0f076253912edf3ce
MD5 b994d24d1049f226fba38c282604b5f4
BLAKE2b-256 08d6470eca85f08a5b8feff37f0d884f457da02c990255d7af44af9aadd6f962

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