1
1
"""Client used to abstract the weird stdin/stdout communication we have with the sandbox"""
2
2
3
3
import logging
4
+ import os
5
+ import subprocess
4
6
5
7
from codegen .git .schemas .repo_config import RepoConfig
6
8
from codegen .runner .clients .server_client import LocalServerClient
7
9
from codegen .runner .models .apis import SANDBOX_SERVER_PORT
10
+ from codegen .shared .configs .session_configs import config
8
11
9
12
logger = logging .getLogger (__name__ )
10
13
@@ -22,15 +25,50 @@ def __init__(self, repo_config: RepoConfig, git_access_token: str | None, host:
22
25
self .git_access_token = git_access_token
23
26
super ().__init__ (server_path = RUNNER_SERVER_PATH , host = host , port = port )
24
27
25
- def _get_envs (self ):
28
+ def _get_envs (self ) -> dict :
26
29
envs = super ()._get_envs ()
27
- envs .update (
28
- {
29
- "CODEGEN_REPOSITORY__REPO_PATH" : self .repo_config .repo_path ,
30
- "CODEGEN_REPOSITORY__REPO_NAME" : self .repo_config .name ,
31
- "CODEGEN_REPOSITORY__FULL_NAME" : self .repo_config .full_name ,
32
- "CODEGEN_REPOSITORY__LANGUAGE" : self .repo_config .language .value ,
33
- "CODEGEN_SECRETS__GITHUB_TOKEN" : self .git_access_token ,
34
- }
35
- )
30
+ codebase_envs = {
31
+ "CODEGEN_REPOSITORY__REPO_PATH" : self .repo_config .repo_path ,
32
+ "CODEGEN_REPOSITORY__REPO_NAME" : self .repo_config .name ,
33
+ "CODEGEN_REPOSITORY__FULL_NAME" : self .repo_config .full_name ,
34
+ "CODEGEN_REPOSITORY__LANGUAGE" : self .repo_config .language .value ,
35
+ }
36
+ if self .git_access_token is not None :
37
+ codebase_envs ["CODEGEN_SECRETS__GITHUB_TOKEN" ] = self .git_access_token
38
+
39
+ envs .update (codebase_envs )
36
40
return envs
41
+
42
+ def _start_server (self , server_path : str ) -> None :
43
+ """Start the FastAPI server in a subprocess"""
44
+ codebase_envs = {
45
+ "CODEGEN_REPOSITORY__REPO_PATH" : self .repo_config .repo_path ,
46
+ "CODEGEN_REPOSITORY__REPO_NAME" : self .repo_config .name ,
47
+ "CODEGEN_REPOSITORY__FULL_NAME" : self .repo_config .full_name ,
48
+ "CODEGEN_REPOSITORY__LANGUAGE" : self .repo_config .language .value ,
49
+ }
50
+ if self .git_access_token is not None :
51
+ codebase_envs ["CODEGEN_SECRETS__GITHUB_TOKEN" ] = self .git_access_token
52
+
53
+ envs = os .environ .copy ()
54
+ envs .update (codebase_envs )
55
+ logger .info (f"Starting local server on { self .base_url } with envvars: { envs } " )
56
+
57
+ self ._process = subprocess .Popen (
58
+ [
59
+ "uvicorn" ,
60
+ server_path ,
61
+ "--host" ,
62
+ self .host ,
63
+ "--port" ,
64
+ str (self .port ),
65
+ ],
66
+ env = envs ,
67
+ )
68
+ self ._wait_for_server ()
69
+
70
+
71
+ if __name__ == "__main__" :
72
+ test_config = RepoConfig .from_repo_path ("/Users/caroljung/git/codegen/codegen-agi" )
73
+ client = CodebaseClient (test_config , config .secrets .github_token )
74
+ print (client .healthcheck ())
0 commit comments