Skip to main content

Jump the Gun

Make Python CLI tools win the speed race, by cheating!

Actions Status PyPI Downloads License: MIT

# In any Python (>= 3.8) environment:
pip install jumpthegun

# For any CLI tool written in Python (>= 3.8):
jumpthegun run <cli-tool> [...]

# Example:
jumpthegun run black --check .

# More details:
jumpthegun --help

Why?

CLI tools should be fast. Ideally, running them should be near-instant.

This is especially significant, for example, when running code linting and formatting tools on just a few files while developing.

How?

✨ Magic! ✨

JumpTheGun makes Python CLI tools start very fast, by entirely avoiding the time taken for Python interpreter startup and module imports.

It works by:

  1. Running a daemon process in the background for each CLI tool. This initializes Python and imports the CLI tool's code in advance.
  2. The daemon listens on a local TCP socket and uses fork to quickly create sub-processes with everything already initialized.
  3. The jumpthegun command is implemented as a Bash script which connects to the daemon, passes the command-line arguments, and then passes input and output back and forth.

Some juicy details:

  • Communication is done using a custom protocol, suitable for a simple implementation in Bash.
  • jumpthegun run works even if a daemon is not already running; it will run a new background daemon in this case.
  • JumpTheGun daemons have a timeout, so after a period of inactivity the daemon will exit. The default timeout is 4 hours. This is configurable via the config file; see Configuration.
  • JumpTheGun needs to import a CLI tool's code and find which function to call to run it. It gets that info inspecting the tool's entrypoint, as per the PyPA Specification, via importlib.metadata.entry_points().
  • To be able to run CLI tools installed in a different Python environment, JumpTheGun finds the Python interpreter used by the CLI tool, and if JumpTheGun isn't available in it, it runs that Python with PYTHONPATH set to include an additional directory with a copy of JumpTheGun's code.

Configuration

The config file is named jumpthegun.json. It is searched for in the following locations, in order:

  1. $XDG_CONFIG_HOME
  2. ~/.config/

The top-level object should be a mapping. The following keys are supported:

  • idle_timeout_seconds: Period with no activity after which the daemon exits. Default: 4 hours.

Caveats

  • JumpTheGun is in early stages of development. It works for me; beyond that I can make no promises. Every detail is likely to change in the future.
  • Windows is not supported.
  • Uses fork, with all of its caveats. For example, tools that run background threads during module import will break. JumpTheGun does not check for such issues.
  • Uses local TCP sockets, so firewalls, VPNs etc. may cause issues.
  • Does not support running standalone Python scripts which aren't installed as part of a package.
  • Tested with Python 3.7 to 3.11, with x86-64 Ubuntu 20.04 and recent macOS on an ARM Mac.
  • Requires having Bash installed.

Using with pre-commit

pre-commit is awesome, but running linters in pre-commit hooks makes commits slower, even when running only on staged files. JumpTheGun fixes that!

Example config (.pre-commit-config.yaml):

repos:
- repo: https://github.com/PyCQA/flake8
  rev: 6.0.0
  hooks:
  - id: flake8
    entry: jumpthegun run flake8
    additional_dependencies:
    - jumpthegun

You may need to run pre-commit install --install-hooks if you've changed the config in an existing working copy of a project.

Then, edit your .git/hooks/pre-commit and make this change:

if [ -x "$INSTALL_PYTHON" ]; then
    #exec "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"
    exec jumpthegun run pre-commit "${ARGS[@]}"

Copyright & License

Copyright 2022-2023 Tal Einat.

Licensed under the MIT License.

Version 3.90 of the filelock library is included in this codebase as-is. It is made available under the terms of the Unlicense software license. See it's LICENSE file for details.

Metadata

Release files for jumpthegun 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jumpthegun 0.2.0
File Size Uploaded Provenance Actions
jumpthegun-0.2.0.tar.gz 59.5 kB Without provenance Details for jumpthegun-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jumpthegun 0.2.0
File Interpreter ABI Platform Actions
jumpthegun-0.2.0-py3-none-any.whl Python 3 none any Details for jumpthegun-0.2.0-py3-none-any.whl

Total release size: 86.1 kB

Release files / jumpthegun-0.2.0.tar.gz

Download URL jumpthegun-0.2.0.tar.gz
Size 59.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7928585e21ca2616bef406f7909e68653f9770889b61ec6e4538f9d02ce4b992
BLAKE2b-256 checksum
How to use checksums
a7c4b488ad3ced202ded4a261347a3422cb80d48ef04ba4b3c033864bcbc9e68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / jumpthegun-0.2.0-py3-none-any.whl

Download URL jumpthegun-0.2.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f08dffbec309df01e960f72419761463d1046d8b0b9d741a37529cfe40af37ac
BLAKE2b-256 checksum
How to use checksums
c66bf3b2f153a7813e0dc8b59b93f29d3409048bfc7a37b3ef3ba11d0fc43c5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for jumpthegun 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page