pynect 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +478 -2
- package/SECURITY.md +34 -0
- package/binding.gyp +60 -0
- package/dist/cli/codegen.d.ts +3 -0
- package/dist/cli/codegen.d.ts.map +1 -0
- package/dist/cli/codegen.js +543 -0
- package/dist/cli/codegen.js.map +1 -0
- package/dist/cli/sync.d.ts +3 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +48 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/config/project.d.ts +57 -0
- package/dist/config/project.d.ts.map +1 -0
- package/dist/config/project.js +176 -0
- package/dist/config/project.js.map +1 -0
- package/dist/core/IsolatedWorker.d.ts +39 -0
- package/dist/core/IsolatedWorker.d.ts.map +1 -0
- package/dist/core/IsolatedWorker.js +178 -0
- package/dist/core/IsolatedWorker.js.map +1 -0
- package/dist/core/PyCallable.d.ts +67 -0
- package/dist/core/PyCallable.d.ts.map +1 -0
- package/dist/core/PyCallable.js +104 -0
- package/dist/core/PyCallable.js.map +1 -0
- package/dist/core/PyContext.d.ts +76 -0
- package/dist/core/PyContext.d.ts.map +1 -0
- package/dist/core/PyContext.js +239 -0
- package/dist/core/PyContext.js.map +1 -0
- package/dist/core/PyIterator.d.ts +84 -0
- package/dist/core/PyIterator.d.ts.map +1 -0
- package/dist/core/PyIterator.js +243 -0
- package/dist/core/PyIterator.js.map +1 -0
- package/dist/core/PyModule.d.ts +53 -0
- package/dist/core/PyModule.d.ts.map +1 -0
- package/dist/core/PyModule.js +162 -0
- package/dist/core/PyModule.js.map +1 -0
- package/dist/core/PyProxy.d.ts +75 -0
- package/dist/core/PyProxy.d.ts.map +1 -0
- package/dist/core/PyProxy.js +563 -0
- package/dist/core/PyProxy.js.map +1 -0
- package/dist/core/PyRuntime.d.ts +112 -0
- package/dist/core/PyRuntime.d.ts.map +1 -0
- package/dist/core/PyRuntime.js +546 -0
- package/dist/core/PyRuntime.js.map +1 -0
- package/dist/env/PackageInstaller.d.ts +232 -0
- package/dist/env/PackageInstaller.d.ts.map +1 -0
- package/dist/env/PackageInstaller.js +628 -0
- package/dist/env/PackageInstaller.js.map +1 -0
- package/dist/env/ProjectEnvironment.d.ts +63 -0
- package/dist/env/ProjectEnvironment.d.ts.map +1 -0
- package/dist/env/ProjectEnvironment.js +379 -0
- package/dist/env/ProjectEnvironment.js.map +1 -0
- package/dist/env/PyfigAdapter.d.ts +32 -0
- package/dist/env/PyfigAdapter.d.ts.map +1 -0
- package/dist/env/PyfigAdapter.js +10 -0
- package/dist/env/PyfigAdapter.js.map +1 -0
- package/dist/env/PythonDetector.d.ts +48 -0
- package/dist/env/PythonDetector.d.ts.map +1 -0
- package/dist/env/PythonDetector.js +182 -0
- package/dist/env/PythonDetector.js.map +1 -0
- package/dist/env/PythonProvisioner.d.ts +16 -0
- package/dist/env/PythonProvisioner.d.ts.map +1 -0
- package/dist/env/PythonProvisioner.js +42 -0
- package/dist/env/PythonProvisioner.js.map +1 -0
- package/dist/env/VenvManager.d.ts +55 -0
- package/dist/env/VenvManager.d.ts.map +1 -0
- package/dist/env/VenvManager.js +153 -0
- package/dist/env/VenvManager.js.map +1 -0
- package/dist/env/executables.d.ts +3 -0
- package/dist/env/executables.d.ts.map +1 -0
- package/dist/env/executables.js +14 -0
- package/dist/env/executables.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +393 -0
- package/dist/index.js.map +1 -0
- package/dist/native/NativeAddonLoader.d.ts +11 -0
- package/dist/native/NativeAddonLoader.d.ts.map +1 -0
- package/dist/native/NativeAddonLoader.js +75 -0
- package/dist/native/NativeAddonLoader.js.map +1 -0
- package/dist/plugins/Plugin.interface.d.ts +41 -0
- package/dist/plugins/Plugin.interface.d.ts.map +1 -0
- package/dist/plugins/Plugin.interface.js +12 -0
- package/dist/plugins/Plugin.interface.js.map +1 -0
- package/dist/plugins/PluginManager.d.ts +26 -0
- package/dist/plugins/PluginManager.d.ts.map +1 -0
- package/dist/plugins/PluginManager.js +174 -0
- package/dist/plugins/PluginManager.js.map +1 -0
- package/dist/plugins/builtin/NumpyPlugin.d.ts +17 -0
- package/dist/plugins/builtin/NumpyPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/NumpyPlugin.js +41 -0
- package/dist/plugins/builtin/NumpyPlugin.js.map +1 -0
- package/dist/plugins/builtin/PandasPlugin.d.ts +19 -0
- package/dist/plugins/builtin/PandasPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/PandasPlugin.js +57 -0
- package/dist/plugins/builtin/PandasPlugin.js.map +1 -0
- package/dist/plugins/builtin/TorchPlugin.d.ts +23 -0
- package/dist/plugins/builtin/TorchPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/TorchPlugin.js +50 -0
- package/dist/plugins/builtin/TorchPlugin.js.map +1 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +12 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/serialization/DataFrameBridge.d.ts +141 -0
- package/dist/serialization/DataFrameBridge.d.ts.map +1 -0
- package/dist/serialization/DataFrameBridge.js +355 -0
- package/dist/serialization/DataFrameBridge.js.map +1 -0
- package/dist/serialization/MsgPackSerializer.d.ts +45 -0
- package/dist/serialization/MsgPackSerializer.d.ts.map +1 -0
- package/dist/serialization/MsgPackSerializer.js +242 -0
- package/dist/serialization/MsgPackSerializer.js.map +1 -0
- package/dist/serialization/NumpyBridge.d.ts +96 -0
- package/dist/serialization/NumpyBridge.d.ts.map +1 -0
- package/dist/serialization/NumpyBridge.js +323 -0
- package/dist/serialization/NumpyBridge.js.map +1 -0
- package/dist/serialization/Serializer.d.ts +78 -0
- package/dist/serialization/Serializer.d.ts.map +1 -0
- package/dist/serialization/Serializer.js +281 -0
- package/dist/serialization/Serializer.js.map +1 -0
- package/dist/types/addon.d.ts +131 -0
- package/dist/types/addon.d.ts.map +1 -0
- package/dist/types/addon.js +32 -0
- package/dist/types/addon.js.map +1 -0
- package/dist/types/config.d.ts +233 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +60 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/python.d.ts +235 -0
- package/dist/types/python.d.ts.map +1 -0
- package/dist/types/python.js +7 -0
- package/dist/types/python.js.map +1 -0
- package/dist/utils/ErrorTranslator.d.ts +83 -0
- package/dist/utils/ErrorTranslator.d.ts.map +1 -0
- package/dist/utils/ErrorTranslator.js +210 -0
- package/dist/utils/ErrorTranslator.js.map +1 -0
- package/dist/utils/Locking.d.ts +3 -0
- package/dist/utils/Locking.d.ts.map +1 -0
- package/dist/utils/Locking.js +10 -0
- package/dist/utils/Locking.js.map +1 -0
- package/dist/utils/Logger.d.ts +27 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +115 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/MemoryMonitor.d.ts +43 -0
- package/dist/utils/MemoryMonitor.d.ts.map +1 -0
- package/dist/utils/MemoryMonitor.js +143 -0
- package/dist/utils/MemoryMonitor.js.map +1 -0
- package/package.json +114 -4
- package/python/ast_inspector.py +248 -0
- package/python/error_handler.py +432 -0
- package/python/isolated_worker.py +94 -0
- package/python/pynect_dispatcher.py +382 -0
- package/python/pynect_runtime.py +574 -0
- package/python/serializer.py +373 -0
- package/python/type_inspector.py +315 -0
- package/scripts/build-native.js +50 -0
- package/scripts/cli.js +21 -0
- package/scripts/ensure-native.js +85 -0
- package/scripts/postinstall.js +40 -0
- package/scripts/pyfig.js +113 -0
- package/scripts/python-provisioner.js +23 -0
- package/scripts/smoke-python-boundary.js +103 -0
- package/src/native/NativeAddonLoader.ts +98 -0
- package/src/native/gil_guard.cpp +25 -0
- package/src/native/gil_guard.h +174 -0
- package/src/native/pynect_addon.cpp +942 -0
- package/src/native/python_bridge.cpp +904 -0
- package/src/native/python_bridge.h +263 -0
- package/src/native/thread_pool.cpp +375 -0
- package/src/native/thread_pool.h +185 -0
- package/src/native/type_converter.cpp +906 -0
- package/src/native/type_converter.h +271 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pynect - Main Entry Point
|
|
3
|
+
*
|
|
4
|
+
* Run Python libraries from Node.js as if they were Native.
|
|
5
|
+
* Embeds CPython in-process via N-API addon with full TypeScript types,
|
|
6
|
+
* Proxy-based API, async/await support, and Next.js integration.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { init, py } from 'pynect';
|
|
11
|
+
*
|
|
12
|
+
* await init({
|
|
13
|
+
* virtualenv: {
|
|
14
|
+
* path: './.venv',
|
|
15
|
+
* packages: ['pandas', 'numpy'],
|
|
16
|
+
* autoInstall: true,
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* const pd = await py.import('pandas');
|
|
21
|
+
* const df = await pd.read_csv('data.csv');
|
|
22
|
+
* const result = await df.describe().to_dict('records');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { PyRuntime } from './core/PyRuntime';
|
|
26
|
+
import type { PynectConfig } from './types/config';
|
|
27
|
+
import type { PyProxyInterface } from './types/python';
|
|
28
|
+
import type { IsolatedCallOptions } from './core/IsolatedWorker';
|
|
29
|
+
/**
|
|
30
|
+
* The main `py` object - a proxy over the PyRuntime singleton.
|
|
31
|
+
* Provides access to all PyRuntime methods after initialization.
|
|
32
|
+
*
|
|
33
|
+
* @throws {PynectNotInitializedError} if accessed before calling `init()`
|
|
34
|
+
*/
|
|
35
|
+
export declare const py: PyRuntime;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the pynect runtime.
|
|
38
|
+
* Must be called before using `py` or any other pynect API.
|
|
39
|
+
*
|
|
40
|
+
* Calling `init()` multiple times is safe - subsequent calls are no-ops
|
|
41
|
+
* unless `shutdown()` was called first, or `force: true` is passed.
|
|
42
|
+
*
|
|
43
|
+
* @param config - pynect configuration options
|
|
44
|
+
* @param options - Additional initialization options
|
|
45
|
+
* @returns Promise that resolves when Python is ready
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* await init({
|
|
50
|
+
* virtualenv: { path: '.venv', packages: ['pandas'], autoInstall: true },
|
|
51
|
+
* logLevel: 'info',
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function init(config?: PynectConfig, options?: {
|
|
56
|
+
force?: boolean;
|
|
57
|
+
}): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Shut down the pynect runtime and release all Python resources.
|
|
60
|
+
* After calling this, `py` is no longer accessible until `init()` is called again.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* await shutdown();
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function shutdown(): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Check if pynect is initialized and ready to use.
|
|
70
|
+
*/
|
|
71
|
+
export declare function isInitialized(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current PyRuntime instance.
|
|
74
|
+
* @throws {PynectNotInitializedError} if not initialized
|
|
75
|
+
*/
|
|
76
|
+
export declare function getRuntime(): PyRuntime;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize the default runtime when needed, then import a Python module.
|
|
79
|
+
* Call `init(config)` first when custom runtime settings are required.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const np = await importModule('numpy');
|
|
84
|
+
* const arr = await np.array([1, 2, 3]);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
/** Module types contributed by `pynect codegen`. */
|
|
88
|
+
export interface PynectModules {
|
|
89
|
+
}
|
|
90
|
+
export declare function importModule<Name extends keyof PynectModules & string>(moduleName: Name): Promise<PynectModules[Name]>;
|
|
91
|
+
export declare function importModule(moduleName: string): Promise<PyProxyInterface>;
|
|
92
|
+
/** Call a JSON-compatible function through the optional killable Python worker. */
|
|
93
|
+
export declare function callIsolated<T = unknown>(moduleName: string, functionName: string, args?: unknown[], options?: IsolatedCallOptions): Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* Evaluate a Python expression and return the result.
|
|
96
|
+
* Shorthand for `py.eval(expression)`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const result = await evalPython('1 + 2 + 3');
|
|
101
|
+
* // result === 6
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export declare function evalPython(expression: string): Promise<unknown>;
|
|
105
|
+
/**
|
|
106
|
+
* Execute Python code (statements, not expressions).
|
|
107
|
+
* Shorthand for `py.exec(code)`.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* await execPython(`
|
|
112
|
+
* import sys
|
|
113
|
+
* print(f"Python {sys.version}")
|
|
114
|
+
* `);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function execPython(code: string): Promise<void>;
|
|
118
|
+
/**
|
|
119
|
+
* Run a Python script file.
|
|
120
|
+
*/
|
|
121
|
+
export declare function runFile(filePath: string): Promise<unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Install Python packages into the configured virtualenv.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* await installPackages(['pandas', 'numpy>=1.24.0', 'scikit-learn']);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function installPackages(packages: string[]): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Get memory statistics for the Python heap.
|
|
133
|
+
*/
|
|
134
|
+
export declare function getMemoryStats(): Promise<{
|
|
135
|
+
pythonHeapBytes: number;
|
|
136
|
+
pythonHeapPeakBytes: number;
|
|
137
|
+
trackedObjects: number;
|
|
138
|
+
pendingCallbacks: number;
|
|
139
|
+
}>;
|
|
140
|
+
/**
|
|
141
|
+
* Trigger Python garbage collection.
|
|
142
|
+
*/
|
|
143
|
+
export declare function collectGarbage(): Promise<void>;
|
|
144
|
+
export { PyRuntime } from './core/PyRuntime';
|
|
145
|
+
export { PyProxy, PYNECT_WITH_OPTIONS } from './core/PyProxy';
|
|
146
|
+
export type { PynectFunction } from './core/PyProxy';
|
|
147
|
+
export { PyModule } from './core/PyModule';
|
|
148
|
+
export { PyCallable } from './core/PyCallable';
|
|
149
|
+
export { PyIterator } from './core/PyIterator';
|
|
150
|
+
export { PyContext } from './core/PyContext';
|
|
151
|
+
export { IsolatedWorker } from './core/IsolatedWorker';
|
|
152
|
+
export type { IsolatedCallOptions } from './core/IsolatedWorker';
|
|
153
|
+
export { Serializer } from './serialization/Serializer';
|
|
154
|
+
export { NumpyBridge } from './serialization/NumpyBridge';
|
|
155
|
+
export { DataFrameBridge } from './serialization/DataFrameBridge';
|
|
156
|
+
export { PythonError, PythonValueError, PythonTypeError, PythonKeyError, PythonIndexError, PythonAttributeError, PythonImportError, PythonModuleNotFoundError, PythonFileNotFoundError, PythonPermissionError, PythonRuntimeError, PythonMemoryError, PythonStopIteration, PythonTimeoutError, PynectNotInitializedError, PynectShutdownError, translatePythonError, isPythonError, isPythonErrorOfType, } from './utils/ErrorTranslator';
|
|
157
|
+
export { PythonDetector } from './env/PythonDetector';
|
|
158
|
+
export { VenvManager } from './env/VenvManager';
|
|
159
|
+
export { PackageInstaller } from './env/PackageInstaller';
|
|
160
|
+
export { createProjectPlan, discoverPynectContributions, moduleDispatcherIncludes, resolveExposedModule, syncProject, validateProjectEnvironment, } from './env/ProjectEnvironment';
|
|
161
|
+
export { resolveProjectConfig } from './config/project';
|
|
162
|
+
export { PluginManager } from './plugins/PluginManager';
|
|
163
|
+
export type { PynectConfig, ResolvedPynectConfig, VirtualenvConfig, IsolationConfig, DispatcherConfig, LogLevel, PyObjectId, PyTypeInfo, PyParamInfo, PyCallableInfo, PyClassInfo, PyModuleInspection, SerializedFormat, SerializedValue, PyCallResult, PyErrorInfo, DataFrameResult, SeriesResult, NumPyArrayResult, PyProxyInterface, AttributePath, NativeAddon, PyCallOptions, } from './types/index';
|
|
164
|
+
export type { AutoSyncMode, PynectModuleManifest, PynectPackageManifest, ResolvedProjectConfig, } from './config/project';
|
|
165
|
+
export type { ExposedModule, PynectContribution, PynectEnvironmentState, PynectProjectPlan, SyncProjectOptions, SyncProjectResult, } from './env/ProjectEnvironment';
|
|
166
|
+
declare const _default: {
|
|
167
|
+
init: typeof init;
|
|
168
|
+
shutdown: typeof shutdown;
|
|
169
|
+
isInitialized: typeof isInitialized;
|
|
170
|
+
getRuntime: typeof getRuntime;
|
|
171
|
+
py: PyRuntime;
|
|
172
|
+
import: typeof importModule;
|
|
173
|
+
callIsolated: typeof callIsolated;
|
|
174
|
+
eval: typeof evalPython;
|
|
175
|
+
exec: typeof execPython;
|
|
176
|
+
runFile: typeof runFile;
|
|
177
|
+
installPackages: typeof installPackages;
|
|
178
|
+
getMemoryStats: typeof getMemoryStats;
|
|
179
|
+
collectGarbage: typeof collectGarbage;
|
|
180
|
+
};
|
|
181
|
+
export default _default;
|
|
182
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAA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,mBAAmB,EACnB,kBAAkB,EAClB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,0BAA0B,GAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,UAAU,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,WAAW,EACX,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;;;;;;;;;;;;;;;;AAGlC,wBAcE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* pynect - Main Entry Point
|
|
4
|
+
*
|
|
5
|
+
* Run Python libraries from Node.js as if they were Native.
|
|
6
|
+
* Embeds CPython in-process via N-API addon with full TypeScript types,
|
|
7
|
+
* Proxy-based API, async/await support, and Next.js integration.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { init, py } from 'pynect';
|
|
12
|
+
*
|
|
13
|
+
* await init({
|
|
14
|
+
* virtualenv: {
|
|
15
|
+
* path: './.venv',
|
|
16
|
+
* packages: ['pandas', 'numpy'],
|
|
17
|
+
* autoInstall: true,
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const pd = await py.import('pandas');
|
|
22
|
+
* const df = await pd.read_csv('data.csv');
|
|
23
|
+
* const result = await df.describe().to_dict('records');
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.PluginManager = exports.resolveProjectConfig = exports.validateProjectEnvironment = exports.syncProject = exports.resolveExposedModule = exports.moduleDispatcherIncludes = exports.discoverPynectContributions = exports.createProjectPlan = exports.PackageInstaller = exports.VenvManager = exports.PythonDetector = exports.isPythonErrorOfType = exports.isPythonError = exports.translatePythonError = exports.PynectShutdownError = exports.PynectNotInitializedError = exports.PythonTimeoutError = exports.PythonStopIteration = exports.PythonMemoryError = exports.PythonRuntimeError = exports.PythonPermissionError = exports.PythonFileNotFoundError = exports.PythonModuleNotFoundError = exports.PythonImportError = exports.PythonAttributeError = exports.PythonIndexError = exports.PythonKeyError = exports.PythonTypeError = exports.PythonValueError = exports.PythonError = exports.DataFrameBridge = exports.NumpyBridge = exports.Serializer = exports.IsolatedWorker = exports.PyContext = exports.PyIterator = exports.PyCallable = exports.PyModule = exports.PYNECT_WITH_OPTIONS = exports.PyProxy = exports.PyRuntime = exports.py = void 0;
|
|
28
|
+
exports.init = init;
|
|
29
|
+
exports.shutdown = shutdown;
|
|
30
|
+
exports.isInitialized = isInitialized;
|
|
31
|
+
exports.getRuntime = getRuntime;
|
|
32
|
+
exports.importModule = importModule;
|
|
33
|
+
exports.callIsolated = callIsolated;
|
|
34
|
+
exports.evalPython = evalPython;
|
|
35
|
+
exports.execPython = execPython;
|
|
36
|
+
exports.runFile = runFile;
|
|
37
|
+
exports.installPackages = installPackages;
|
|
38
|
+
exports.getMemoryStats = getMemoryStats;
|
|
39
|
+
exports.collectGarbage = collectGarbage;
|
|
40
|
+
const PyRuntime_1 = require("./core/PyRuntime");
|
|
41
|
+
const Logger_1 = require("./utils/Logger");
|
|
42
|
+
const ErrorTranslator_1 = require("./utils/ErrorTranslator");
|
|
43
|
+
const ProjectEnvironment_1 = require("./env/ProjectEnvironment");
|
|
44
|
+
const Locking_1 = require("./utils/Locking");
|
|
45
|
+
// Singleton Runtime Management
|
|
46
|
+
let _runtime = null;
|
|
47
|
+
let _autoShutdownEnabled = true;
|
|
48
|
+
const _logger = new Logger_1.Logger('pynect');
|
|
49
|
+
// Main py Object (Proxy over PyRuntime)
|
|
50
|
+
/**
|
|
51
|
+
* The main `py` object - a proxy over the PyRuntime singleton.
|
|
52
|
+
* Provides access to all PyRuntime methods after initialization.
|
|
53
|
+
*
|
|
54
|
+
* @throws {PynectNotInitializedError} if accessed before calling `init()`
|
|
55
|
+
*/
|
|
56
|
+
exports.py = new Proxy({}, {
|
|
57
|
+
get(_target, prop) {
|
|
58
|
+
if (!_runtime) {
|
|
59
|
+
// Provide helpful error for common misuse
|
|
60
|
+
if (prop === 'then') {
|
|
61
|
+
// Prevent silent "awaiting py" mistakes
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
throw new ErrorTranslator_1.PynectNotInitializedError(`Cannot access py.${String(prop)} because Pynect is not initialized. ` +
|
|
65
|
+
`Call 'await init()' before using 'py'.`);
|
|
66
|
+
}
|
|
67
|
+
const value = _runtime[prop];
|
|
68
|
+
if (typeof value === 'function') {
|
|
69
|
+
return value.bind(_runtime);
|
|
70
|
+
}
|
|
71
|
+
return value;
|
|
72
|
+
},
|
|
73
|
+
set(_target, prop, value) {
|
|
74
|
+
if (!_runtime) {
|
|
75
|
+
throw new ErrorTranslator_1.PynectNotInitializedError('Pynect is not initialized.');
|
|
76
|
+
}
|
|
77
|
+
_runtime[prop] = value;
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
has(_target, prop) {
|
|
81
|
+
if (!_runtime) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return prop in _runtime;
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
// Lifecycle Functions
|
|
88
|
+
/**
|
|
89
|
+
* Initialize the pynect runtime.
|
|
90
|
+
* Must be called before using `py` or any other pynect API.
|
|
91
|
+
*
|
|
92
|
+
* Calling `init()` multiple times is safe - subsequent calls are no-ops
|
|
93
|
+
* unless `shutdown()` was called first, or `force: true` is passed.
|
|
94
|
+
*
|
|
95
|
+
* @param config - pynect configuration options
|
|
96
|
+
* @param options - Additional initialization options
|
|
97
|
+
* @returns Promise that resolves when Python is ready
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* await init({
|
|
102
|
+
* virtualenv: { path: '.venv', packages: ['pandas'], autoInstall: true },
|
|
103
|
+
* logLevel: 'info',
|
|
104
|
+
* });
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
async function init(config, options) {
|
|
108
|
+
await (0, Locking_1.withPynectLock)({ operation: 'init' }, async () => {
|
|
109
|
+
if (_runtime && !options?.force) {
|
|
110
|
+
_logger.debug('Pynect already initialized; skipping');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (_runtime && options?.force)
|
|
114
|
+
await _doShutdown();
|
|
115
|
+
await _doInit(config);
|
|
116
|
+
}, undefined, {
|
|
117
|
+
key: 'pynect-runtime-lifecycle',
|
|
118
|
+
name: 'Pynect runtime lifecycle',
|
|
119
|
+
namespace: 'pynect',
|
|
120
|
+
scope: 'memory',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
async function _doInit(config) {
|
|
124
|
+
_logger.info('Initializing Pynect runtime');
|
|
125
|
+
const startTime = performance.now();
|
|
126
|
+
try {
|
|
127
|
+
_runtime = await PyRuntime_1.PyRuntime.create(config);
|
|
128
|
+
_autoShutdownEnabled = _runtime.getConfig().autoShutdown;
|
|
129
|
+
if (_autoShutdownEnabled) {
|
|
130
|
+
_registerCleanup();
|
|
131
|
+
}
|
|
132
|
+
const elapsed = (performance.now() - startTime).toFixed(0);
|
|
133
|
+
_logger.success(`Pynect runtime ready in ${elapsed}ms`);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
_runtime = null;
|
|
137
|
+
_logger.error('Failed to initialize Pynect runtime', err);
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Shut down the pynect runtime and release all Python resources.
|
|
143
|
+
* After calling this, `py` is no longer accessible until `init()` is called again.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```typescript
|
|
147
|
+
* await shutdown();
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async function shutdown() {
|
|
151
|
+
await (0, Locking_1.withPynectLock)({ operation: 'shutdown' }, async () => _doShutdown(), undefined, {
|
|
152
|
+
key: 'pynect-runtime-lifecycle',
|
|
153
|
+
name: 'Pynect runtime lifecycle',
|
|
154
|
+
namespace: 'pynect',
|
|
155
|
+
scope: 'memory',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async function _doShutdown() {
|
|
159
|
+
if (!_runtime) {
|
|
160
|
+
_logger.debug('Pynect is not initialized; nothing to shut down');
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
_logger.info('Shutting down Pynect runtime');
|
|
164
|
+
const runtime = _runtime;
|
|
165
|
+
try {
|
|
166
|
+
await runtime.shutdown();
|
|
167
|
+
_runtime = null;
|
|
168
|
+
_logger.success('Pynect runtime shut down');
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
_logger.error('Error during Pynect shutdown', err);
|
|
172
|
+
throw err;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Check if pynect is initialized and ready to use.
|
|
177
|
+
*/
|
|
178
|
+
function isInitialized() {
|
|
179
|
+
return _runtime !== null && _runtime.isRunning();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get the current PyRuntime instance.
|
|
183
|
+
* @throws {PynectNotInitializedError} if not initialized
|
|
184
|
+
*/
|
|
185
|
+
function getRuntime() {
|
|
186
|
+
if (!_runtime) {
|
|
187
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
188
|
+
}
|
|
189
|
+
return _runtime;
|
|
190
|
+
}
|
|
191
|
+
async function importModule(moduleName) {
|
|
192
|
+
if (!_runtime) {
|
|
193
|
+
await init();
|
|
194
|
+
}
|
|
195
|
+
if (!_runtime) {
|
|
196
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
197
|
+
}
|
|
198
|
+
const exposed = moduleName.includes(':')
|
|
199
|
+
? (0, ProjectEnvironment_1.resolveExposedModule)(moduleName, _runtime.getConfig().projectRoot)
|
|
200
|
+
: undefined;
|
|
201
|
+
if (moduleName.includes(':') && !exposed) {
|
|
202
|
+
throw new Error(`Unknown Pynect module id: ${moduleName}`);
|
|
203
|
+
}
|
|
204
|
+
return _runtime.import(exposed?.import ?? moduleName);
|
|
205
|
+
}
|
|
206
|
+
/** Call a JSON-compatible function through the optional killable Python worker. */
|
|
207
|
+
async function callIsolated(moduleName, functionName, args = [], options = {}) {
|
|
208
|
+
if (!_runtime) {
|
|
209
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
210
|
+
}
|
|
211
|
+
return _runtime.callIsolated(moduleName, functionName, args, options);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Evaluate a Python expression and return the result.
|
|
215
|
+
* Shorthand for `py.eval(expression)`.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const result = await evalPython('1 + 2 + 3');
|
|
220
|
+
* // result === 6
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
async function evalPython(expression) {
|
|
224
|
+
if (!_runtime) {
|
|
225
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
226
|
+
}
|
|
227
|
+
return _runtime.eval(expression);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Execute Python code (statements, not expressions).
|
|
231
|
+
* Shorthand for `py.exec(code)`.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* await execPython(`
|
|
236
|
+
* import sys
|
|
237
|
+
* print(f"Python {sys.version}")
|
|
238
|
+
* `);
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
async function execPython(code) {
|
|
242
|
+
if (!_runtime) {
|
|
243
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
244
|
+
}
|
|
245
|
+
return _runtime.exec(code);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Run a Python script file.
|
|
249
|
+
*/
|
|
250
|
+
async function runFile(filePath) {
|
|
251
|
+
if (!_runtime) {
|
|
252
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
253
|
+
}
|
|
254
|
+
return _runtime.runFile(filePath);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Install Python packages into the configured virtualenv.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* await installPackages(['pandas', 'numpy>=1.24.0', 'scikit-learn']);
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
async function installPackages(packages) {
|
|
265
|
+
if (!_runtime) {
|
|
266
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
267
|
+
}
|
|
268
|
+
return _runtime.installPackages(packages);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Get memory statistics for the Python heap.
|
|
272
|
+
*/
|
|
273
|
+
async function getMemoryStats() {
|
|
274
|
+
if (!_runtime) {
|
|
275
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
276
|
+
}
|
|
277
|
+
return _runtime.getMemoryStats();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Trigger Python garbage collection.
|
|
281
|
+
*/
|
|
282
|
+
async function collectGarbage() {
|
|
283
|
+
if (!_runtime) {
|
|
284
|
+
throw new ErrorTranslator_1.PynectNotInitializedError();
|
|
285
|
+
}
|
|
286
|
+
return _runtime.collectGarbage();
|
|
287
|
+
}
|
|
288
|
+
// Auto-cleanup on process exit
|
|
289
|
+
let _cleanupRegistered = false;
|
|
290
|
+
function _registerCleanup() {
|
|
291
|
+
if (_cleanupRegistered) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
_cleanupRegistered = true;
|
|
295
|
+
const cleanup = () => {
|
|
296
|
+
if (!_autoShutdownEnabled || !_runtime) {
|
|
297
|
+
return Promise.resolve();
|
|
298
|
+
}
|
|
299
|
+
return shutdown().catch(() => undefined);
|
|
300
|
+
};
|
|
301
|
+
process.on('beforeExit', cleanup);
|
|
302
|
+
process.on('exit', () => {
|
|
303
|
+
if (_autoShutdownEnabled && _runtime) {
|
|
304
|
+
try {
|
|
305
|
+
_runtime.shutdownSync();
|
|
306
|
+
}
|
|
307
|
+
catch {
|
|
308
|
+
// Process exit cleanup is best-effort.
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
// Exports
|
|
314
|
+
// Core
|
|
315
|
+
var PyRuntime_2 = require("./core/PyRuntime");
|
|
316
|
+
Object.defineProperty(exports, "PyRuntime", { enumerable: true, get: function () { return PyRuntime_2.PyRuntime; } });
|
|
317
|
+
var PyProxy_1 = require("./core/PyProxy");
|
|
318
|
+
Object.defineProperty(exports, "PyProxy", { enumerable: true, get: function () { return PyProxy_1.PyProxy; } });
|
|
319
|
+
Object.defineProperty(exports, "PYNECT_WITH_OPTIONS", { enumerable: true, get: function () { return PyProxy_1.PYNECT_WITH_OPTIONS; } });
|
|
320
|
+
var PyModule_1 = require("./core/PyModule");
|
|
321
|
+
Object.defineProperty(exports, "PyModule", { enumerable: true, get: function () { return PyModule_1.PyModule; } });
|
|
322
|
+
var PyCallable_1 = require("./core/PyCallable");
|
|
323
|
+
Object.defineProperty(exports, "PyCallable", { enumerable: true, get: function () { return PyCallable_1.PyCallable; } });
|
|
324
|
+
var PyIterator_1 = require("./core/PyIterator");
|
|
325
|
+
Object.defineProperty(exports, "PyIterator", { enumerable: true, get: function () { return PyIterator_1.PyIterator; } });
|
|
326
|
+
var PyContext_1 = require("./core/PyContext");
|
|
327
|
+
Object.defineProperty(exports, "PyContext", { enumerable: true, get: function () { return PyContext_1.PyContext; } });
|
|
328
|
+
var IsolatedWorker_1 = require("./core/IsolatedWorker");
|
|
329
|
+
Object.defineProperty(exports, "IsolatedWorker", { enumerable: true, get: function () { return IsolatedWorker_1.IsolatedWorker; } });
|
|
330
|
+
// Serialization
|
|
331
|
+
var Serializer_1 = require("./serialization/Serializer");
|
|
332
|
+
Object.defineProperty(exports, "Serializer", { enumerable: true, get: function () { return Serializer_1.Serializer; } });
|
|
333
|
+
var NumpyBridge_1 = require("./serialization/NumpyBridge");
|
|
334
|
+
Object.defineProperty(exports, "NumpyBridge", { enumerable: true, get: function () { return NumpyBridge_1.NumpyBridge; } });
|
|
335
|
+
var DataFrameBridge_1 = require("./serialization/DataFrameBridge");
|
|
336
|
+
Object.defineProperty(exports, "DataFrameBridge", { enumerable: true, get: function () { return DataFrameBridge_1.DataFrameBridge; } });
|
|
337
|
+
// Error types
|
|
338
|
+
var ErrorTranslator_2 = require("./utils/ErrorTranslator");
|
|
339
|
+
Object.defineProperty(exports, "PythonError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonError; } });
|
|
340
|
+
Object.defineProperty(exports, "PythonValueError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonValueError; } });
|
|
341
|
+
Object.defineProperty(exports, "PythonTypeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonTypeError; } });
|
|
342
|
+
Object.defineProperty(exports, "PythonKeyError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonKeyError; } });
|
|
343
|
+
Object.defineProperty(exports, "PythonIndexError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonIndexError; } });
|
|
344
|
+
Object.defineProperty(exports, "PythonAttributeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonAttributeError; } });
|
|
345
|
+
Object.defineProperty(exports, "PythonImportError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonImportError; } });
|
|
346
|
+
Object.defineProperty(exports, "PythonModuleNotFoundError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonModuleNotFoundError; } });
|
|
347
|
+
Object.defineProperty(exports, "PythonFileNotFoundError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonFileNotFoundError; } });
|
|
348
|
+
Object.defineProperty(exports, "PythonPermissionError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonPermissionError; } });
|
|
349
|
+
Object.defineProperty(exports, "PythonRuntimeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonRuntimeError; } });
|
|
350
|
+
Object.defineProperty(exports, "PythonMemoryError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonMemoryError; } });
|
|
351
|
+
Object.defineProperty(exports, "PythonStopIteration", { enumerable: true, get: function () { return ErrorTranslator_2.PythonStopIteration; } });
|
|
352
|
+
Object.defineProperty(exports, "PythonTimeoutError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonTimeoutError; } });
|
|
353
|
+
Object.defineProperty(exports, "PynectNotInitializedError", { enumerable: true, get: function () { return ErrorTranslator_2.PynectNotInitializedError; } });
|
|
354
|
+
Object.defineProperty(exports, "PynectShutdownError", { enumerable: true, get: function () { return ErrorTranslator_2.PynectShutdownError; } });
|
|
355
|
+
Object.defineProperty(exports, "translatePythonError", { enumerable: true, get: function () { return ErrorTranslator_2.translatePythonError; } });
|
|
356
|
+
Object.defineProperty(exports, "isPythonError", { enumerable: true, get: function () { return ErrorTranslator_2.isPythonError; } });
|
|
357
|
+
Object.defineProperty(exports, "isPythonErrorOfType", { enumerable: true, get: function () { return ErrorTranslator_2.isPythonErrorOfType; } });
|
|
358
|
+
// Environment management
|
|
359
|
+
var PythonDetector_1 = require("./env/PythonDetector");
|
|
360
|
+
Object.defineProperty(exports, "PythonDetector", { enumerable: true, get: function () { return PythonDetector_1.PythonDetector; } });
|
|
361
|
+
var VenvManager_1 = require("./env/VenvManager");
|
|
362
|
+
Object.defineProperty(exports, "VenvManager", { enumerable: true, get: function () { return VenvManager_1.VenvManager; } });
|
|
363
|
+
var PackageInstaller_1 = require("./env/PackageInstaller");
|
|
364
|
+
Object.defineProperty(exports, "PackageInstaller", { enumerable: true, get: function () { return PackageInstaller_1.PackageInstaller; } });
|
|
365
|
+
var ProjectEnvironment_2 = require("./env/ProjectEnvironment");
|
|
366
|
+
Object.defineProperty(exports, "createProjectPlan", { enumerable: true, get: function () { return ProjectEnvironment_2.createProjectPlan; } });
|
|
367
|
+
Object.defineProperty(exports, "discoverPynectContributions", { enumerable: true, get: function () { return ProjectEnvironment_2.discoverPynectContributions; } });
|
|
368
|
+
Object.defineProperty(exports, "moduleDispatcherIncludes", { enumerable: true, get: function () { return ProjectEnvironment_2.moduleDispatcherIncludes; } });
|
|
369
|
+
Object.defineProperty(exports, "resolveExposedModule", { enumerable: true, get: function () { return ProjectEnvironment_2.resolveExposedModule; } });
|
|
370
|
+
Object.defineProperty(exports, "syncProject", { enumerable: true, get: function () { return ProjectEnvironment_2.syncProject; } });
|
|
371
|
+
Object.defineProperty(exports, "validateProjectEnvironment", { enumerable: true, get: function () { return ProjectEnvironment_2.validateProjectEnvironment; } });
|
|
372
|
+
var project_1 = require("./config/project");
|
|
373
|
+
Object.defineProperty(exports, "resolveProjectConfig", { enumerable: true, get: function () { return project_1.resolveProjectConfig; } });
|
|
374
|
+
// Plugins
|
|
375
|
+
var PluginManager_1 = require("./plugins/PluginManager");
|
|
376
|
+
Object.defineProperty(exports, "PluginManager", { enumerable: true, get: function () { return PluginManager_1.PluginManager; } });
|
|
377
|
+
// Default export
|
|
378
|
+
exports.default = {
|
|
379
|
+
init,
|
|
380
|
+
shutdown,
|
|
381
|
+
isInitialized,
|
|
382
|
+
getRuntime,
|
|
383
|
+
py: exports.py,
|
|
384
|
+
import: importModule,
|
|
385
|
+
callIsolated,
|
|
386
|
+
eval: evalPython,
|
|
387
|
+
exec: execPython,
|
|
388
|
+
runFile,
|
|
389
|
+
installPackages,
|
|
390
|
+
getMemoryStats,
|
|
391
|
+
collectGarbage,
|
|
392
|
+
};
|
|
393
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAiFH,oBAsBC;AA4BD,4BAYC;AAwBD,sCAEC;AAMD,gCAKC;AAqBD,oCAUC;AAGD,oCAQC;AAYD,gCAGC;AAcD,gCAGC;AAKD,0BAGC;AAUD,0CAGC;AAKD,wCAQC;AAKD,wCAGC;AAtSD,gDAA6C;AAC7C,2CAAwC;AACxC,6DAAoE;AAIpE,iEAAgE;AAChE,6CAAiD;AAEjD,+BAA+B;AAE/B,IAAI,QAAQ,GAAqB,IAAI,CAAC;AACtC,IAAI,oBAAoB,GAAG,IAAI,CAAC;AAEhC,MAAM,OAAO,GAAG,IAAI,eAAM,CAAC,QAAQ,CAAC,CAAC;AAErC,wCAAwC;AAExC;;;;;GAKG;AACU,QAAA,EAAE,GAAc,IAAI,KAAK,CAAC,EAAe,EAAE;IACtD,GAAG,CAAC,OAAO,EAAE,IAAqB;QAChC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,0CAA0C;YAC1C,IAAI,IAAI,KAAK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E5B,4CAAwD;AAA/C,+GAAA,oBAAoB,OAAA;AAE7B,UAAU;AACV,yDAAwD;AAA/C,8GAAA,aAAa,OAAA;AA2CtB,iBAAiB;AACjB,kBAAe;IACb,IAAI;IACJ,QAAQ;IACR,aAAa;IACb,UAAU;IACV,EAAE,EAAF,UAAE;IACF,MAAM,EAAE,YAAY;IACpB,YAAY;IACZ,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,eAAe;IACf,cAAc;IACd,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NativeAddon } from '../types/addon';
|
|
2
|
+
export interface NativeAddonBuildOptions {
|
|
3
|
+
projectRoot: string;
|
|
4
|
+
pythonExecutable: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Load an addon built for the selected Python, compiling it through the active
|
|
8
|
+
* JavaScript runtime when no exact match exists.
|
|
9
|
+
*/
|
|
10
|
+
export declare function loadOrBuildNativeAddon(options: NativeAddonBuildOptions): NativeAddon;
|
|
11
|
+
//# sourceMappingURL=NativeAddonLoader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeAddonLoader.d.ts","sourceRoot":"","sources":["../../src/native/NativeAddonLoader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,WAAW,CA2CpF"}
|