Skip to main content

applecrate: A Python package for creating macOS installer packages.

Project description

AppleCrate

Package your command line tools into a native macOS installer.

AppleCrate is a tool for creating native macOS installers for your command line tools. It's useful for creating installers for command line tools written in any language. Tools written in interpreted languages like Python will need to be first processed with a tool like pyinstaller to create a standalone executable.

Installation

pip install applecrate

Simple Example

applecrate build \
--app mytool \
--version 1.0.0 \
--license LICENSE \
--install dist/mytool "/usr/local/bin/{{ app }}-{{ version }}" \
--link /usr/local/bin/mytool "/usr/local/bin/{{ app }}-{{ version }}"

This will create a native macOS installer for the tool dist/mytool which will install it to /usr/local/bin/mytool-1.0.0. The installer will create a symlink to the tool at /usr/local/bin/mytool and will also create an uninstaller to remove the tool.

You can also use applecrate from your own Python code to create installers programmatically:

"""Create a macOS installer package programmatically."""

import pathlib

from applecrate import build_installer

if __name__ == "__main__":
    build_installer(
        app="TestApp",
        version="1.0.0",
        license="LICENSE",
        install=[(pathlib.Path("dist/testapp"), pathlib.Path("/usr/local/bin/testapp"))],
        output="build/{{ app }}-{{ version }}.pkg",
        verbose=print,
    )

How It Works

AppleCrate is a Python application that uses the pkgbuild and productbuild command line tools to create a macOS installer package. AppleCrate does not do anything that you couldn't do yourself with these tools, but it automates the process and provide a simple command line interface. Creating a macOS installer package is a multi-step process that requires the generation of multiple files such as HTML files for the welcome screen, pre and post install scripts, Distribution XML file, etc. AppleCrate takes care of all of this for you but also allows you to customize the installer by providing your own files for these steps.

AppleCrate uses Jinja2 templates to generate the files required for the installer. This allows you to use template variables in your files or command line parameters to customize the installer. For example, you can use {{ app }} and {{ version }} in your files to refer to the app name and version you provide on the command line.

Usage

Usage: applecrate build [OPTIONS]

  applecrate: A Python package for creating macOS installer packages.

Options:
  -a, --app TEXT                  App name
  -v, --version TEXT              App version
  -l, --license FILE              Path to license file. If provided, the
                                  installer will include a click-through license
                                  agreement.
  -w, --welcome FILE              Path to welcome markdown or HTML file
  -c, --conclusion FILE           Path to conclusion markdown or HTML file
  -u, --uninstall FILE            Path to uninstall script; if not provided, an
                                  uninstall script will be created for you. See
                                  also '--no-uninstall'
  -U, --no-uninstall              Do not include an uninstall script in the
                                  package
  -L, --url NAME URL              Links to additional resources to include in
                                  conclusion HTML shown after installation. For
                                  example, the project website or documentation.
  -b, --banner FILE               Path to optional PNG banner image for
                                  installer package.
  -i, --install FILE_OR_DIR DEST  Install FILE_OR_DIR to destination DEST; DEST
                                  must be an absolute path, for example
                                  '/usr/local/bin/app'. DEST may include
                                  template variables {{ app }} and {{ version
                                  }}. For example: `--install dist/app
                                  "/usr/local/bin/{{ app }}-{{ version }}"` will
                                  install the file 'dist/app' to
                                  '/usr/local/bin/app-1.0.0' if --app=app and
                                  --version=1.0.0.
  -k, --link SRC TARGET           Create a symbolic link from SRC to DEST after
                                  installation. SRC and TARGET must be absolute
                                  paths and both may include template variables
                                  {{ app }} and {{ version }}. For example:
                                  `--link "/Library/Application Support/{{ app
                                  }}/{{ version }}/app" "/usr/local/bin/{{ app
                                  }}-{{ version }}"`
  -p, --pre-install FILE          Path to pre-install shell script; if not
                                  provided, a pre-install script will be created
                                  for you.
  -P, --post-install FILE         Path to post-install shell script; if not
                                  provided, a post-install script will be
                                  created for you.
  -s, --sign APPLE_DEVELOPER_CERTIFICATE_ID
                                  Sign the installer package with a developer
                                  ID. If APPLE_DEVELOPER_CERTIFICATE_ID starts
                                  with '$', it will be treated as an environment
                                  variable and the value of the environment
                                  variable will be used as the developer ID.
  -d, --build-dir DIRECTORY       Build directory to use for building the
                                  installer package. Default is
                                  build/applecrate/darwin if not provided.
  -o, --output FILE               Path to save the installer package.
  --help                          Show this message and exit.

Configuration

The command line tool applecrate can be configured via pyproject.toml or applecrate.toml in the current working directory or via command line options. The command line arguments will always take precedence over the configuration files. If present, applecrate.toml will take precedence over pyproject.toml. The configuration file should be in the following format:

pyproject.toml:

[tool.applecrate]
app = "mytool"
version = "1.0.0"
license = "LICENSE"
install = [
    ["dist/mytool", "/usr/local/bin/{{ app }}-{{ version }}"],
]

applecrate.toml:

app = "mytool"
version = "1.0.0"
license = "LICENSE"
install = [
    ["dist/mytool", "/usr/local/bin/{{ app }}-{{ version }}"],
]

Any command line option is a valid key in the configuration file. For example, the --app option can be set in the configuration file as app = "mytool". Command line options with a dash (-) should be converted to underscores (_) in the configuration file. For example, the --pre-install option should be set in the configuration file as pre_install = "scripts/preinstall.sh".

To Do

  • Add support for signing the installer with a developer certificate
  • Add support for notarizing the installer
  • Add python API to create installers programmatically
  • Add applecrate check command to check the configuration without building the installer
  • Documentation (set up mkdocs)
  • Tests

Credits

Heavily inspired by macOS Installer Builder by Kosala Herath. AppleCrate is a complete rewrite in Python but borrows many ideas from macOS Installer Builder and is thus licensed under the same Apache License, Version 2.0.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License here.

Contributing

Contributions of all kinds are welcome! Please see CONTRIBUTING.md for more information.

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

applecrate-0.1.1.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

applecrate-0.1.1-py2.py3-none-any.whl (21.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file applecrate-0.1.1.tar.gz.

File metadata

  • Download URL: applecrate-0.1.1.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for applecrate-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a40d187f561ac2cb210dcc64fc3836abdc8825173a4d2350b8d9b04c27b3afdf
MD5 dcbc15be68e73ea3b8d380c913fd8bdb
BLAKE2b-256 f4e4b8ccc4ffab8cadb9f00ceff5d972bb365485dc102f54cc526af4321d0040

See more details on using hashes here.

File details

Details for the file applecrate-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: applecrate-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for applecrate-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 61a4ebc77c80da84b086dd4d216bdb7ebc6cc32e97de8bef4caa17570c8b1a21
MD5 b3d95ff1dc8874ff7120d1ee67c2cc09
BLAKE2b-256 cea5b44858e7e1b6af3b090350c70f47ddcb27e6cb2e5a6194345b3b6087cdfb

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