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

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: hatch_pex-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b974c1026ee10ef4983aa46526fe80aad4fadf16c25b67710689e7e4aaa2053d
MD5 8b943c70883b376df7be783fcbbed0c0
BLAKE2b-256 0821072e72a82ad367c54aac821e921838e8dcf322a08a7fb18471d80b18f1aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_pex-0.1.2.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.2-py2.py3-none-any.whl.

File metadata

  • Download URL: hatch_pex-0.1.2-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.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4ede49822885469a7290ca15c106ae8a392cde1b0517736d79bb3372e11287b2
MD5 d033ea4ac510b69ff8288b1421342f7e
BLAKE2b-256 e44606713ab1456d8bf9fc6077a79ad58fa69ddc7841dc8cf890717be2a7cb70

See more details on using hashes here.

Provenance

The following attestation bundles were made for hatch_pex-0.1.2-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