Skip to main content

Hatch plugin for building PEX binaries.

Project description

hatch-pex 🍳

This plugin adds a PEX executable build target for Hatch.

Quickstart

To make the 'pex' target available in Hatch, you just need to add hatch-pex as a dependency of the pex build target.

[tool.hatch.build.targets.pex]
dependencies = ["hatch-pex"]

From there, you can build with Hatch!

$ hatch build -t pex
$ ls dist/pex
myapp.pex

To add a scie build, just set the scie type

[tool.hatch.build.targets.pex]
dependencies = ["hatch-pex"]
scie = "eager"
$ hatch build -t pex
$ ls dist/pex
myapp.pex   myapp

Comparison to PyApp

Hatch's built-in 'binary' build target will generate a self-extracting binary including a Python interpreter and your code using PyApp. This is functionally identical to PEX's scie binaries, except that a scie PEX does not need to be compiled for every Python project.

Instead, the scie binary is just a "dumb" pre-built binary that the PEX zipapp gets appended to (with some metadata to tell the binary how to run it). This works because executables can have arbitrary data appended to them, and a zip can have arbitrary data before it's header, and both are still valid.

Configuration

Since all this plugin really does under the hood is call pex with your project and entry-points as arguments, it is about as configurable as the pex command itself. pex --help has a good explanation of all the options here, and docs.pex-tool.org is also very informative.

When you run hatch build -t pex, the builder will effectively run the following command for each entry in your project.scripts table:

$ pex \
    --project "${PROJECT}" \
    --output-file "${SCRIPT_NAME}.pex" \
    --script "${SCRIPT_NAME}"
    # ... other config args here ...

Pretty much all of the below configuration is just passed straight to the pex command as arguments.

If you have an empty project.scripts, or you set tool.hatch.build.targets.pex.scripts to an empty list, then hatch-pex will build an interactive PEX.

Options

[tool.hatch.build.targets.pex]
scripts = [] # Limit the scripts that get made into PEXes
pex-args = ["--venv", "prepend"] # Set default arguments to pass to `pex`
scie = false # Set to "eager" or "lazy" to build a scie PEX.
suffix = ".pex" # The suffix of the output file.

# NOTE: If the suffix is '.pex', and scie is true
# then both a 'scie' and a '.pex' file will be created.

# You can override your defaults for each PEX,
# add extra arguments, or add additional PEXes by defining tables...
[tool.hatch.build.targets.pex.script.'somescript']
pex-args = []
extra-pex-args = [] 
scie = false
suffix = ""
command = ["-exe", "{script}.py"]
# "{script}" gets replaced with the above name

# If there are no scripts, an interactive PEX is built with the
# project name as the executable name.
# You can also manually configure one.
[tool.hatch.build.targets.pex.interactive]
name = "somename" # the project.name by default
pex-args = []
extra-pex-args = []
suffix = ".pex"
scie = false

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

hatch_pex-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

hatch_pex-0.1.1-py2.py3-none-any.whl (7.0 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: hatch_pex-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hatch_pex-0.1.1.tar.gz
Algorithm Hash digest
SHA256 77bd75da20dedeaeb88af60eddfce2e1636c783d8dd4acfa5fe831ec0272d28e
MD5 9bcf645c7e3d00b6e1b7ac53828f526c
BLAKE2b-256 02ded5b7bbf889395c52bd31cfba546e254cf1a9a36d94cb44082662b899ba5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_pex-0.1.1.tar.gz:

Publisher: build.yml on oh-ok/hatch-pex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: hatch_pex-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hatch_pex-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21ca433f73e7a03f62a4c240f3e92387c6a11dfb0fdaafd91899c82a65fd988d
MD5 f70e608d94e4d4ebd4b6a26428b37407
BLAKE2b-256 6072801d060d2984c321886bc634fdd3f206c8186fd29787725eb24e58c660ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_pex-0.1.1-py2.py3-none-any.whl:

Publisher: build.yml on oh-ok/hatch-pex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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