isolated-environment


Nameisolated-environment JSON
Version 1.3.4 PyPI version JSON
download
home_pagehttps://github.com/zackees/isolated-environment
SummaryLike Pipx, but allows creation of a virtual environment then populating it.
upload_time2024-03-25 04:52:03
maintainerZachary Vorhies
docs_urlNone
authorNone
requires_python>=3.7
licenseBSD 3-Clause License
keywords template-python-cmd
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # isolated-environment

[![Linting](https://github.com/zackees/isolated-environment/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/lint.yml)
[![MacOS_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_macos.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_macos.yml)
[![Ubuntu_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_ubuntu.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_ubuntu.yml)
[![Win_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_win.yml)

![image](https://github.com/zackees/isolated-environment/assets/6856673/8dab37f1-0c6e-42ec-9680-2013287baa98)

# Summary

Got pinned dependencies in your python package that make it hard to install? Use isolated-environment to package those up in a runtime `venv` that only your package has access to.

This is a package isolation library designed originally for AI developers to solve the problems
of AI dependency conflicts introduced by the various `pytorch`/`tensorflow`/etc incompatibilities within and between AI apps.

*Install*
```bash
pip install isolated-environment
```

*Runtime*
```python
# Example of running "whisper --help" in an isolated-environment
from pathlib import Path
import subprocess
from isolated_environment import isolated_environment_run

TENSOR_VERSION = "2.1.2"
CUDA_VERSION = "cu121"
EXTRA_INDEX_URL = f"https://download.pytorch.org/whl/{CUDA_VERSION}"
HERE = Path(os.path.abspath(os.path.dirname(__file__)))

venv_path = Path(HERE) / "whisper-venv"
requirements = [
    "whisper-whisper",
    f"torch=={TENSOR_VERSION}+{CUDA_VERSION} --extra-index-url {EXTRA_INDEX_URL}"
]
cmd_list = ["whisper", "--help"]
# Note that shell=False, universal_newlines=True, capture=True
cp: subprocess.CompletedProcess = isolated_environment_run(
    env_path=venv_path,
    requirements=requirements,
    cmd_list=cmd_list)
print(cp.stdout)
```

Install cuda pytorch when nvidia-smi is found:

```python
# This generates an environment that should be passed to subprocess.run(...)
def get_environment() -> dict[str, Any]:
    """Returns the environment suitable for subprocess.run(..., env=env,...)"""
    venv_dir = HERE / "venv" / "whisper"
    deps = [
        "openai-whisper",
    ]
    if has_nvidia_smi():
        deps.append(  # This computer has nvidia cuda installed so install cuda torch.
            f"torch=={TENSOR_VERSION}+{CUDA_VERSION} --extra-index-url {EXTRA_INDEX_URL}"
        )
    else:
        # Install CPU version.
        deps.append(f"torch=={TENSOR_VERSION}")
    env = isolated_environment(venv_dir, deps)
    return env
```

Any changes to the pip requirements list between runs will invoke a call to `pip install`.

It moves the install of your chosen dependencies from **install time** to **runtime**. The benefit of this is that you can query the system
and make choices on what needs to be installed. For example in `pip` you can't conditionally install packages based on whether `nvidia-smi` has
been installed (indicating `cuda` acceleration), but with `isolated-environment` this is straightfoward.

# Development

## Install

  * First time setup
    * clone the repo
    * run `./install`
  * To develop software, run `. ./activate.sh`

# Windows

This environment requires you to use `git-bash`.

# Linting

Run `./lint.sh` to find linting errors using `ruff`, `flake8` and `mypy`.

# License

This software is free to use for personal and commercial products. However, if you make changes to `isolated-environment` code you must agree to the
following "good-samaritan" stipulations:

  * All changes to `isolated-environment` **MUST** be put into a github fork, linked to this github project (https://github.com/zackees/isolated-environment).
    * That means clicking on the fork button on this repo, and then putting your changes into that fork.

This agreement means that `isolated-environment` can receive additional features from those that benefit from this package, so that others can benefit as well.

This supplemental licensing supersedes any language in the generic license attached. If you merely use `isolated-environment` as is, without modification,
none of this supplemental license applies to you.

# Releases
  * 1.3.4 - Isolation for pip too so that it doesn't bind to the parent pip.
  * 1.3.1 - New `full_isolation` mode to allow packages installed on other parts of the system from binding.
  * 1.3.1 - Update readme.
  * 1.3.0 - Marks a new interface.
  * 1.2.7 - Please use `isolated_environment_run()` instead of `isolated_environment`. The latter has
            footguns when using Linux when invoking `python` and `shell=True`
  * 1.2.6 - Update readme
  * 1.2.4 - Now support more build options, instead of just --extra-index-url.
  * 1.2.3 - All builds green with complex dependencies!
  * 1.2.2 - Tested and fixed complex semversion + build number for isolated_environment
  * 1.2.1 - Fixes `isolated_environment()` not installing deps correctly on first go
  * 1.2.0 - Now just use `isolated_environment()`, more simple.
  * 1.0.6 - `exists` -> `installed()`, adds `pip_list()`, adds `clean()`
  * 1.0.5 - Added `exists()`
  * 1.0.4 - Added `lock()`
  * 1.0.0 - Initial release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/zackees/isolated-environment",
    "name": "isolated-environment",
    "maintainer": "Zachary Vorhies",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "template-python-cmd",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/94/30/bca8ee2e7e8e4f2493a7726fce54c4718a43a683ef5bf074172ad04ee893/isolated-environment-1.3.4.tar.gz",
    "platform": null,
    "description": "# isolated-environment\r\n\r\n[![Linting](https://github.com/zackees/isolated-environment/actions/workflows/lint.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/lint.yml)\r\n[![MacOS_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_macos.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_macos.yml)\r\n[![Ubuntu_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_ubuntu.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_ubuntu.yml)\r\n[![Win_Tests](https://github.com/zackees/isolated-environment/actions/workflows/push_win.yml/badge.svg)](https://github.com/zackees/isolated-environment/actions/workflows/push_win.yml)\r\n\r\n![image](https://github.com/zackees/isolated-environment/assets/6856673/8dab37f1-0c6e-42ec-9680-2013287baa98)\r\n\r\n# Summary\r\n\r\nGot pinned dependencies in your python package that make it hard to install? Use isolated-environment to package those up in a runtime `venv` that only your package has access to.\r\n\r\nThis is a package isolation library designed originally for AI developers to solve the problems\r\nof AI dependency conflicts introduced by the various `pytorch`/`tensorflow`/etc incompatibilities within and between AI apps.\r\n\r\n*Install*\r\n```bash\r\npip install isolated-environment\r\n```\r\n\r\n*Runtime*\r\n```python\r\n# Example of running \"whisper --help\" in an isolated-environment\r\nfrom pathlib import Path\r\nimport subprocess\r\nfrom isolated_environment import isolated_environment_run\r\n\r\nTENSOR_VERSION = \"2.1.2\"\r\nCUDA_VERSION = \"cu121\"\r\nEXTRA_INDEX_URL = f\"https://download.pytorch.org/whl/{CUDA_VERSION}\"\r\nHERE = Path(os.path.abspath(os.path.dirname(__file__)))\r\n\r\nvenv_path = Path(HERE) / \"whisper-venv\"\r\nrequirements = [\r\n    \"whisper-whisper\",\r\n    f\"torch=={TENSOR_VERSION}+{CUDA_VERSION} --extra-index-url {EXTRA_INDEX_URL}\"\r\n]\r\ncmd_list = [\"whisper\", \"--help\"]\r\n# Note that shell=False, universal_newlines=True, capture=True\r\ncp: subprocess.CompletedProcess = isolated_environment_run(\r\n    env_path=venv_path,\r\n    requirements=requirements,\r\n    cmd_list=cmd_list)\r\nprint(cp.stdout)\r\n```\r\n\r\nInstall cuda pytorch when nvidia-smi is found:\r\n\r\n```python\r\n# This generates an environment that should be passed to subprocess.run(...)\r\ndef get_environment() -> dict[str, Any]:\r\n    \"\"\"Returns the environment suitable for subprocess.run(..., env=env,...)\"\"\"\r\n    venv_dir = HERE / \"venv\" / \"whisper\"\r\n    deps = [\r\n        \"openai-whisper\",\r\n    ]\r\n    if has_nvidia_smi():\r\n        deps.append(  # This computer has nvidia cuda installed so install cuda torch.\r\n            f\"torch=={TENSOR_VERSION}+{CUDA_VERSION} --extra-index-url {EXTRA_INDEX_URL}\"\r\n        )\r\n    else:\r\n        # Install CPU version.\r\n        deps.append(f\"torch=={TENSOR_VERSION}\")\r\n    env = isolated_environment(venv_dir, deps)\r\n    return env\r\n```\r\n\r\nAny changes to the pip requirements list between runs will invoke a call to `pip install`.\r\n\r\nIt moves the install of your chosen dependencies from **install time** to **runtime**. The benefit of this is that you can query the system\r\nand make choices on what needs to be installed. For example in `pip` you can't conditionally install packages based on whether `nvidia-smi` has\r\nbeen installed (indicating `cuda` acceleration), but with `isolated-environment` this is straightfoward.\r\n\r\n# Development\r\n\r\n## Install\r\n\r\n  * First time setup\r\n    * clone the repo\r\n    * run `./install`\r\n  * To develop software, run `. ./activate.sh`\r\n\r\n# Windows\r\n\r\nThis environment requires you to use `git-bash`.\r\n\r\n# Linting\r\n\r\nRun `./lint.sh` to find linting errors using `ruff`, `flake8` and `mypy`.\r\n\r\n# License\r\n\r\nThis software is free to use for personal and commercial products. However, if you make changes to `isolated-environment` code you must agree to the\r\nfollowing \"good-samaritan\" stipulations:\r\n\r\n  * All changes to `isolated-environment` **MUST** be put into a github fork, linked to this github project (https://github.com/zackees/isolated-environment).\r\n    * That means clicking on the fork button on this repo, and then putting your changes into that fork.\r\n\r\nThis agreement means that `isolated-environment` can receive additional features from those that benefit from this package, so that others can benefit as well.\r\n\r\nThis supplemental licensing supersedes any language in the generic license attached. If you merely use `isolated-environment` as is, without modification,\r\nnone of this supplemental license applies to you.\r\n\r\n# Releases\r\n  * 1.3.4 - Isolation for pip too so that it doesn't bind to the parent pip.\r\n  * 1.3.1 - New `full_isolation` mode to allow packages installed on other parts of the system from binding.\r\n  * 1.3.1 - Update readme.\r\n  * 1.3.0 - Marks a new interface.\r\n  * 1.2.7 - Please use `isolated_environment_run()` instead of `isolated_environment`. The latter has\r\n            footguns when using Linux when invoking `python` and `shell=True`\r\n  * 1.2.6 - Update readme\r\n  * 1.2.4 - Now support more build options, instead of just --extra-index-url.\r\n  * 1.2.3 - All builds green with complex dependencies!\r\n  * 1.2.2 - Tested and fixed complex semversion + build number for isolated_environment\r\n  * 1.2.1 - Fixes `isolated_environment()` not installing deps correctly on first go\r\n  * 1.2.0 - Now just use `isolated_environment()`, more simple.\r\n  * 1.0.6 - `exists` -> `installed()`, adds `pip_list()`, adds `clean()`\r\n  * 1.0.5 - Added `exists()`\r\n  * 1.0.4 - Added `lock()`\r\n  * 1.0.0 - Initial release\r\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "Like Pipx, but allows creation of a virtual environment then populating it.",
    "version": "1.3.4",
    "project_urls": {
        "Homepage": "https://github.com/zackees/isolated-environment"
    },
    "split_keywords": [
        "template-python-cmd"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d743605471f5ba43d22992bd4497b9ed8352140d2e6f0907f093cf3631ccd1c7",
                "md5": "e6df7b82e96f1212e6c98266c583d5ee",
                "sha256": "ba463e6b0b8e38240a946d82a5a906c5ae849fc6ce3f57f5b2807d20635832c5"
            },
            "downloads": -1,
            "filename": "isolated_environment-1.3.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e6df7b82e96f1212e6c98266c583d5ee",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 10975,
            "upload_time": "2024-03-25T04:52:01",
            "upload_time_iso_8601": "2024-03-25T04:52:01.658379Z",
            "url": "https://files.pythonhosted.org/packages/d7/43/605471f5ba43d22992bd4497b9ed8352140d2e6f0907f093cf3631ccd1c7/isolated_environment-1.3.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9430bca8ee2e7e8e4f2493a7726fce54c4718a43a683ef5bf074172ad04ee893",
                "md5": "109f0359f67485ec6309abc32fdf4a8f",
                "sha256": "f61e2d600ee24d604f7a0391fb5f69933e31ce1eeab8693c20e7e4316676408e"
            },
            "downloads": -1,
            "filename": "isolated-environment-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "109f0359f67485ec6309abc32fdf4a8f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 21674,
            "upload_time": "2024-03-25T04:52:03",
            "upload_time_iso_8601": "2024-03-25T04:52:03.437054Z",
            "url": "https://files.pythonhosted.org/packages/94/30/bca8ee2e7e8e4f2493a7726fce54c4718a43a683ef5bf074172ad04ee893/isolated-environment-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 04:52:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "zackees",
    "github_project": "isolated-environment",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "isolated-environment"
}
        
Elapsed time: 0.20659s