a pipx script installer supporting inline metadata for python scripts
Project description
pipx_isolate
a pipx script installer supporting inline script metadata for python scripts
The purpose for this is to be able to isolate the dependencies for small scripts into a virtual environment.
Inline Script Metadata looks like this:
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "beautifulsoup4",
# "click>=8.3.1",
# ]
# ///
import os
import sys
import contextlib
from typing import Sequence, NamedTuple
import click
from bs4 import BeautifulSoup, Doctype
You could either manually add that to your script, or use uv like: uv add --script <PATH> click beautifulsoup4. pipx_isolate add-metadata <PATH> shows you all the import statements and wraps uv add --script.
Once you have a script that has metadata, you can use pipx run --path /path/to/script, which parses the metadata at the top, installs anything that is needed into a venv into ~/.cache/pipx, and then runs the script in that environment.
Running pipx_isolate install <name> looks up the name of the script in your $PATH, and creates a wrapper script that looks like this:
#!/bin/sh
exec /home/username/.local/bin/pipx run --path /full/path/to/name "$@"
This way, if you ever update the metadata at the top, pipx picks up the new changes, and runs it with the correct dependencies in a virtual environment.
If you want to pass arguments to pipx run in the generated script, you can do so like: pipx_isolate install <file> --run --no-cache
pipx_isolate install by default creates a bin directory at ~/.local/share/pipx_isolate/bin/ so in order to call the wrapper scripts instead of the original, you should update your $PATH to put that directory near the front of your $PATH:
export PATH="$HOME/.local/share/pipx_isolate/bin:$PATH"
To find/install all the scripts with inline script metadata, I run a command like this:
rg --files-with-matches -e '/// script' | xargs -I{} sh -c "test -x {} && uv export --script {} --quiet >/dev/null && echo {}" | parallel pipx_isolate install
Installation
Requires python3.10+
To install with pip, run:
pip install pipx_isolate
Usage
pipx_isolate --help
Tests
git clone 'https://github.com/purarue/pipx_isolate'
cd ./pipx_isolate
pip install '.[testing]'
flake8 ./pipx_isolate
mypy ./pipx_isolate
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 pipx_isolate-0.1.1.tar.gz.
File metadata
- Download URL: pipx_isolate-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c4bf97e4f000e86d25fed1eac7e56292bd4029da6791f3e1819d412dfa6e1fc
|
|
| MD5 |
3457eab5ed18b4a4bbe9e891dbe26e76
|
|
| BLAKE2b-256 |
8ccdbaa5ba7d10082ad7a98a39db2523752c74f339dd0e91a5e4020c88b87d7a
|
File details
Details for the file pipx_isolate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pipx_isolate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2449b127a60db779fc04e4f63a6d9c1812709c887b71689bbcdd0e15b4b47c12
|
|
| MD5 |
e582afee959c9e3099699fa9fc86e12c
|
|
| BLAKE2b-256 |
ecb4765a349edd1e2dce99af34fa243a486aa9d3eda1c86d8d81f26f02fb6f22
|