nodepyx 1.0.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 +22 -0
- package/README.md +399 -0
- package/binding.gyp +73 -0
- package/dist/core/PyCallable.d.ts +65 -0
- package/dist/core/PyCallable.d.ts.map +1 -0
- package/dist/core/PyCallable.js +109 -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 +228 -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 +55 -0
- package/dist/core/PyModule.d.ts.map +1 -0
- package/dist/core/PyModule.js +172 -0
- package/dist/core/PyModule.js.map +1 -0
- package/dist/core/PyProxy.d.ts +65 -0
- package/dist/core/PyProxy.d.ts.map +1 -0
- package/dist/core/PyProxy.js +483 -0
- package/dist/core/PyProxy.js.map +1 -0
- package/dist/core/PyRuntime.d.ts +105 -0
- package/dist/core/PyRuntime.d.ts.map +1 -0
- package/dist/core/PyRuntime.js +438 -0
- package/dist/core/PyRuntime.js.map +1 -0
- package/dist/env/CondaManager.d.ts +118 -0
- package/dist/env/CondaManager.d.ts.map +1 -0
- package/dist/env/CondaManager.js +401 -0
- package/dist/env/CondaManager.js.map +1 -0
- package/dist/env/PackageInstaller.d.ts +233 -0
- package/dist/env/PackageInstaller.d.ts.map +1 -0
- package/dist/env/PackageInstaller.js +609 -0
- package/dist/env/PackageInstaller.js.map +1 -0
- package/dist/env/PythonDetector.d.ts +103 -0
- package/dist/env/PythonDetector.d.ts.map +1 -0
- package/dist/env/PythonDetector.js +381 -0
- package/dist/env/PythonDetector.js.map +1 -0
- package/dist/env/VenvManager.d.ts +117 -0
- package/dist/env/VenvManager.d.ts.map +1 -0
- package/dist/env/VenvManager.js +331 -0
- package/dist/env/VenvManager.js.map +1 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +393 -0
- package/dist/index.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/PythonTypeMapper.d.ts +87 -0
- package/dist/types/PythonTypeMapper.d.ts.map +1 -0
- package/dist/types/PythonTypeMapper.js +449 -0
- package/dist/types/PythonTypeMapper.js.map +1 -0
- package/dist/types/StubCache.d.ts +109 -0
- package/dist/types/StubCache.d.ts.map +1 -0
- package/dist/types/StubCache.js +333 -0
- package/dist/types/StubCache.js.map +1 -0
- package/dist/types/TypeGenerator.d.ts +139 -0
- package/dist/types/TypeGenerator.d.ts.map +1 -0
- package/dist/types/TypeGenerator.js +372 -0
- package/dist/types/TypeGenerator.js.map +1 -0
- package/dist/types/addon.d.ts +114 -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 +175 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +35 -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/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 +44 -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 +177 -0
- package/python/error_handler.py +433 -0
- package/python/nodepyx_runtime.py +575 -0
- package/python/serializer.py +379 -0
- package/python/type_inspector.py +288 -0
- package/scripts/build-native.js +68 -0
- package/scripts/download-prebuilds.js +99 -0
- package/scripts/generate-stubs.js +405 -0
- package/scripts/install.js +260 -0
- package/src/core/PyCallable.ts +137 -0
- package/src/core/PyContext.ts +296 -0
- package/src/core/PyIterator.ts +294 -0
- package/src/core/PyModule.ts +194 -0
- package/src/core/PyProxy.ts +605 -0
- package/src/core/PyRuntime.ts +504 -0
- package/src/env/CondaManager.ts +451 -0
- package/src/env/PackageInstaller.ts +738 -0
- package/src/env/PythonDetector.ts +414 -0
- package/src/env/VenvManager.ts +396 -0
- package/src/index.ts +425 -0
- package/src/native/gil_guard.cpp +26 -0
- package/src/native/gil_guard.h +175 -0
- package/src/native/nodepyx_addon.cpp +886 -0
- package/src/native/python_bridge.cpp +790 -0
- package/src/native/python_bridge.h +257 -0
- package/src/native/thread_pool.cpp +336 -0
- package/src/native/thread_pool.h +175 -0
- package/src/native/type_converter.cpp +901 -0
- package/src/native/type_converter.h +272 -0
- package/src/nextjs/PyProvider.tsx +123 -0
- package/src/nextjs/index.ts +21 -0
- package/src/nextjs/usePython.ts +106 -0
- package/src/nextjs/withnodepyx.ts +88 -0
- package/src/plugins/Plugin.interface.ts +51 -0
- package/src/plugins/PluginManager.ts +155 -0
- package/src/plugins/builtin/NumpyPlugin.ts +36 -0
- package/src/plugins/builtin/PandasPlugin.ts +49 -0
- package/src/plugins/builtin/TorchPlugin.ts +56 -0
- package/src/plugins/index.ts +7 -0
- package/src/serialization/DataFrameBridge.ts +398 -0
- package/src/serialization/MsgPackSerializer.ts +220 -0
- package/src/serialization/NumpyBridge.ts +332 -0
- package/src/serialization/Serializer.ts +320 -0
- package/src/types/PythonTypeMapper.ts +495 -0
- package/src/types/StubCache.ts +340 -0
- package/src/types/TypeGenerator.ts +491 -0
- package/src/types/addon.ts +170 -0
- package/src/types/config.ts +226 -0
- package/src/types/index.ts +55 -0
- package/src/types/python.ts +309 -0
- package/src/types/stubs/numpy.d.ts +441 -0
- package/src/types/stubs/pandas.d.ts +575 -0
- package/src/types/stubs/sklearn.d.ts +728 -0
- package/src/types/stubs/torch.d.ts +694 -0
- package/src/utils/ErrorTranslator.ts +220 -0
- package/src/utils/Logger.ts +119 -0
- package/src/utils/MemoryMonitor.ts +175 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* nodepyx — 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 'nodepyx';
|
|
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.PackageInstaller = exports.CondaManager = exports.VenvManager = exports.PythonDetector = exports.TypeGenerator = exports.isPythonErrorOfType = exports.isPythonError = exports.translatePythonError = exports.nodepyxShutdownError = exports.nodepyxNotInitializedError = 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.PyContext = exports.PyIterator = exports.PyCallable = exports.PyModule = 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.evalPython = evalPython;
|
|
34
|
+
exports.execPython = execPython;
|
|
35
|
+
exports.runFile = runFile;
|
|
36
|
+
exports.installPackages = installPackages;
|
|
37
|
+
exports.getMemoryStats = getMemoryStats;
|
|
38
|
+
exports.collectGarbage = collectGarbage;
|
|
39
|
+
const PyRuntime_1 = require("./core/PyRuntime");
|
|
40
|
+
const Logger_1 = require("./utils/Logger");
|
|
41
|
+
const ErrorTranslator_1 = require("./utils/ErrorTranslator");
|
|
42
|
+
// ─── Singleton Runtime Management ──────────────────────────────────────────
|
|
43
|
+
let _runtime = null;
|
|
44
|
+
let _initializing = false;
|
|
45
|
+
let _initPromise = null;
|
|
46
|
+
const _logger = new Logger_1.Logger('nodepyx');
|
|
47
|
+
// ─── Main py Object (Proxy over PyRuntime) ─────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* The main `py` object — a proxy over the PyRuntime singleton.
|
|
50
|
+
* Provides access to all PyRuntime methods after initialization.
|
|
51
|
+
*
|
|
52
|
+
* @throws {nodepyxNotInitializedError} if accessed before calling `init()`
|
|
53
|
+
*/
|
|
54
|
+
exports.py = new Proxy({}, {
|
|
55
|
+
get(_target, prop) {
|
|
56
|
+
if (!_runtime) {
|
|
57
|
+
// Provide helpful error for common misuse
|
|
58
|
+
if (prop === 'then') {
|
|
59
|
+
// Prevent silent "awaiting py" mistakes
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError(`Cannot access py.${String(prop)} — nodepyx is not initialized. ` +
|
|
63
|
+
`Call 'await nodepyx.init()' before using 'py'.`);
|
|
64
|
+
}
|
|
65
|
+
const value = _runtime[prop];
|
|
66
|
+
if (typeof value === 'function') {
|
|
67
|
+
return value.bind(_runtime);
|
|
68
|
+
}
|
|
69
|
+
return value;
|
|
70
|
+
},
|
|
71
|
+
set(_target, prop, value) {
|
|
72
|
+
if (!_runtime) {
|
|
73
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError('nodepyx is not initialized.');
|
|
74
|
+
}
|
|
75
|
+
_runtime[prop] = value;
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
78
|
+
has(_target, prop) {
|
|
79
|
+
if (!_runtime) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return prop in _runtime;
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
// ─── Lifecycle Functions ────────────────────────────────────────────────────
|
|
86
|
+
/**
|
|
87
|
+
* Initialize the nodepyx runtime.
|
|
88
|
+
* Must be called before using `py` or any other nodepyx API.
|
|
89
|
+
*
|
|
90
|
+
* Calling `init()` multiple times is safe — subsequent calls are no-ops
|
|
91
|
+
* unless `shutdown()` was called first, or `force: true` is passed.
|
|
92
|
+
*
|
|
93
|
+
* @param config - nodepyx configuration options
|
|
94
|
+
* @param options - Additional initialization options
|
|
95
|
+
* @returns Promise that resolves when Python is ready
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* await init({
|
|
100
|
+
* virtualenv: { path: '.venv', packages: ['pandas'], autoInstall: true },
|
|
101
|
+
* logLevel: 'info',
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
async function init(config, options) {
|
|
106
|
+
// Already initialized
|
|
107
|
+
if (_runtime && !options?.force) {
|
|
108
|
+
_logger.debug('nodepyx already initialized, skipping');
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Initialization in progress — wait for it
|
|
112
|
+
if (_initializing && _initPromise) {
|
|
113
|
+
return _initPromise;
|
|
114
|
+
}
|
|
115
|
+
// Force re-init: shut down first
|
|
116
|
+
if (_runtime && options?.force) {
|
|
117
|
+
await shutdown();
|
|
118
|
+
}
|
|
119
|
+
_initializing = true;
|
|
120
|
+
_initPromise = _doInit(config);
|
|
121
|
+
try {
|
|
122
|
+
await _initPromise;
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
_initializing = false;
|
|
126
|
+
_initPromise = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async function _doInit(config) {
|
|
130
|
+
_logger.info('Initializing nodepyx runtime...');
|
|
131
|
+
const startTime = performance.now();
|
|
132
|
+
try {
|
|
133
|
+
_runtime = await PyRuntime_1.PyRuntime.create(config);
|
|
134
|
+
const elapsed = (performance.now() - startTime).toFixed(0);
|
|
135
|
+
_logger.success(`nodepyx runtime ready in ${elapsed}ms`);
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
_runtime = null;
|
|
139
|
+
_logger.error('Failed to initialize nodepyx runtime', err);
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Shut down the nodepyx runtime and release all Python resources.
|
|
145
|
+
* After calling this, `py` is no longer accessible until `init()` is called again.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* await shutdown();
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
async function shutdown() {
|
|
153
|
+
if (!_runtime) {
|
|
154
|
+
_logger.debug('nodepyx not initialized, nothing to shut down');
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
_logger.info('Shutting down nodepyx runtime...');
|
|
158
|
+
const runtime = _runtime;
|
|
159
|
+
_runtime = null;
|
|
160
|
+
try {
|
|
161
|
+
await runtime.shutdown();
|
|
162
|
+
_logger.success('nodepyx runtime shut down');
|
|
163
|
+
}
|
|
164
|
+
catch (err) {
|
|
165
|
+
_logger.error('Error during nodepyx shutdown', err);
|
|
166
|
+
throw err;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if nodepyx is initialized and ready to use.
|
|
171
|
+
*/
|
|
172
|
+
function isInitialized() {
|
|
173
|
+
return _runtime !== null && _runtime.isRunning();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get the current PyRuntime instance.
|
|
177
|
+
* @throws {nodepyxNotInitializedError} if not initialized
|
|
178
|
+
*/
|
|
179
|
+
function getRuntime() {
|
|
180
|
+
if (!_runtime) {
|
|
181
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
182
|
+
}
|
|
183
|
+
return _runtime;
|
|
184
|
+
}
|
|
185
|
+
// ─── Convenience API ────────────────────────────────────────────────────────
|
|
186
|
+
/**
|
|
187
|
+
* Import a Python module and return a Proxy.
|
|
188
|
+
* Shorthand for `py.import(moduleName)`.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```typescript
|
|
192
|
+
* const np = await importModule('numpy');
|
|
193
|
+
* const arr = await np.array([1, 2, 3]);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
async function importModule(moduleName) {
|
|
197
|
+
if (!_runtime) {
|
|
198
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
199
|
+
}
|
|
200
|
+
return _runtime.import(moduleName);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Evaluate a Python expression and return the result.
|
|
204
|
+
* Shorthand for `py.eval(expression)`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const result = await evalPython('1 + 2 + 3');
|
|
209
|
+
* // result === 6
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
async function evalPython(expression) {
|
|
213
|
+
if (!_runtime) {
|
|
214
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
215
|
+
}
|
|
216
|
+
return _runtime.eval(expression);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Execute Python code (statements, not expressions).
|
|
220
|
+
* Shorthand for `py.exec(code)`.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```typescript
|
|
224
|
+
* await execPython(`
|
|
225
|
+
* import sys
|
|
226
|
+
* print(f"Python {sys.version}")
|
|
227
|
+
* `);
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
async function execPython(code) {
|
|
231
|
+
if (!_runtime) {
|
|
232
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
233
|
+
}
|
|
234
|
+
return _runtime.exec(code);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Run a Python script file.
|
|
238
|
+
*/
|
|
239
|
+
async function runFile(filePath) {
|
|
240
|
+
if (!_runtime) {
|
|
241
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
242
|
+
}
|
|
243
|
+
return _runtime.runFile(filePath);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Install Python packages into the configured virtualenv.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* await installPackages(['pandas', 'numpy>=1.24.0', 'scikit-learn']);
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
async function installPackages(packages) {
|
|
254
|
+
if (!_runtime) {
|
|
255
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
256
|
+
}
|
|
257
|
+
return _runtime.installPackages(packages);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Get memory statistics for the Python heap.
|
|
261
|
+
*/
|
|
262
|
+
async function getMemoryStats() {
|
|
263
|
+
if (!_runtime) {
|
|
264
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
265
|
+
}
|
|
266
|
+
return _runtime.getMemoryStats();
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Trigger Python garbage collection.
|
|
270
|
+
*/
|
|
271
|
+
async function collectGarbage() {
|
|
272
|
+
if (!_runtime) {
|
|
273
|
+
throw new ErrorTranslator_1.nodepyxNotInitializedError();
|
|
274
|
+
}
|
|
275
|
+
return _runtime.collectGarbage();
|
|
276
|
+
}
|
|
277
|
+
// ─── Auto-cleanup on process exit ──────────────────────────────────────────
|
|
278
|
+
let _cleanupRegistered = false;
|
|
279
|
+
function _registerCleanup() {
|
|
280
|
+
if (_cleanupRegistered) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
_cleanupRegistered = true;
|
|
284
|
+
const cleanup = async () => {
|
|
285
|
+
if (_runtime) {
|
|
286
|
+
try {
|
|
287
|
+
await shutdown();
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// Ignore errors during cleanup
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
process.on('exit', () => {
|
|
295
|
+
// Synchronous cleanup on exit (best-effort)
|
|
296
|
+
if (_runtime) {
|
|
297
|
+
try {
|
|
298
|
+
_runtime.shutdownSync();
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
// ignore
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
process.on('SIGINT', async () => {
|
|
306
|
+
await cleanup();
|
|
307
|
+
process.exit(0);
|
|
308
|
+
});
|
|
309
|
+
process.on('SIGTERM', async () => {
|
|
310
|
+
await cleanup();
|
|
311
|
+
process.exit(0);
|
|
312
|
+
});
|
|
313
|
+
process.on('uncaughtException', async (err) => {
|
|
314
|
+
_logger.error('Uncaught exception, shutting down nodepyx', err);
|
|
315
|
+
await cleanup();
|
|
316
|
+
throw err;
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// Register cleanup automatically
|
|
320
|
+
_registerCleanup();
|
|
321
|
+
// ─── Exports ───────────────────────────────────────────────────────────────
|
|
322
|
+
// Core
|
|
323
|
+
var PyRuntime_2 = require("./core/PyRuntime");
|
|
324
|
+
Object.defineProperty(exports, "PyRuntime", { enumerable: true, get: function () { return PyRuntime_2.PyRuntime; } });
|
|
325
|
+
var PyProxy_1 = require("./core/PyProxy");
|
|
326
|
+
Object.defineProperty(exports, "PyProxy", { enumerable: true, get: function () { return PyProxy_1.PyProxy; } });
|
|
327
|
+
var PyModule_1 = require("./core/PyModule");
|
|
328
|
+
Object.defineProperty(exports, "PyModule", { enumerable: true, get: function () { return PyModule_1.PyModule; } });
|
|
329
|
+
var PyCallable_1 = require("./core/PyCallable");
|
|
330
|
+
Object.defineProperty(exports, "PyCallable", { enumerable: true, get: function () { return PyCallable_1.PyCallable; } });
|
|
331
|
+
var PyIterator_1 = require("./core/PyIterator");
|
|
332
|
+
Object.defineProperty(exports, "PyIterator", { enumerable: true, get: function () { return PyIterator_1.PyIterator; } });
|
|
333
|
+
var PyContext_1 = require("./core/PyContext");
|
|
334
|
+
Object.defineProperty(exports, "PyContext", { enumerable: true, get: function () { return PyContext_1.PyContext; } });
|
|
335
|
+
// Serialization
|
|
336
|
+
var Serializer_1 = require("./serialization/Serializer");
|
|
337
|
+
Object.defineProperty(exports, "Serializer", { enumerable: true, get: function () { return Serializer_1.Serializer; } });
|
|
338
|
+
var NumpyBridge_1 = require("./serialization/NumpyBridge");
|
|
339
|
+
Object.defineProperty(exports, "NumpyBridge", { enumerable: true, get: function () { return NumpyBridge_1.NumpyBridge; } });
|
|
340
|
+
var DataFrameBridge_1 = require("./serialization/DataFrameBridge");
|
|
341
|
+
Object.defineProperty(exports, "DataFrameBridge", { enumerable: true, get: function () { return DataFrameBridge_1.DataFrameBridge; } });
|
|
342
|
+
// Error types
|
|
343
|
+
var ErrorTranslator_2 = require("./utils/ErrorTranslator");
|
|
344
|
+
Object.defineProperty(exports, "PythonError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonError; } });
|
|
345
|
+
Object.defineProperty(exports, "PythonValueError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonValueError; } });
|
|
346
|
+
Object.defineProperty(exports, "PythonTypeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonTypeError; } });
|
|
347
|
+
Object.defineProperty(exports, "PythonKeyError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonKeyError; } });
|
|
348
|
+
Object.defineProperty(exports, "PythonIndexError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonIndexError; } });
|
|
349
|
+
Object.defineProperty(exports, "PythonAttributeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonAttributeError; } });
|
|
350
|
+
Object.defineProperty(exports, "PythonImportError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonImportError; } });
|
|
351
|
+
Object.defineProperty(exports, "PythonModuleNotFoundError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonModuleNotFoundError; } });
|
|
352
|
+
Object.defineProperty(exports, "PythonFileNotFoundError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonFileNotFoundError; } });
|
|
353
|
+
Object.defineProperty(exports, "PythonPermissionError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonPermissionError; } });
|
|
354
|
+
Object.defineProperty(exports, "PythonRuntimeError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonRuntimeError; } });
|
|
355
|
+
Object.defineProperty(exports, "PythonMemoryError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonMemoryError; } });
|
|
356
|
+
Object.defineProperty(exports, "PythonStopIteration", { enumerable: true, get: function () { return ErrorTranslator_2.PythonStopIteration; } });
|
|
357
|
+
Object.defineProperty(exports, "PythonTimeoutError", { enumerable: true, get: function () { return ErrorTranslator_2.PythonTimeoutError; } });
|
|
358
|
+
Object.defineProperty(exports, "nodepyxNotInitializedError", { enumerable: true, get: function () { return ErrorTranslator_2.nodepyxNotInitializedError; } });
|
|
359
|
+
Object.defineProperty(exports, "nodepyxShutdownError", { enumerable: true, get: function () { return ErrorTranslator_2.nodepyxShutdownError; } });
|
|
360
|
+
Object.defineProperty(exports, "translatePythonError", { enumerable: true, get: function () { return ErrorTranslator_2.translatePythonError; } });
|
|
361
|
+
Object.defineProperty(exports, "isPythonError", { enumerable: true, get: function () { return ErrorTranslator_2.isPythonError; } });
|
|
362
|
+
Object.defineProperty(exports, "isPythonErrorOfType", { enumerable: true, get: function () { return ErrorTranslator_2.isPythonErrorOfType; } });
|
|
363
|
+
// Type generation
|
|
364
|
+
var TypeGenerator_1 = require("./types/TypeGenerator");
|
|
365
|
+
Object.defineProperty(exports, "TypeGenerator", { enumerable: true, get: function () { return TypeGenerator_1.TypeGenerator; } });
|
|
366
|
+
// Environment management
|
|
367
|
+
var PythonDetector_1 = require("./env/PythonDetector");
|
|
368
|
+
Object.defineProperty(exports, "PythonDetector", { enumerable: true, get: function () { return PythonDetector_1.PythonDetector; } });
|
|
369
|
+
var VenvManager_1 = require("./env/VenvManager");
|
|
370
|
+
Object.defineProperty(exports, "VenvManager", { enumerable: true, get: function () { return VenvManager_1.VenvManager; } });
|
|
371
|
+
var CondaManager_1 = require("./env/CondaManager");
|
|
372
|
+
Object.defineProperty(exports, "CondaManager", { enumerable: true, get: function () { return CondaManager_1.CondaManager; } });
|
|
373
|
+
var PackageInstaller_1 = require("./env/PackageInstaller");
|
|
374
|
+
Object.defineProperty(exports, "PackageInstaller", { enumerable: true, get: function () { return PackageInstaller_1.PackageInstaller; } });
|
|
375
|
+
// Plugins
|
|
376
|
+
var PluginManager_1 = require("./plugins/PluginManager");
|
|
377
|
+
Object.defineProperty(exports, "PluginManager", { enumerable: true, get: function () { return PluginManager_1.PluginManager; } });
|
|
378
|
+
// Default export
|
|
379
|
+
exports.default = {
|
|
380
|
+
init,
|
|
381
|
+
shutdown,
|
|
382
|
+
isInitialized,
|
|
383
|
+
getRuntime,
|
|
384
|
+
py: exports.py,
|
|
385
|
+
import: importModule,
|
|
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;;;AA+EH,oBA6BC;AA0BD,4BAiBC;AAKD,sCAEC;AAMD,gCAKC;AAcD,oCAGC;AAYD,gCAGC;AAcD,gCAGC;AAKD,0BAGC;AAUD,0CAGC;AAKD,wCAQC;AAKD,wCAGC;AAlQD,gDAA6C;AAC7C,2CAAwC;AACxC,6DAAqE;AAIrE,wKAAwK;AAExK,IAAI,QAAQ,GAAqB,IAAI,CAAC;AACtC,IAAI,aAAa,GAAG,KAAK,CAAC;AAC1B,IAAI,YAAY,GAAyB,IAAI,CAAC;AAE9C,MAAM,OAAO,GAAG,IAAI,eAAM,CAAC,SAAS,CAAC,CAAC;AAEtC,sJAAsJ;AAEtJ;;;;;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,MAAM,EAAE,CAAC;gBACpB,wCAAwC;gBACxC,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,MAAM,IAAI,4CAA0B,CAClC,oBAAoB,MAAM,CAAC,IAAI,CAAC,mCAAmC;gBACnE,gDAAgD,CACjD,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAAI,QAAwD,CAAC,IAAI,CAAC,CAAC;QAC9E,IAAI,OAAO,KAAK,KAAK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,sHAAA,mBAAmB,OAAA;AAGrB,kBAAkB;AAClB,uDAAsD;AAA7C,8GAAA,aAAa,OAAA;AAEtB,yBAAyB;AACzB,uDAAsD;AAA7C,gHAAA,cAAc,OAAA;AACvB,iDAAgD;AAAvC,0GAAA,WAAW,OAAA;AACpB,mDAAkD;AAAzC,4GAAA,YAAY,OAAA;AACrB,2DAA0D;AAAjD,oHAAA,gBAAgB,OAAA;AAEzB,UAAU;AACV,yDAAwD;AAA/C,8GAAA,aAAa,OAAA;AA2BtB,iBAAiB;AACjB,kBAAe;IACb,IAAI;IACJ,QAAQ;IACR,aAAa;IACb,UAAU;IACV,EAAE,EAAF,UAAE;IACF,MAAM,EAAE,YAAY;IACpB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,eAAe;IACf,cAAc;IACd,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nodepyx — Plugin Interface
|
|
3
|
+
*
|
|
4
|
+
* Every nodepyx plugin must implement this interface. Plugins can:
|
|
5
|
+
* - Transform Python object values as they cross the JS boundary
|
|
6
|
+
* - Register custom type mappings
|
|
7
|
+
* - Hook into lifecycle events (init, shutdown)
|
|
8
|
+
* - Add convenience methods to PyProxy instances
|
|
9
|
+
*/
|
|
10
|
+
import type { SerializedValue } from '../types/python';
|
|
11
|
+
export type PythonTypeName = string;
|
|
12
|
+
export interface PluginInitContext {
|
|
13
|
+
runtimeVersion: string;
|
|
14
|
+
pythonVersion: {
|
|
15
|
+
major: number;
|
|
16
|
+
minor: number;
|
|
17
|
+
patch: number;
|
|
18
|
+
};
|
|
19
|
+
registerTypeHandler(typeName: PythonTypeName, handler: TypeTransformHandler): void;
|
|
20
|
+
}
|
|
21
|
+
export type TypeTransformHandler = (raw: SerializedValue, typeHint: string, metadata: Record<string, unknown>) => unknown | null;
|
|
22
|
+
export interface nodepyxPlugin {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly version: string;
|
|
25
|
+
readonly supportedModules: readonly string[];
|
|
26
|
+
readonly handledTypes?: readonly PythonTypeName[];
|
|
27
|
+
readonly description?: string;
|
|
28
|
+
readonly homepage?: string;
|
|
29
|
+
onInit?(ctx: PluginInitContext): Promise<void> | void;
|
|
30
|
+
onShutdown?(): Promise<void> | void;
|
|
31
|
+
onModuleImported?(moduleName: string, moduleOid: number): Promise<void> | void;
|
|
32
|
+
transformResult?: TypeTransformHandler;
|
|
33
|
+
serializeValue?(value: unknown, targetTypeName?: string): SerializedValue | null;
|
|
34
|
+
}
|
|
35
|
+
export interface PluginRegistration {
|
|
36
|
+
plugin: nodepyxPlugin;
|
|
37
|
+
active: boolean;
|
|
38
|
+
loadedAt: number;
|
|
39
|
+
modulesBound: Set<string>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Plugin.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Plugin.interface.d.ts","sourceRoot":"","sources":["../../src/plugins/Plugin.interface.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIvD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAEpC,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/D,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACpF;AAED,MAAM,MAAM,oBAAoB,GAAG,CACjC,GAAG,EAAO,eAAe,EACzB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC9B,OAAO,GAAG,IAAI,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAc,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAW,MAAM,CAAC;IAClC,QAAQ,CAAC,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7C,QAAQ,CAAC,YAAY,CAAC,EAAK,SAAS,cAAc,EAAE,CAAC;IACrD,QAAQ,CAAC,WAAW,CAAC,EAAM,MAAM,CAAC;IAClC,QAAQ,CAAC,QAAQ,CAAC,EAAS,MAAM,CAAC;IAElC,MAAM,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAwB,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3E,UAAU,CAAC,IAA2C,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC3E,gBAAgB,CAAC,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAE/E,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC,cAAc,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAAC;CAClF;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAQ,aAAa,CAAC;IAC5B,MAAM,EAAQ,OAAO,CAAC;IACtB,QAAQ,EAAM,MAAM,CAAC;IACrB,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* nodepyx — Plugin Interface
|
|
4
|
+
*
|
|
5
|
+
* Every nodepyx plugin must implement this interface. Plugins can:
|
|
6
|
+
* - Transform Python object values as they cross the JS boundary
|
|
7
|
+
* - Register custom type mappings
|
|
8
|
+
* - Hook into lifecycle events (init, shutdown)
|
|
9
|
+
* - Add convenience methods to PyProxy instances
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
//# sourceMappingURL=Plugin.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Plugin.interface.js","sourceRoot":"","sources":["../../src/plugins/Plugin.interface.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* nodepyx — PluginManager
|
|
3
|
+
*
|
|
4
|
+
* Manages registration, lifecycle, and dispatch of nodepyx plugins.
|
|
5
|
+
* PyRuntime holds a single PluginManager instance.
|
|
6
|
+
*/
|
|
7
|
+
import type { nodepyxPlugin, PluginRegistration, PluginInitContext } from './Plugin.interface';
|
|
8
|
+
import type { SerializedValue } from '../types/python';
|
|
9
|
+
export declare class PluginManager {
|
|
10
|
+
private readonly _plugins;
|
|
11
|
+
private readonly _typeMap;
|
|
12
|
+
private readonly _moduleMap;
|
|
13
|
+
register(plugin: nodepyxPlugin): this;
|
|
14
|
+
registerBuiltins(): Promise<void>;
|
|
15
|
+
initAll(ctx: PluginInitContext): Promise<void>;
|
|
16
|
+
shutdownAll(): Promise<void>;
|
|
17
|
+
onModuleImported(moduleName: string, moduleOid: number): Promise<void>;
|
|
18
|
+
transformResult(value: SerializedValue, typeName: string, metadata?: Record<string, unknown>): unknown | null;
|
|
19
|
+
serializeValue(value: unknown, targetTypeName?: string): SerializedValue | null;
|
|
20
|
+
get names(): string[];
|
|
21
|
+
getPlugin(name: string): PluginRegistration | undefined;
|
|
22
|
+
get active(): PluginRegistration[];
|
|
23
|
+
get all(): PluginRegistration[];
|
|
24
|
+
isActive(name: string): boolean;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/plugins/PluginManager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK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