pynect 0.2.7 → 0.2.10

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.
Files changed (106) hide show
  1. package/README.md +68 -27
  2. package/SECURITY.md +6 -6
  3. package/dist/cli/codegen.d.ts +3 -0
  4. package/dist/cli/codegen.d.ts.map +1 -1
  5. package/dist/cli/codegen.js +15 -3
  6. package/dist/cli/codegen.js.map +1 -1
  7. package/dist/cli/sync.d.ts.map +1 -1
  8. package/dist/cli/sync.js +38 -19
  9. package/dist/cli/sync.js.map +1 -1
  10. package/dist/config/project.d.ts +8 -52
  11. package/dist/config/project.d.ts.map +1 -1
  12. package/dist/config/project.js +74 -121
  13. package/dist/config/project.js.map +1 -1
  14. package/dist/core/isolated-worker.js +4 -4
  15. package/dist/core/isolated-worker.js.map +1 -1
  16. package/dist/core/py-proxy.d.ts +2 -1
  17. package/dist/core/py-proxy.d.ts.map +1 -1
  18. package/dist/core/py-proxy.js +55 -7
  19. package/dist/core/py-proxy.js.map +1 -1
  20. package/dist/core/py-runtime.d.ts +1 -5
  21. package/dist/core/py-runtime.d.ts.map +1 -1
  22. package/dist/core/py-runtime.js +36 -100
  23. package/dist/core/py-runtime.js.map +1 -1
  24. package/dist/core/pynect-callback.d.ts +16 -0
  25. package/dist/core/pynect-callback.d.ts.map +1 -0
  26. package/dist/core/pynect-callback.js +52 -0
  27. package/dist/core/pynect-callback.js.map +1 -0
  28. package/dist/env/project-environment.d.ts +9 -30
  29. package/dist/env/project-environment.d.ts.map +1 -1
  30. package/dist/env/project-environment.js +32 -217
  31. package/dist/env/project-environment.js.map +1 -1
  32. package/dist/env/python.d.ts +16 -0
  33. package/dist/env/python.d.ts.map +1 -0
  34. package/dist/env/python.js +9 -0
  35. package/dist/env/python.js.map +1 -0
  36. package/dist/index.d.ts +8 -24
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +5 -31
  39. package/dist/index.js.map +1 -1
  40. package/dist/native/native-addon-loader.d.ts.map +1 -1
  41. package/dist/native/native-addon-loader.js +15 -5
  42. package/dist/native/native-addon-loader.js.map +1 -1
  43. package/dist/types/addon.d.ts +6 -0
  44. package/dist/types/addon.d.ts.map +1 -1
  45. package/dist/types/addon.js.map +1 -1
  46. package/dist/types/config.d.ts +18 -85
  47. package/dist/types/config.d.ts.map +1 -1
  48. package/dist/types/config.js +17 -15
  49. package/dist/types/config.js.map +1 -1
  50. package/dist/types/index.d.ts +1 -1
  51. package/dist/types/index.d.ts.map +1 -1
  52. package/dist/types/python.d.ts +2 -0
  53. package/dist/types/python.d.ts.map +1 -1
  54. package/package.json +3 -4
  55. package/prebuilds/darwin-arm64/pynect-prebuild.json +1 -1
  56. package/prebuilds/darwin-arm64/pynect_addon.node +0 -0
  57. package/prebuilds/darwin-x64/pynect-prebuild.json +1 -1
  58. package/prebuilds/darwin-x64/pynect_addon.node +0 -0
  59. package/prebuilds/linux-arm64/pynect-prebuild.json +1 -1
  60. package/prebuilds/linux-arm64/pynect_addon.node +0 -0
  61. package/prebuilds/linux-x64/pynect-prebuild.json +1 -1
  62. package/prebuilds/linux-x64/pynect_addon.node +0 -0
  63. package/prebuilds/win32-arm64/pynect-prebuild.json +1 -1
  64. package/prebuilds/win32-arm64/pynect_addon.node +0 -0
  65. package/prebuilds/win32-x64/pynect-prebuild.json +1 -1
  66. package/prebuilds/win32-x64/pynect_addon.node +0 -0
  67. package/python/pynect_runtime.py +1 -1
  68. package/python/type_inspector.py +12 -0
  69. package/scripts/build-native.js +4 -3
  70. package/scripts/postinstall.js +2 -2
  71. package/scripts/python.js +33 -0
  72. package/scripts/smoke-python-boundary.js +72 -21
  73. package/src/native/callback_bridge.h +11 -0
  74. package/src/native/native-addon-loader.ts +13 -4
  75. package/src/native/pynect_addon.cpp +346 -4
  76. package/src/native/python_bridge.cpp +12 -0
  77. package/src/native/python_bridge.h +7 -0
  78. package/src/native/thread_pool.cpp +62 -55
  79. package/src/native/thread_pool.h +13 -0
  80. package/src/native/type_converter.h +2 -0
  81. package/dist/env/executables.d.ts +0 -3
  82. package/dist/env/executables.d.ts.map +0 -1
  83. package/dist/env/executables.js +0 -14
  84. package/dist/env/executables.js.map +0 -1
  85. package/dist/env/package-installer.d.ts +0 -232
  86. package/dist/env/package-installer.d.ts.map +0 -1
  87. package/dist/env/package-installer.js +0 -615
  88. package/dist/env/package-installer.js.map +0 -1
  89. package/dist/env/pyfig-adapter.d.ts +0 -38
  90. package/dist/env/pyfig-adapter.d.ts.map +0 -1
  91. package/dist/env/pyfig-adapter.js +0 -10
  92. package/dist/env/pyfig-adapter.js.map +0 -1
  93. package/dist/env/python-detector.d.ts +0 -48
  94. package/dist/env/python-detector.d.ts.map +0 -1
  95. package/dist/env/python-detector.js +0 -182
  96. package/dist/env/python-detector.js.map +0 -1
  97. package/dist/env/python-provisioner.d.ts +0 -16
  98. package/dist/env/python-provisioner.d.ts.map +0 -1
  99. package/dist/env/python-provisioner.js +0 -42
  100. package/dist/env/python-provisioner.js.map +0 -1
  101. package/dist/env/venv-manager.d.ts +0 -56
  102. package/dist/env/venv-manager.d.ts.map +0 -1
  103. package/dist/env/venv-manager.js +0 -160
  104. package/dist/env/venv-manager.js.map +0 -1
  105. package/scripts/pyfig.js +0 -142
  106. package/scripts/python-provisioner.js +0 -23
package/scripts/pyfig.js DELETED
@@ -1,142 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
-
6
- const REQUIRED_PYFIG_FUNCTIONS = [
7
- 'createPyfig',
8
- ];
9
-
10
- function loadPyfig() {
11
- const configured = process.env.PYNECT_PYFIG_PATH;
12
- if (configured) {
13
- return requireCompatiblePyfig(path.resolve(configured), 'PYNECT_PYFIG_PATH');
14
- }
15
- let packageError;
16
- try {
17
- return requireCompatiblePyfig('pyfig', 'installed pyfig package');
18
- } catch (error) {
19
- packageError = error;
20
- }
21
-
22
- // During coordinated source development, a published but older package can
23
- // resolve successfully. Prefer the sibling build when its API is compatible.
24
- const sibling = path.resolve(__dirname, '..', '..', 'pyfig', 'dist', 'cjs', 'index.js');
25
- if (fs.existsSync(sibling)) {
26
- return requireCompatiblePyfig(sibling, 'sibling pyfig build');
27
- }
28
-
29
- const detail = packageError instanceof Error ? ` ${packageError.message}` : '';
30
- throw new Error(
31
- `Pynect requires a Pyfig release with the venv and spawn API.${detail}`,
32
- { cause: packageError },
33
- );
34
- }
35
-
36
- function requireCompatiblePyfig(specifier, label) {
37
- const candidate = require(specifier);
38
- const missing = REQUIRED_PYFIG_FUNCTIONS.filter(name => typeof candidate[name] !== 'function');
39
- if (missing.length > 0) {
40
- throw new Error(`${label} is missing required exports: ${missing.join(', ')}.`);
41
- }
42
- return candidate;
43
- }
44
-
45
- function parseBoolean(value, fallback) {
46
- if (value === undefined) return fallback;
47
- if (/^(1|true|yes|on)$/i.test(value)) return true;
48
- if (/^(0|false|no|off)$/i.test(value)) return false;
49
- throw new TypeError(`Invalid boolean value: ${value}`);
50
- }
51
-
52
- function pep440PythonRange(value) {
53
- return value.trim().replace(/\s+(?=[<>=!~])/gu, ',');
54
- }
55
-
56
- function pep440UvRange(value) {
57
- const trimmed = value.trim();
58
- return /^\d+(?:\.\d+){1,2}$/u.test(trimmed) ? `==${trimmed}` : trimmed;
59
- }
60
-
61
- function projectRoot(explicit) {
62
- const hint = explicit || process.env.PYNECT_PROJECT_ROOT || process.env.INIT_CWD;
63
- return hint ? path.resolve(hint) : loadPyfig().resolveProjectRoot(process.cwd());
64
- }
65
-
66
- function pynectPyfigOptions(options = {}) {
67
- const pyfig = loadPyfig();
68
- const installPython = options.autoInstallPython ?? parseBoolean(
69
- process.env.PYNECT_INSTALL_PYTHON ?? process.env.PYNECT_AUTO_INSTALL,
70
- true,
71
- );
72
- return {
73
- projectRoot: projectRoot(options.projectRoot),
74
- python: options.pythonPath || process.env.PYNECT_PYTHON || '',
75
- requiresPython: pep440PythonRange(
76
- options.pythonRange || process.env.PYNECT_REQUIRES_PYTHON ||
77
- pyfig.DEFAULT_REQUIRES_PYTHON,
78
- ),
79
- managedPython: options.managedPython || process.env.PYNECT_MANAGED_PYTHON ||
80
- process.env.PYNECT_PYTHON_VERSION || pyfig.DEFAULT_MANAGED_PYTHON,
81
- requiresUv: pep440UvRange(
82
- options.uvVersion || process.env.PYNECT_REQUIRES_UV ||
83
- process.env.PYNECT_UV_VERSION || pyfig.DEFAULT_REQUIRES_UV,
84
- ),
85
- requireEmbedding: true,
86
- requireGil: true,
87
- installPython,
88
- installUv: options.autoInstallUv ?? parseBoolean(process.env.PYNECT_INSTALL_UV, true),
89
- createVirtualEnvironment: options.autoCreateVirtualEnvironment ??
90
- parseBoolean(process.env.PYNECT_CREATE_VIRTUAL_ENVIRONMENT, true),
91
- env: options.env ? { ...process.env, ...options.env } : process.env,
92
- };
93
- }
94
-
95
- function assertEmbeddable(python) {
96
- if (!python.embedding) {
97
- throw new Error(
98
- `Python ${python.version} at ${python.executable} is missing Python.h or its CPython ` +
99
- 'embedding library.',
100
- );
101
- }
102
- return python;
103
- }
104
-
105
- function createPynectPyfig(options = {}) {
106
- const client = loadPyfig().createPyfig(pynectPyfigOptions(options));
107
- return {
108
- ...client,
109
- python(args = [], spawnOptions = {}) {
110
- return client.uv(['run', '--', 'python', ...args], spawnOptions);
111
- },
112
- pythonSync(args = [], spawnOptions = {}) {
113
- return client.uvSync(['run', '--', 'python', ...args], spawnOptions);
114
- },
115
- pip(args = [], spawnOptions = {}) {
116
- return client.uv(['pip', ...args], spawnOptions);
117
- },
118
- pipSync(args = [], spawnOptions = {}) {
119
- return client.uvSync(['pip', ...args], spawnOptions);
120
- },
121
- };
122
- }
123
-
124
- async function ensurePynectPython(options = {}) {
125
- const client = createPynectPyfig(options);
126
- const python = assertEmbeddable(await client.pythonInfo());
127
- return { client, python };
128
- }
129
-
130
- async function ensurePynectEnvironment(options = {}) {
131
- const client = createPynectPyfig(options);
132
- const environment = await client.prepare();
133
- assertEmbeddable(environment.python);
134
- return { client, environment };
135
- }
136
-
137
- module.exports = {
138
- createPynectPyfig,
139
- ensurePynectEnvironment,
140
- ensurePynectPython,
141
- projectRoot,
142
- };
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const { ensurePynectPython } = require('./pyfig');
4
-
5
- async function ensurePython(options = {}) {
6
- const { python } = await ensurePynectPython({
7
- autoInstallPython: options.autoInstall,
8
- managedPython: options.version,
9
- pythonPath: options.pythonPath,
10
- projectRoot: options.projectRoot,
11
- });
12
- return python;
13
- }
14
-
15
- async function detectPython(explicit) {
16
- try {
17
- return await ensurePython({ autoInstall: false, pythonPath: explicit });
18
- } catch {
19
- return null;
20
- }
21
- }
22
-
23
- module.exports = { detectPython, ensurePython };