| 174 | } |
| 175 | |
| 176 | export class PythonProvider implements ApiProvider { |
| 177 | config: PythonProviderConfig; |
| 178 | |
| 179 | private scriptPath: string; |
| 180 | private functionName: string | null; |
| 181 | private isInitialized: boolean = false; |
| 182 | private initializationPromise: Promise<void> | null = null; |
| 183 | public label: string | undefined; |
| 184 | private pool: PythonWorkerPool | null = null; |
| 185 | |
| 186 | constructor( |
| 187 | runPath: string, |
| 188 | private options?: ProviderOptions, |
| 189 | ) { |
| 190 | const { filePath: providerPath, functionName } = parsePathOrGlob( |
| 191 | options?.config.basePath || '', |
| 192 | runPath, |
| 193 | ); |
| 194 | this.scriptPath = path.relative(options?.config.basePath || '', providerPath); |
| 195 | this.functionName = functionName || null; |
| 196 | this.id = () => options?.id ?? `python:${this.scriptPath}:${this.functionName || 'default'}`; |
| 197 | this.label = options?.label; |
| 198 | this.config = options?.config ?? {}; |
| 199 | } |
| 200 | |
| 201 | id() { |
| 202 | return `python:${this.scriptPath}:${this.functionName || 'default'}`; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Process any file:// references in the configuration and initialize worker pool |
| 207 | * This should be called after initialization |
| 208 | * @returns A promise that resolves when all file references have been processed |
| 209 | */ |
| 210 | public async initialize(): Promise<void> { |
| 211 | // If already initialized, return immediately |
| 212 | if (this.isInitialized) { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | // If initialization is in progress, return the existing promise |
| 217 | if (this.initializationPromise != null) { |
| 218 | return this.initializationPromise; |
| 219 | } |
| 220 | |
| 221 | // Start initialization and store the promise |
| 222 | this.initializationPromise = (async () => { |
| 223 | try { |
| 224 | this.config = await processConfigFileReferences( |
| 225 | this.config, |
| 226 | this.options?.config.basePath || '', |
| 227 | ); |
| 228 | |
| 229 | // Initialize worker pool |
| 230 | const workerCount = this.getWorkerCount(); |
| 231 | const absPath = path.resolve( |
| 232 | path.join(this.options?.config.basePath || '', this.scriptPath), |
| 233 | ); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…