isolated environment2, re-written using uv
Project description
iso-env - Run apps in an isolated environment using uv
About
Got an AI app? Are you in dependency hell because of pytorch? Well, so was I...
Once upon a time I wanted to release an AI tool called transcribe-anything to tie a bunch of AI tools together to do translations across Windows/Mac/Linux without any complicated setup. To do this, I made isolated-environment, a package built ontop of venv. It was extremely messy but got the job done, and transcribe-anything surged in popularity. Fast forward a year later and uv comes out. uv-iso-env is a remake of isolated-environment but built on top of uv, the way god intended it.
Simple Example
import unittest
from pathlib import Path
from iso_env import IsoEnv, IsoEnvArgs, Requirements
REQUIREMENTS_TXT = """
static-ffmpeg
"""
class MainTester(unittest.TestCase):
"""Main tester class."""
def test_iso_env(self) -> None:
"""Test command line interface (CLI)."""
args = IsoEnvArgs(
venv_path=Path(".env_ffmpeg"),
build_info=Requirements(REQUIREMENTS_TXT, python_version="==3.10.*"),
)
iso = IsoEnv(args)
cp = iso.run(["static_ffmpeg", "-version"])
print(cp)
cp = iso.run(["pwd"])
print(cp)
print()
if __name__ == "__main__":
unittest.main()
Complex Example
"""
Unit test file.
"""
import unittest
from pathlib import Path
from iso_env.api import IsoEnv, IsoEnvArgs, PyProjectToml
PY_PROJECT_TOML = PyProjectToml(
"""
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.10.0"
dependencies = [
"torch==2.1.2",
]
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[tool.uv.sources]
torch = [
{ index = "pytorch-cu121", marker = "platform_system == 'Windows'" },
]
[[tool.uv.index]]
name = "pytorch-cu121"
url = "https://download.pytorch.org/whl/cu121"
explicit = true
"""
)
class ComplexInstallTester(unittest.TestCase):
"""Main tester class."""
@unittest.skip("Skip this test - it takes a long time")
def test_iso_env(self) -> None:
"""Test command line interface (CLI)."""
args = IsoEnvArgs(
venv_path=Path(".env_torch"),
build_info=PY_PROJECT_TOML,
)
iso = IsoEnv(args)
cp = iso.run(['python', '-c', "import torch; print(torch.__version__)"], check=True)
print(cp)
if __name__ == "__main__":
unittest.main()
To develop software, run . ./activate
Windows
This environment requires you to use git-bash.
Linting
Run ./lint to find linting errors.
Footguns
Please don't use shell=True when you run python unless you absolutely need to. Why? Because on Linux, if you are running a script and you have any errors, instead of bombing out immediately, python will drop you into a command terminal. This only happens on Linux (and maybe mac). It's a very nasty bug when you try and run your scripts on linux, causing your scripts to hang. The workaround is to use shutil.which(progname_str) and pass the resulting full path into iso.run([progname_str, ...], shell=False)
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 uv_iso_env-1.0.35.tar.gz.
File metadata
- Download URL: uv_iso_env-1.0.35.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1296fd41bebcd951cc01d74efe4343567b3588a6edff68346e0fa32102a26bf0
|
|
| MD5 |
814760d22ae9bb6d7e56e69c479676b4
|
|
| BLAKE2b-256 |
a0dfcec0610d9975c70f6c30389adbcc89f56979499bc305c974d58fbc8f7262
|
File details
Details for the file uv_iso_env-1.0.35-py3-none-any.whl.
File metadata
- Download URL: uv_iso_env-1.0.35-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b24e379c5958efb54fd7df6a3ef23b6015c053951b2c77115eb80982611f153
|
|
| MD5 |
6a2c3ae7f2f14d0e6ac6b093d0409fd3
|
|
| BLAKE2b-256 |
a30b30fe187cf9c56d2b3684d5b30c80199703804d9534afd0738ee140aeb75c
|