How tanixlu/pyfuze works
Purpose and Entry Points
pyfuze is a Python packaging CLI that turns a Python script or project directory into a single executable. Its public command entry is implemented in src/pyfuze/__main__.py and src/pyfuze/cli.py; package exports/version metadata are in src/pyfuze/__init__.py. The generated executable is driven at runtime by a compiled C launcher.
CLI Orchestration
src/pyfuze/cli.py is the primary control plane: it accepts the project input plus mode, entry point, dependency, inclusion/exclusion, extraction, environment, and Windows GUI options. It resolves either a single script or a folder project, selects one of Bundle, Online, or Portable packaging paths, and coordinates artifact creation. Shared Python-side filesystem/process logic belongs in src/pyfuze/utils.py.
Project Assembly Boundary
The packager constructs an application payload from the supplied project, its entry file, inferred Python/package sources, and explicit extra files. Dependency definitions can enter through requirements, pyproject.toml, and uv.lock; they are packaging-time inputs rather than application runtime code. Example project shape and intended folder-entry behavior are represented by examples/complex/app.py, examples/complex/pyproject.toml, and examples/complex/uv.lock.
Packaging Modes
Bundle is the default same-platform path: it embeds Python and resolved dependencies and extracts them before execution. Online builds a smaller cross-platform payload that bootstraps Python/dependencies at runtime through uv. Portable creates an extraction-free Cosmopolitan APE-style executable, restricted to pure-Python projects/dependencies and a fixed Cosmopolitan Python release. Mode dispatch and artifact generation are centered in src/pyfuze/cli.py.
Native Runtime Launcher
The embedded launcher is C code in csrc/main.c, with runtime configuration encoding/decoding in csrc/config.c and csrc/config.h. It is the execution boundary between the produced native executable and packaged Python payload: it determines runtime setup, extraction/working behavior, then starts the selected Python entry point. Native utility support is in csrc/utils.c and csrc/utils.h; compile_csrc.sh builds this launcher for inclusion in packaging output.
Runtime Filesystem and Environment Flow
For Bundle and Online artifacts, launch-time content is unpacked under the configured unzip path, with the default working directory <unzip-path>/src. The launcher exposes executable location and invocation directory through PYFUZE_EXECUTABLE_PATH and PYFUZE_INVOKE_DIR, allowing packaged applications to deliberately choose persistent or caller-relative paths. Windows GUI behavior is also passed from CLI packaging options into launcher/runtime behavior.
External Dependencies and Distribution
Cosmopolitan underpins Portable mode and executable portability; uv handles dependency resolution/installation and constrains Online mode’s platform coverage. Online runtime can retrieve uv, Python, and packages from public or user-specified installer/index mirrors. The Python package is built/published from pyproject.toml, while PyPI publication automation is defined in .github/workflows/publish2pypi.yml.
Main entry points: cli.py Packaging orchestrator · main.c C launcher · pyproject.toml Dependency definitions · __main__.py CLI entry
Components 22
Python packager
- CLI entry
src/pyfuze/__main__.py - Packaging orchestrator · Selects mode, resolves project input, and produces artifacts.
src/pyfuze/cli.py - Package metadata
src/pyfuze/__init__.py - Shared utilities · Filesystem and process operations used during packaging.
src/pyfuze/utils.py
Payload assembly
- Project or script input · A single script or directory project with a selected entry file.
- Dependency definitions · Requirements, pyproject metadata, and uv lock data.
examples/complex/pyproject.toml - Example uv lock · Represents locked dependency input for folder projects.
examples/complex/uv.lock - Example app entry
examples/complex/app.py - Application payload · Entry source, inferred packages, dependencies, and explicit included files.
- Bundle mode · Embeds Python and dependencies for same-platform extraction.
src/pyfuze/cli.py - Online mode · Produces a small payload that bootstraps its runtime through uv.
src/pyfuze/cli.py - Portable mode · Builds an extraction-free pure-Python Cosmopolitan executable.
src/pyfuze/cli.py
Generated runtime
- Generated executable
- C launcher · Configures execution and starts the packaged Python entry point.
csrc/main.c - Launcher configuration · Encodes packaging options for launcher behavior.
csrc/config.c - Native utilities
csrc/utils.c - Launcher build · Compiles the native launcher included in packaging output.
compile_csrc.sh - Extracted runtime workspace · Bundle and Online unpack under the unzip path; default workdir is src.
External tooling
- uv · Resolves build dependencies and installs Online runtime components.
- Cosmopolitan · Provides the fixed APE-style Python runtime for Portable mode.
- PyPI publication
.github/workflows/publish2pypi.yml - Build metadata · Defines Python package build and publication inputs.
pyproject.toml
Connections 26
- CLI entry → Packaging orchestrator: invokes
- Packaging orchestrator → Shared utilities: uses
- Project or script input → Application payload: sources and entry
- Example app entry → Project or script input: illustrates
- Dependency definitions → Application payload: defines dependencies
- Example uv lock → Dependency definitions: illustrates lock input
- Packaging orchestrator → Application payload: assembles
- Packaging orchestrator → Bundle mode: dispatches
- Packaging orchestrator → Online mode: dispatches
- Packaging orchestrator → Portable mode: dispatches
- Application payload → Bundle mode: embedded content
- Application payload → Online mode: bootstrap payload
- Application payload → Portable mode: pure-Python content
- Bundle mode → Generated executable: produces
- Online mode → Generated executable: produces
- Portable mode → Generated executable: produces
- Launcher build → C launcher: compiles
- Launcher configuration → C launcher: runtime options
- Native utilities → C launcher: supports
- C launcher → Generated executable: embedded in
- Generated executable → Extracted runtime workspace: Bundle/Online unpack
- C launcher → Extracted runtime workspace: sets workspace and env · Exposes executable and invocation paths to the application.
- uv → Dependency definitions: resolves
- uv → Online mode: runtime bootstrap
- Cosmopolitan → Portable mode: fixed runtime
- Build metadata → PyPI publication: package release