Skip to content

Commit

Permalink
Merge pull request #36 from isidentical/isolate-interact
Browse files Browse the repository at this point in the history
feat: Isolate builder APIs!
  • Loading branch information
isidentical authored Nov 7, 2022
2 parents 51f83ea + bb4bb76 commit 23c0781
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 233 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,37 @@
Run any Python function, with any dependencies, in any machine you want. Isolate offers a
pluggable end-to-end solution for building, managing, and using isolated environments (virtualenv,
conda, and possibly more).
conda, remote, and more).

## Try it!

```py
from isolate import Template, LocalBox

# Build you first environment by specifying its kind (like virtualenv or conda)
template = Template("virtualenv")

# Add some packages to it.
template << "pyjokes==0.5.0"

# Forward it to a box (your local machine, or a remote machine)
environment = template >> LocalBox()

# And then, finally try executing some code

def get_pyjokes_version():
import pyjokes

return pyjokes.__version__

# If pyjokes==0.6.0 is installed in your local environment, it is going to print
# 0.6.0 here.
print("Installed pyjokes version: ", get_pyjokes_version())

# But if you run the same function in an isolated environment, you'll get
# 0.5.0.
print("Isolated pyjokes version: ", environment.run(get_pyjokes_version))
```

## Motivation

Expand Down
338 changes: 134 additions & 204 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ description = "Managed isolated environments for Python"
authors = ["Features & Labels <[email protected]>"]

[tool.poetry.dependencies]
python = ">=3.7"
python = ">=3.7,<4.0"
virtualenv = ">=20.4"
importlib-metadata = ">=4.4"
grpcio = { version = ">=1.49", optional = true }
protobuf = { version = "*", optional = true }
rich = ">=12.0"
grpcio = ">=1.49"
protobuf = "*"

[tool.poetry.extras]
grpc = ["grpcio", "protobuf"]
server = ["grpcio", "protobuf"]
grpc = []
server = []

[tool.poetry.plugins."isolate.backends"]
"virtualenv" = "isolate.backends.virtualenv:VirtualPythonEnvironment"
Expand Down
9 changes: 7 additions & 2 deletions src/isolate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
from isolate.interface import (
Box,
BoxedEnvironment,
LocalBox,
RemoteBox,
Template,
)
from isolate.registry import prepare_environment

__version__ = "0.1.0"
3 changes: 3 additions & 0 deletions src/isolate/backends/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def create(self) -> EnvironmentDefinition:
configuration=interface.to_struct(self.target_environment_config),
)

def exists(self) -> bool:
return False

def open_connection(
self, connection_key: EnvironmentDefinition
) -> IsolateServerConnection:
Expand Down
4 changes: 3 additions & 1 deletion src/isolate/backends/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import tempfile
from contextlib import contextmanager
from dataclasses import dataclass
from dataclasses import dataclass, replace
from pathlib import Path
from typing import TYPE_CHECKING, Callable, Iterator

Expand Down Expand Up @@ -77,5 +77,7 @@ def cache_dir_for(self, backend: BaseEnvironment) -> Path:
environment_base_path.mkdir(exist_ok=True, parents=True)
return environment_base_path / backend.key

replace = replace


DEFAULT_SETTINGS = IsolateSettings()
Loading

0 comments on commit 23c0781

Please sign in to comment.