|
12 | 12 | from grpc import ServicerContext, StatusCode
|
13 | 13 |
|
14 | 14 | from isolate.backends import EnvironmentCreationError, IsolateSettings
|
| 15 | +from isolate.backends.common import active_python |
15 | 16 | from isolate.backends.local import LocalPythonEnvironment
|
| 17 | +from isolate.backends.virtualenv import VirtualPythonEnvironment |
16 | 18 | from isolate.connections.grpc import AgentError, LocalPythonGRPC
|
17 | 19 | from isolate.logs import Log, LogLevel, LogSource
|
18 | 20 | from isolate.server import definitions
|
|
23 | 25 |
|
24 | 26 | # Number of threads that the gRPC server will use.
|
25 | 27 | MAX_THREADS = int(os.getenv("MAX_THREADS", 5))
|
| 28 | +_AGENT_REQUIREMENTS_TXT = os.getenv("AGENT_REQUIREMENTS_TXT") |
| 29 | + |
| 30 | +if _AGENT_REQUIREMENTS_TXT is not None: |
| 31 | + with open(_AGENT_REQUIREMENTS_TXT) as stream: |
| 32 | + AGENT_REQUIREMENTS = stream.read().splitlines() |
| 33 | +else: |
| 34 | + AGENT_REQUIREMENTS = [] |
| 35 | + |
26 | 36 |
|
27 | 37 | # Number of seconds to observe the queue before checking the termination
|
28 | 38 | # event.
|
@@ -69,6 +79,18 @@ def Run(
|
69 | 79 | for environment in environments:
|
70 | 80 | environment.apply_settings(run_settings)
|
71 | 81 |
|
| 82 | + primary_environment = environments[0] |
| 83 | + |
| 84 | + if AGENT_REQUIREMENTS: |
| 85 | + python_version = getattr( |
| 86 | + primary_environment, "python_version", active_python() |
| 87 | + ) |
| 88 | + agent_environ = VirtualPythonEnvironment( |
| 89 | + requirements=AGENT_REQUIREMENTS, |
| 90 | + python_version=python_version, |
| 91 | + ) |
| 92 | + environments.insert(1, agent_environ) |
| 93 | + |
72 | 94 | extra_inheritance_paths = []
|
73 | 95 | if INHERIT_FROM_LOCAL:
|
74 | 96 | local_environment = LocalPythonEnvironment()
|
|
0 commit comments