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"] # 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.
# Pass '--scie-only' or '--pex-only' to specify if
# you want one or the other
# 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 = ".pex"
command = ["--script", "{script}"]
# "{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 = []
scie = false
suffix = ".pex"
# 'command' is not valid here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatch_pex-0.1.3.tar.gz.
File metadata
- Download URL: hatch_pex-0.1.3.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31bf3f185269425707920aead9998d3f5424fc266b643f04be2830679f26902b
|
|
| MD5 |
8386f17dcafed2b5f21aaa5f0f148c4d
|
|
| BLAKE2b-256 |
7b1745ead284baa13e161d971430e6ff7583f9414372a863588d5b573a54ec27
|
Provenance
The following attestation bundles were made for hatch_pex-0.1.3.tar.gz:
Publisher:
build.yml on oh-ok/hatch-pex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_pex-0.1.3.tar.gz -
Subject digest:
31bf3f185269425707920aead9998d3f5424fc266b643f04be2830679f26902b - Sigstore transparency entry: 198276506
- Sigstore integration time:
-
Permalink:
oh-ok/hatch-pex@1b81d768d49898be453057e95e8204675b56a7c4 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/oh-ok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@1b81d768d49898be453057e95e8204675b56a7c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hatch_pex-0.1.3-py2.py3-none-any.whl.
File metadata
- Download URL: hatch_pex-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e368bc106d5869c21107220cbe845bebff7e1a795ca5536f32ad014d776cb612
|
|
| MD5 |
24a3fd424e103c1d6094d08c3d81563c
|
|
| BLAKE2b-256 |
6ed7eae244c8467cb40d7c545f31948847aab469242e0175451cf4b3e2acd3e1
|
Provenance
The following attestation bundles were made for hatch_pex-0.1.3-py2.py3-none-any.whl:
Publisher:
build.yml on oh-ok/hatch-pex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_pex-0.1.3-py2.py3-none-any.whl -
Subject digest:
e368bc106d5869c21107220cbe845bebff7e1a795ca5536f32ad014d776cb612 - Sigstore transparency entry: 198276509
- Sigstore integration time:
-
Permalink:
oh-ok/hatch-pex@1b81d768d49898be453057e95e8204675b56a7c4 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/oh-ok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@1b81d768d49898be453057e95e8204675b56a7c4 -
Trigger Event:
push
-
Statement type: