MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / start_python

Method start_python

e2e/rust/src/harness/container.rs:92–150  ·  view source on GitHub ↗
(alias: &str, script: &str)

Source from the content-addressed store, hash-verified

90
91impl ContainerHttpServer {
92 pub async fn start_python(alias: &str, script: &str) -> Result<Self, String> {
93 let engine = ContainerEngine::from_env()?;
94 let host_port = find_free_port();
95 let network = e2e_network_name();
96 let host = network.as_ref().map_or_else(
97 || "host.openshell.internal".to_string(),
98 |_| alias.to_string(),
99 );
100 let port = if network.is_some() { 8000 } else { host_port };
101
102 let mut args = vec![
103 "run".to_string(),
104 "--detach".to_string(),
105 "--rm".to_string(),
106 "--entrypoint".to_string(),
107 "python3".to_string(),
108 ];
109 if let Some(network) = network.as_deref() {
110 args.extend([
111 "--network".to_string(),
112 network.to_string(),
113 "--network-alias".to_string(),
114 alias.to_string(),
115 ]);
116 } else {
117 args.extend(["-p".to_string(), format!("{host_port}:8000")]);
118 }
119 args.extend([
120 DEFAULT_TEST_SERVER_IMAGE.to_string(),
121 "-c".to_string(),
122 script.to_string(),
123 ]);
124
125 let output = engine
126 .command()
127 .args(&args)
128 .output()
129 .map_err(|e| format!("start {} test server: {e}", engine.name()))?;
130
131 let stdout = String::from_utf8_lossy(&output.stdout).trim().to_string();
132 let stderr = String::from_utf8_lossy(&output.stderr).to_string();
133
134 if !output.status.success() {
135 return Err(format!(
136 "{} run failed (exit {:?}):\n{stderr}",
137 engine.name(),
138 output.status.code()
139 ));
140 }
141
142 let server = Self {
143 host,
144 port,
145 container_id: stdout,
146 engine,
147 };
148 server.wait_until_ready().await?;
149 Ok(server)

Callers

nothing calls this directly

Calls 5

find_free_portFunction · 0.85
e2e_network_nameFunction · 0.85
commandMethod · 0.80
wait_until_readyMethod · 0.80
successMethod · 0.45

Tested by

no test coverage detected