tywrap 0.8.0 → 0.9.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.
Files changed (157) hide show
  1. package/README.md +22 -7
  2. package/SECURITY.md +39 -0
  3. package/dist/config/index.d.ts.map +1 -1
  4. package/dist/config/index.js +8 -0
  5. package/dist/config/index.js.map +1 -1
  6. package/dist/core/annotation-parser.d.ts +2 -1
  7. package/dist/core/annotation-parser.d.ts.map +1 -1
  8. package/dist/core/annotation-parser.js +6 -3
  9. package/dist/core/annotation-parser.js.map +1 -1
  10. package/dist/core/generator.d.ts +23 -4
  11. package/dist/core/generator.d.ts.map +1 -1
  12. package/dist/core/generator.js +243 -170
  13. package/dist/core/generator.js.map +1 -1
  14. package/dist/core/mapper.d.ts +3 -2
  15. package/dist/core/mapper.d.ts.map +1 -1
  16. package/dist/core/mapper.js +5 -5
  17. package/dist/core/mapper.js.map +1 -1
  18. package/dist/index.d.ts +7 -5
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +6 -4
  21. package/dist/index.js.map +1 -1
  22. package/dist/runtime/base-bridge.d.ts +3 -7
  23. package/dist/runtime/base-bridge.d.ts.map +1 -1
  24. package/dist/runtime/base-bridge.js +4 -17
  25. package/dist/runtime/base-bridge.js.map +1 -1
  26. package/dist/runtime/bounded-context.d.ts +3 -22
  27. package/dist/runtime/bounded-context.d.ts.map +1 -1
  28. package/dist/runtime/bounded-context.js +13 -53
  29. package/dist/runtime/bounded-context.js.map +1 -1
  30. package/dist/runtime/bridge-codec.d.ts +1 -1
  31. package/dist/runtime/bridge-codec.d.ts.map +1 -1
  32. package/dist/runtime/bridge-codec.js +78 -55
  33. package/dist/runtime/bridge-codec.js.map +1 -1
  34. package/dist/runtime/errors.d.ts +16 -0
  35. package/dist/runtime/errors.d.ts.map +1 -1
  36. package/dist/runtime/errors.js +17 -0
  37. package/dist/runtime/errors.js.map +1 -1
  38. package/dist/runtime/http-transport.d.ts +1 -1
  39. package/dist/runtime/http-transport.d.ts.map +1 -1
  40. package/dist/runtime/http-transport.js +1 -1
  41. package/dist/runtime/http-transport.js.map +1 -1
  42. package/dist/runtime/index.d.ts +1 -0
  43. package/dist/runtime/index.d.ts.map +1 -1
  44. package/dist/runtime/index.js +1 -0
  45. package/dist/runtime/index.js.map +1 -1
  46. package/dist/runtime/node.d.ts +7 -36
  47. package/dist/runtime/node.d.ts.map +1 -1
  48. package/dist/runtime/node.js +2 -80
  49. package/dist/runtime/node.js.map +1 -1
  50. package/dist/runtime/pooled-transport.d.ts +120 -59
  51. package/dist/runtime/pooled-transport.d.ts.map +1 -1
  52. package/dist/runtime/pooled-transport.js +345 -78
  53. package/dist/runtime/pooled-transport.js.map +1 -1
  54. package/dist/runtime/pyodide-bootstrap-core.generated.d.ts.map +1 -1
  55. package/dist/runtime/pyodide-bootstrap-core.generated.js +1 -1
  56. package/dist/runtime/pyodide-bootstrap-core.generated.js.map +1 -1
  57. package/dist/runtime/pyodide-transport.d.ts +1 -1
  58. package/dist/runtime/pyodide-transport.d.ts.map +1 -1
  59. package/dist/runtime/pyodide-transport.js +2 -3
  60. package/dist/runtime/pyodide-transport.js.map +1 -1
  61. package/dist/runtime/rpc-client.d.ts +7 -36
  62. package/dist/runtime/rpc-client.d.ts.map +1 -1
  63. package/dist/runtime/rpc-client.js +20 -102
  64. package/dist/runtime/rpc-client.js.map +1 -1
  65. package/dist/runtime/subprocess-transport.d.ts +30 -69
  66. package/dist/runtime/subprocess-transport.d.ts.map +1 -1
  67. package/dist/runtime/subprocess-transport.js +179 -236
  68. package/dist/runtime/subprocess-transport.js.map +1 -1
  69. package/dist/runtime/timed-out-request-tracker.d.ts +2 -1
  70. package/dist/runtime/timed-out-request-tracker.d.ts.map +1 -1
  71. package/dist/runtime/transport.d.ts +9 -19
  72. package/dist/runtime/transport.d.ts.map +1 -1
  73. package/dist/runtime/transport.js +1 -1
  74. package/dist/runtime/transport.js.map +1 -1
  75. package/dist/runtime/validators.d.ts +49 -0
  76. package/dist/runtime/validators.d.ts.map +1 -1
  77. package/dist/runtime/validators.js +152 -0
  78. package/dist/runtime/validators.js.map +1 -1
  79. package/dist/types/index.d.ts +14 -39
  80. package/dist/types/index.d.ts.map +1 -1
  81. package/dist/tywrap.d.ts +3 -2
  82. package/dist/tywrap.d.ts.map +1 -1
  83. package/dist/tywrap.js +140 -13
  84. package/dist/tywrap.js.map +1 -1
  85. package/dist/utils/cache.d.ts +3 -16
  86. package/dist/utils/cache.d.ts.map +1 -1
  87. package/dist/utils/codec.d.ts +1 -0
  88. package/dist/utils/codec.d.ts.map +1 -1
  89. package/dist/utils/codec.js +13 -13
  90. package/dist/utils/codec.js.map +1 -1
  91. package/dist/utils/ir-cache.d.ts +2 -1
  92. package/dist/utils/ir-cache.d.ts.map +1 -1
  93. package/dist/utils/runtime.d.ts +0 -29
  94. package/dist/utils/runtime.d.ts.map +1 -1
  95. package/dist/utils/runtime.js +16 -107
  96. package/dist/utils/runtime.js.map +1 -1
  97. package/dist/version.js +1 -1
  98. package/package.json +7 -6
  99. package/runtime/frame_codec.py +7 -1
  100. package/runtime/python_bridge.py +85 -125
  101. package/runtime/tywrap_bridge_core.py +133 -150
  102. package/src/config/index.ts +11 -0
  103. package/src/core/annotation-parser.ts +7 -4
  104. package/src/core/generator.ts +315 -205
  105. package/src/core/mapper.ts +8 -8
  106. package/src/index.ts +7 -4
  107. package/src/runtime/base-bridge.ts +5 -30
  108. package/src/runtime/bounded-context.ts +12 -67
  109. package/src/runtime/bridge-codec.ts +94 -65
  110. package/src/runtime/errors.ts +21 -0
  111. package/src/runtime/http-transport.ts +6 -1
  112. package/src/runtime/index.ts +6 -0
  113. package/src/runtime/node.ts +9 -120
  114. package/src/runtime/pooled-transport.ts +424 -90
  115. package/src/runtime/pyodide-bootstrap-core.generated.ts +1 -1
  116. package/src/runtime/pyodide-transport.ts +7 -3
  117. package/src/runtime/rpc-client.ts +37 -139
  118. package/src/runtime/subprocess-transport.ts +210 -285
  119. package/src/runtime/timed-out-request-tracker.ts +1 -1
  120. package/src/runtime/transport.ts +15 -23
  121. package/src/runtime/validators.ts +204 -0
  122. package/src/types/index.ts +21 -60
  123. package/src/tywrap.ts +157 -22
  124. package/src/utils/cache.ts +3 -3
  125. package/src/utils/codec.ts +21 -13
  126. package/src/utils/ir-cache.ts +1 -1
  127. package/src/utils/runtime.ts +17 -128
  128. package/src/version.ts +1 -1
  129. package/dist/core/discovery.d.ts +0 -103
  130. package/dist/core/discovery.d.ts.map +0 -1
  131. package/dist/core/discovery.js +0 -380
  132. package/dist/core/discovery.js.map +0 -1
  133. package/dist/core/validation.d.ts +0 -102
  134. package/dist/core/validation.d.ts.map +0 -1
  135. package/dist/core/validation.js +0 -490
  136. package/dist/core/validation.js.map +0 -1
  137. package/dist/runtime/base.d.ts +0 -22
  138. package/dist/runtime/base.d.ts.map +0 -1
  139. package/dist/runtime/base.js +0 -23
  140. package/dist/runtime/base.js.map +0 -1
  141. package/dist/runtime/transport-pool.d.ts +0 -196
  142. package/dist/runtime/transport-pool.d.ts.map +0 -1
  143. package/dist/runtime/transport-pool.js +0 -418
  144. package/dist/runtime/transport-pool.js.map +0 -1
  145. package/runtime/__pycache__/_tywrap_conformance_chunking_fixtures.cpython-311.pyc +0 -0
  146. package/runtime/__pycache__/_tywrap_member_fixtures.cpython-311.pyc +0 -0
  147. package/runtime/__pycache__/_tywrap_w4_chunking_fixture.cpython-311.pyc +0 -0
  148. package/runtime/__pycache__/_tywrap_w5_request_chunking_fixture.cpython-311.pyc +0 -0
  149. package/runtime/__pycache__/_tywrap_w6_pool_chunking_fixture.cpython-311.pyc +0 -0
  150. package/runtime/__pycache__/frame_codec.cpython-311.pyc +0 -0
  151. package/runtime/__pycache__/safe_codec.cpython-311.pyc +0 -0
  152. package/runtime/__pycache__/tywrap_bridge_core.cpython-311.pyc +0 -0
  153. package/runtime/safe_codec.py +0 -352
  154. package/src/core/discovery.ts +0 -477
  155. package/src/core/validation.ts +0 -729
  156. package/src/runtime/base.ts +0 -24
  157. package/src/runtime/transport-pool.ts +0 -538
@@ -1,103 +0,0 @@
1
- /**
2
- * Python Module Discovery System
3
- *
4
- * Handles module resolution, dependency detection, and file system operations
5
- * across different runtime environments
6
- */
7
- export interface ModuleInfo {
8
- name: string;
9
- path: string;
10
- version?: string;
11
- isPackage: boolean;
12
- dependencies: string[];
13
- }
14
- export interface DiscoveryOptions {
15
- pythonPath?: string;
16
- virtualEnv?: string;
17
- searchPaths?: string[];
18
- excludePatterns?: string[];
19
- includeStdLib?: boolean;
20
- timeoutMs?: number;
21
- }
22
- export declare class ModuleDiscovery {
23
- private options;
24
- private moduleCache;
25
- private dependencyGraph;
26
- private pythonExecPromise?;
27
- constructor(options?: DiscoveryOptions);
28
- private getPythonExecutable;
29
- /**
30
- * Find Python modules from various sources
31
- */
32
- findPythonModules(paths: string[]): Promise<ModuleInfo[]>;
33
- /**
34
- * Resolve Python module path from module name
35
- */
36
- resolvePythonPath(moduleName: string): Promise<string | null>;
37
- /**
38
- * Resolve a module path by asking the Python interpreter for `__file__`.
39
- * Caches and returns the resolved path, or `null` when the interpreter is
40
- * unavailable, reports a builtin, or fails.
41
- */
42
- private resolveViaInterpreter;
43
- /**
44
- * Fallback resolution: probe `<path>/<module>.py` and
45
- * `<path>/<module>/__init__.py` across the known Python search paths.
46
- * Returns the first existing candidate, or `null`.
47
- */
48
- private resolveViaSearchPaths;
49
- /**
50
- * Check if a file is a valid Python file
51
- */
52
- isValidPythonFile(path: string): boolean;
53
- /**
54
- * Build dependency graph for modules
55
- */
56
- buildDependencyGraph(modules: ModuleInfo[]): Promise<Map<string, Set<string>>>;
57
- /**
58
- * Extract dependencies from Python source file
59
- */
60
- extractDependencies(filePath: string): Promise<string[]>;
61
- /**
62
- * Parse import statements from Python source code
63
- */
64
- parseDependenciesFromSource(source: string): string[];
65
- /**
66
- * Extract the top-level module name imported by a single (trimmed) source
67
- * line, or `null` when the line is a comment, blank, or not an import.
68
- */
69
- private extractImportedModule;
70
- /**
71
- * Detect circular dependencies
72
- */
73
- detectCircularDependencies(): string[][];
74
- /**
75
- * Get Python search paths
76
- */
77
- private getPythonSearchPaths;
78
- /**
79
- * Scan a directory path for Python modules
80
- */
81
- private scanPath;
82
- /**
83
- * Extract module name from file path
84
- */
85
- private extractModuleNameFromPath;
86
- /**
87
- * Get module version information
88
- */
89
- getModuleVersion(moduleName: string): Promise<string | undefined>;
90
- /**
91
- * Clear module cache
92
- */
93
- clearCache(): void;
94
- /**
95
- * Get cached module information
96
- */
97
- getCachedModule(moduleName: string): ModuleInfo | undefined;
98
- /**
99
- * Get dependency graph
100
- */
101
- getDependencyGraph(): Map<string, Set<string>>;
102
- }
103
- //# sourceMappingURL=discovery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmCH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,iBAAiB,CAAC,CAAkB;gBAEhC,OAAO,GAAE,gBAAqB;YAe5B,mBAAmB;IAQjC;;OAEG;IACG,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAsB/D;;OAEG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAkBnE;;;;OAIG;YACW,qBAAqB;IAoCnC;;;;OAIG;YACW,qBAAqB;IAwBnC;;OAEG;IACH,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAkBxC;;OAEG;IACG,oBAAoB,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAcpF;;OAEG;IACG,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAc9D;;OAEG;IACH,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;IAarD;;;OAGG;IACH,OAAO,CAAC,qBAAqB;IAc7B;;OAEG;IACH,0BAA0B,IAAI,MAAM,EAAE,EAAE;IAuCxC;;OAEG;YACW,oBAAoB;IAyClC;;OAEG;YACW,QAAQ;IA4BtB;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAejC;;OAEG;IACG,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA0BvE;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;OAEG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI3D;;OAEG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAG/C"}
@@ -1,380 +0,0 @@
1
- /**
2
- * Python Module Discovery System
3
- *
4
- * Handles module resolution, dependency detection, and file system operations
5
- * across different runtime environments
6
- */
7
- // import type { PythonImport } from '../types/index.js';
8
- import { fsUtils, processUtils, pathUtils } from '../utils/runtime.js';
9
- import { resolvePythonExecutable } from '../utils/python.js';
10
- import { getComponentLogger } from '../utils/logger.js';
11
- const log = getComponentLogger('Discovery');
12
- /**
13
- * Strict allow-list for Python module names.
14
- *
15
- * Module names are interpolated into a `python -c` source string, so anything
16
- * outside a conservative identifier-plus-dots shape (e.g. quotes, semicolons,
17
- * newlines, parentheses, whitespace) could break out of the intended
18
- * expression and inject arbitrary code into the interpreter. Reject those
19
- * before they ever reach the subprocess argv.
20
- */
21
- const SAFE_MODULE_NAME = /^[A-Za-z_][A-Za-z0-9_.]*$/;
22
- /**
23
- * Validate a Python module name against {@link SAFE_MODULE_NAME}.
24
- *
25
- * @throws {Error} if the name is empty or contains characters that could
26
- * escape the `python -c` expression it is interpolated into.
27
- */
28
- function assertSafeModuleName(moduleName) {
29
- if (typeof moduleName !== 'string' || !SAFE_MODULE_NAME.test(moduleName)) {
30
- throw new Error(`Unsafe Python module name rejected: ${JSON.stringify(moduleName)}. ` +
31
- 'Module names must match /^[A-Za-z_][A-Za-z0-9_.]*$/.');
32
- }
33
- }
34
- export class ModuleDiscovery {
35
- options;
36
- moduleCache = new Map();
37
- dependencyGraph = new Map();
38
- pythonExecPromise;
39
- constructor(options = {}) {
40
- this.options = {
41
- includeStdLib: false,
42
- excludePatterns: ['__pycache__', '*.pyc', '.git', '.svn'],
43
- ...options,
44
- // Avoid "no timeout by default" for subprocess discovery paths.
45
- timeoutMs: typeof options.timeoutMs === 'number' &&
46
- Number.isFinite(options.timeoutMs) &&
47
- options.timeoutMs > 0
48
- ? options.timeoutMs
49
- : 30000,
50
- };
51
- }
52
- async getPythonExecutable() {
53
- this.pythonExecPromise ??= resolvePythonExecutable({
54
- pythonPath: this.options.pythonPath,
55
- virtualEnv: this.options.virtualEnv,
56
- });
57
- return this.pythonExecPromise;
58
- }
59
- /**
60
- * Find Python modules from various sources
61
- */
62
- async findPythonModules(paths) {
63
- const modules = [];
64
- const seen = new Set();
65
- for (const path of paths) {
66
- try {
67
- const foundModules = await this.scanPath(path);
68
- for (const module of foundModules) {
69
- if (!seen.has(module.name)) {
70
- modules.push(module);
71
- seen.add(module.name);
72
- this.moduleCache.set(module.name, module);
73
- }
74
- }
75
- }
76
- catch (error) {
77
- log.warn('Failed to scan path', { path, error: String(error) });
78
- }
79
- }
80
- return modules;
81
- }
82
- /**
83
- * Resolve Python module path from module name
84
- */
85
- async resolvePythonPath(moduleName) {
86
- // Reject names that could break out of the `python -c` expression below.
87
- assertSafeModuleName(moduleName);
88
- // Check cache first
89
- const cached = this.moduleCache.get(moduleName);
90
- if (cached) {
91
- return cached.path;
92
- }
93
- // Try to resolve using Python's module finder, then fall back to a
94
- // filesystem search across the known Python paths.
95
- return ((await this.resolveViaInterpreter(moduleName)) ??
96
- (await this.resolveViaSearchPaths(moduleName)));
97
- }
98
- /**
99
- * Resolve a module path by asking the Python interpreter for `__file__`.
100
- * Caches and returns the resolved path, or `null` when the interpreter is
101
- * unavailable, reports a builtin, or fails.
102
- */
103
- async resolveViaInterpreter(moduleName) {
104
- if (!processUtils.isAvailable()) {
105
- return null;
106
- }
107
- try {
108
- const pythonPath = await this.getPythonExecutable();
109
- const result = await processUtils.exec(pythonPath, [
110
- '-c',
111
- `import ${moduleName}; print(${moduleName}.__file__ if hasattr(${moduleName}, '__file__') else '${moduleName}.__path__[0]' if hasattr(${moduleName}, '__path__') else 'builtin')`,
112
- ], { timeoutMs: this.options.timeoutMs });
113
- if (result.code === 0 && result.stdout.trim() !== 'builtin') {
114
- const modulePath = result.stdout.trim();
115
- // Cache the result
116
- this.moduleCache.set(moduleName, {
117
- name: moduleName,
118
- path: modulePath,
119
- isPackage: modulePath.endsWith('__init__.py'),
120
- dependencies: [],
121
- });
122
- return modulePath;
123
- }
124
- }
125
- catch (error) {
126
- log.warn('Failed to resolve module', { moduleName, error: String(error) });
127
- }
128
- return null;
129
- }
130
- /**
131
- * Fallback resolution: probe `<path>/<module>.py` and
132
- * `<path>/<module>/__init__.py` across the known Python search paths.
133
- * Returns the first existing candidate, or `null`.
134
- */
135
- async resolveViaSearchPaths(moduleName) {
136
- const searchPaths = await this.getPythonSearchPaths();
137
- for (const searchPath of searchPaths) {
138
- const candidates = [
139
- pathUtils.join(searchPath, `${moduleName}.py`),
140
- pathUtils.join(searchPath, moduleName, '__init__.py'),
141
- ];
142
- for (const candidate of candidates) {
143
- try {
144
- if (fsUtils.isAvailable()) {
145
- await fsUtils.readFile(candidate);
146
- return candidate; // File exists
147
- }
148
- }
149
- catch {
150
- // File doesn't exist, continue
151
- }
152
- }
153
- }
154
- return null;
155
- }
156
- /**
157
- * Check if a file is a valid Python file
158
- */
159
- isValidPythonFile(path) {
160
- if (!path.endsWith('.py')) {
161
- return false;
162
- }
163
- // Check against exclude patterns
164
- for (const pattern of this.options.excludePatterns ?? []) {
165
- if (pattern.startsWith('*') && path.endsWith(pattern.slice(1))) {
166
- return false;
167
- }
168
- if (path.includes(pattern)) {
169
- return false;
170
- }
171
- }
172
- return true;
173
- }
174
- /**
175
- * Build dependency graph for modules
176
- */
177
- async buildDependencyGraph(modules) {
178
- this.dependencyGraph.clear();
179
- for (const module of modules) {
180
- const dependencies = await this.extractDependencies(module.path);
181
- this.dependencyGraph.set(module.name, new Set(dependencies));
182
- // Update module info
183
- module.dependencies = dependencies;
184
- }
185
- return new Map(this.dependencyGraph);
186
- }
187
- /**
188
- * Extract dependencies from Python source file
189
- */
190
- async extractDependencies(filePath) {
191
- if (!fsUtils.isAvailable()) {
192
- return [];
193
- }
194
- try {
195
- const source = await fsUtils.readFile(filePath);
196
- return this.parseDependenciesFromSource(source);
197
- }
198
- catch (error) {
199
- log.warn('Failed to read file', { filePath, error: String(error) });
200
- return [];
201
- }
202
- }
203
- /**
204
- * Parse import statements from Python source code
205
- */
206
- parseDependenciesFromSource(source) {
207
- const dependencies = [];
208
- for (const line of source.split('\n')) {
209
- const moduleName = this.extractImportedModule(line.trim());
210
- if (moduleName) {
211
- dependencies.push(moduleName);
212
- }
213
- }
214
- return [...new Set(dependencies)]; // Remove duplicates
215
- }
216
- /**
217
- * Extract the top-level module name imported by a single (trimmed) source
218
- * line, or `null` when the line is a comment, blank, or not an import.
219
- */
220
- extractImportedModule(trimmed) {
221
- // Skip comments and empty lines
222
- if (trimmed.startsWith('#') || trimmed === '') {
223
- return null;
224
- }
225
- // Match `import x.y.z` and `from x.y.z import ...` statements.
226
- const match = trimmed.match(/^import\s+([a-zA-Z_][a-zA-Z0-9_\.]*)/) ??
227
- trimmed.match(/^from\s+([a-zA-Z_][a-zA-Z0-9_\.]*)\s+import/);
228
- return match?.[1]?.split('.')[0] ?? null; // Get top-level module
229
- }
230
- /**
231
- * Detect circular dependencies
232
- */
233
- detectCircularDependencies() {
234
- const cycles = [];
235
- const visited = new Set();
236
- const recursionStack = new Set();
237
- const dfs = (module, path) => {
238
- if (recursionStack.has(module)) {
239
- // Found cycle
240
- const cycleStart = path.indexOf(module);
241
- cycles.push([...path.slice(cycleStart), module]);
242
- return;
243
- }
244
- if (visited.has(module)) {
245
- return;
246
- }
247
- visited.add(module);
248
- recursionStack.add(module);
249
- const dependencies = this.dependencyGraph.get(module);
250
- if (dependencies) {
251
- for (const dep of dependencies) {
252
- dfs(dep, [...path, module]);
253
- }
254
- }
255
- recursionStack.delete(module);
256
- };
257
- for (const module of this.dependencyGraph.keys()) {
258
- if (!visited.has(module)) {
259
- dfs(module, []);
260
- }
261
- }
262
- return cycles;
263
- }
264
- /**
265
- * Get Python search paths
266
- */
267
- async getPythonSearchPaths() {
268
- const paths = [];
269
- // Add explicit search paths
270
- if (this.options.searchPaths) {
271
- paths.push(...this.options.searchPaths);
272
- }
273
- // Add virtual environment paths
274
- if (this.options.virtualEnv) {
275
- paths.push(pathUtils.join(this.options.virtualEnv, 'lib', 'python*', 'site-packages'), pathUtils.join(this.options.virtualEnv, 'Lib', 'site-packages') // Windows
276
- );
277
- }
278
- // Get Python's sys.path if available
279
- if (processUtils.isAvailable()) {
280
- try {
281
- const pythonPath = await this.getPythonExecutable();
282
- const result = await processUtils.exec(pythonPath, ['-c', 'import sys; print("\\n".join(sys.path))'], { timeoutMs: this.options.timeoutMs });
283
- if (result.code === 0) {
284
- const sysPaths = result.stdout
285
- .trim()
286
- .split('\n')
287
- .filter(p => p.trim());
288
- paths.push(...sysPaths);
289
- }
290
- }
291
- catch (error) {
292
- log.warn('Failed to get Python sys.path', { error: String(error) });
293
- }
294
- }
295
- return [...new Set(paths)]; // Remove duplicates
296
- }
297
- /**
298
- * Scan a directory path for Python modules
299
- */
300
- async scanPath(path) {
301
- const modules = [];
302
- if (!fsUtils.isAvailable()) {
303
- return modules;
304
- }
305
- try {
306
- // For now, just create a stub - full directory scanning would need more complex logic
307
- if (this.isValidPythonFile(path)) {
308
- // Single file
309
- const moduleName = this.extractModuleNameFromPath(path);
310
- const dependencies = await this.extractDependencies(path);
311
- modules.push({
312
- name: moduleName,
313
- path,
314
- isPackage: false,
315
- dependencies,
316
- });
317
- }
318
- }
319
- catch (error) {
320
- log.warn('Failed to scan path', { path, error: String(error) });
321
- }
322
- return modules;
323
- }
324
- /**
325
- * Extract module name from file path
326
- */
327
- extractModuleNameFromPath(path) {
328
- // Normalize backslashes to forward slashes for Windows compatibility
329
- const normalizedPath = path.replace(/\\/g, '/');
330
- const parts = normalizedPath.split('/');
331
- const filename = parts[parts.length - 1];
332
- if (filename === '__init__.py') {
333
- // Package module
334
- return parts[parts.length - 2] ?? 'unknown';
335
- }
336
- // Regular module
337
- return filename?.replace('.py', '') ?? 'unknown';
338
- }
339
- /**
340
- * Get module version information
341
- */
342
- async getModuleVersion(moduleName) {
343
- // Reject names that could break out of the `python -c` expression below.
344
- assertSafeModuleName(moduleName);
345
- if (!processUtils.isAvailable()) {
346
- return undefined;
347
- }
348
- try {
349
- const pythonPath = await this.getPythonExecutable();
350
- const result = await processUtils.exec(pythonPath, ['-c', `import ${moduleName}; print(getattr(${moduleName}, '__version__', 'unknown'))`], { timeoutMs: this.options.timeoutMs });
351
- if (result.code === 0 && result.stdout.trim() !== 'unknown') {
352
- return result.stdout.trim();
353
- }
354
- }
355
- catch (error) {
356
- log.warn('Failed to get module version', { moduleName, error: String(error) });
357
- }
358
- return undefined;
359
- }
360
- /**
361
- * Clear module cache
362
- */
363
- clearCache() {
364
- this.moduleCache.clear();
365
- this.dependencyGraph.clear();
366
- }
367
- /**
368
- * Get cached module information
369
- */
370
- getCachedModule(moduleName) {
371
- return this.moduleCache.get(moduleName);
372
- }
373
- /**
374
- * Get dependency graph
375
- */
376
- getDependencyGraph() {
377
- return new Map(this.dependencyGraph);
378
- }
379
- }
380
- //# sourceMappingURL=discovery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../../src/core/discovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yDAAyD;AACzD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,GAAG,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AAErD;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,UAAkB;IAC9C,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,KAAK,CACb,uCAAuC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI;YACnE,sDAAsD,CACzD,CAAC;IACJ,CAAC;AACH,CAAC;AAmBD,MAAM,OAAO,eAAe;IAClB,OAAO,CAAmB;IAC1B,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC5C,eAAe,GAAG,IAAI,GAAG,EAAuB,CAAC;IACjD,iBAAiB,CAAmB;IAE5C,Y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C;IAC/B,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,UAAkB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -1,102 +0,0 @@
1
- /**
2
- * Error Handling & Validation Framework
3
- *
4
- * Comprehensive error handling, syntax validation, and analysis reporting system
5
- */
6
- import type { AnalysisError, AnalysisWarning, PythonFunction, PythonClass, PythonType } from '../types/index.js';
7
- export interface ValidationConfig {
8
- strictTypeChecking: boolean;
9
- allowMissingTypeHints: boolean;
10
- maxComplexityScore: number;
11
- deprecatedPatterns: string[];
12
- requiredDocstrings: boolean;
13
- }
14
- export interface ValidationReport {
15
- errors: AnalysisError[];
16
- warnings: AnalysisWarning[];
17
- statistics: ValidationStatistics;
18
- recommendations: ValidationRecommendation[];
19
- }
20
- export interface ValidationStatistics {
21
- totalIssues: number;
22
- errorCount: number;
23
- warningCount: number;
24
- typeHintCoverage: number;
25
- docstringCoverage: number;
26
- complexityScore: number;
27
- qualityScore: number;
28
- }
29
- export interface ValidationRecommendation {
30
- type: 'performance' | 'maintainability' | 'type-safety' | 'documentation';
31
- severity: 'low' | 'medium' | 'high' | 'critical';
32
- message: string;
33
- suggestion: string;
34
- file?: string;
35
- line?: number;
36
- impact: string;
37
- }
38
- export declare class ValidationEngine {
39
- private config;
40
- constructor(config?: Partial<ValidationConfig>);
41
- /**
42
- * Validate Python functions for type safety and best practices
43
- */
44
- validateFunction(func: PythonFunction, filePath?: string): ValidationReport;
45
- /**
46
- * Validate Python classes for structure and best practices
47
- */
48
- validateClass(cls: PythonClass, filePath?: string): ValidationReport;
49
- /**
50
- * Validate type annotations for correctness
51
- */
52
- validateTypeAnnotation(type: PythonType, context?: string): AnalysisError[];
53
- /**
54
- * Generate comprehensive analysis report
55
- */
56
- generateReport(functions: PythonFunction[], classes: PythonClass[], filePath?: string): ValidationReport;
57
- /**
58
- * Private validation methods
59
- */
60
- private validateTypeHints;
61
- /**
62
- * Emit a missing-type warning, and—in strict mode—an accompanying error.
63
- * In strict mode without allowMissingTypeHints, we warn first then error.
64
- */
65
- private reportMissingType;
66
- /**
67
- * Check the function return type annotation (skip __init__ methods as they
68
- * conventionally don't need return type annotations).
69
- */
70
- private checkReturnTypeHint;
71
- /**
72
- * Check a single parameter's type annotation (skip 'self' and 'cls').
73
- */
74
- private checkParameterTypeHint;
75
- /**
76
- * Validate a single parameter's type structure only in strict mode
77
- * (skip 'self' and 'cls' parameters).
78
- */
79
- private checkParameterTypeStructure;
80
- /**
81
- * Validate the return type structure only in strict mode.
82
- */
83
- private checkReturnTypeStructure;
84
- private validateDocstring;
85
- private validateParameters;
86
- private validateDeprecatedPatterns;
87
- private validateComplexity;
88
- private validateClassStructure;
89
- private validateInheritance;
90
- private validateTypeStructure;
91
- private isEmptyType;
92
- private generateFunctionRecommendations;
93
- private generateModuleRecommendations;
94
- private calculateFunctionStatistics;
95
- private calculateClassStatistics;
96
- private calculateModuleStatistics;
97
- private calculateComplexity;
98
- private calculateQualityScore;
99
- private calculateClassQualityScore;
100
- private calculateModuleQualityScore;
101
- }
102
- //# sourceMappingURL=validation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAEf,cAAc,EACd,WAAW,EACX,UAAU,EACX,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,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