@opensip-cli/lang-python 0.1.8 → 0.1.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.
package/README.md CHANGED
@@ -23,8 +23,8 @@ This package is published for the CLI and advanced plugin authors; most users sh
23
23
  ## Documentation
24
24
 
25
25
  - 📚 Project docs: https://opensip.ai/docs/opensip-cli/
26
- - 🧭 Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.8/docs/public/70-reference/02-package-catalog.md
27
- - 📦 Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.8/packages/languages/lang-python
26
+ - 🧭 Package catalog (what every package does): https://github.com/opensip-ai/opensip-cli/blob/v0.1.10/docs/public/70-reference/02-package-catalog.md
27
+ - 📦 Source: https://github.com/opensip-ai/opensip-cli/tree/v0.1.10/packages/languages/lang-python
28
28
 
29
29
  ## License
30
30
 
@@ -1,8 +1,8 @@
1
1
  import { nameOf, walkNodes } from '@opensip-cli/tree-sitter';
2
2
  import { describe, expect, it } from 'vitest';
3
- import { findEnclosingFunction, getEnclosingFunctionName, isMethod } from '../enclosing.js';
3
+ import { findEnclosingFunction, getEnclosingFunctionName } from '../enclosing.js';
4
4
  import { parsePython } from '../parse.js';
5
- import { isFunction } from '../predicates.js';
5
+ import { isFunction, isMethod } from '../predicates.js';
6
6
  const SRC = [
7
7
  'class S:',
8
8
  ' def m(self):',
@@ -1 +1 @@
1
- {"version":3,"file":"enclosing.test.js","sourceRoot":"","sources":["../../src/__tests__/enclosing.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa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I,CAAC,qBAAqB,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=query.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/query.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { pythonAdapter } from '../adapter.js';
3
+ function parse(src) {
4
+ const tree = pythonAdapter.parse(src, 't.py');
5
+ if (!tree)
6
+ throw new Error('no tree');
7
+ return tree;
8
+ }
9
+ const q = pythonAdapter.query;
10
+ describe('pythonQuery (LanguageQueryAPI)', () => {
11
+ it('is wired onto the adapter', () => {
12
+ expect(pythonAdapter.query).toBeDefined();
13
+ });
14
+ it('findFunctions returns defs, methods, and anonymous lambdas', () => {
15
+ const tree = parse([
16
+ 'def top():',
17
+ ' pass',
18
+ 'class C:',
19
+ ' def m(self):',
20
+ ' f = lambda x: x',
21
+ '',
22
+ ].join('\n'));
23
+ const names = q.findFunctions(tree).map((f) => f.name);
24
+ expect(names).toContain('top');
25
+ expect(names).toContain('m');
26
+ expect(names).toContain(null); // lambda
27
+ });
28
+ it('findImports handles import, aliased import, from-import, and wildcard', () => {
29
+ const tree = parse([
30
+ 'import os.path',
31
+ 'import numpy as np',
32
+ 'from collections import OrderedDict, defaultdict',
33
+ 'from mod import *',
34
+ '',
35
+ ].join('\n'));
36
+ const imports = q.findImports(tree);
37
+ const bySpec = new Map(imports.map((i) => [i.specifier, i.names]));
38
+ expect(bySpec.get('os.path')).toEqual(['path']);
39
+ expect(bySpec.get('numpy')).toEqual(['numpy']);
40
+ expect(bySpec.get('collections')).toEqual(['OrderedDict', 'defaultdict']);
41
+ expect(bySpec.get('mod')).toEqual([]); // wildcard contributes no names
42
+ });
43
+ it('findCallsTo matches identifier and attribute call targets', () => {
44
+ const tree = parse(['def f():', ' foo()', ' obj.bar()', ''].join('\n'));
45
+ expect(q.findCallsTo(tree, 'foo').length).toBe(1);
46
+ expect(q.findCallsTo(tree, 'bar').length).toBe(1);
47
+ expect(q.findCallsTo(tree, 'absent').length).toBe(0);
48
+ });
49
+ it('findCallsTo ignores computed/subscript callees', () => {
50
+ const tree = parse(['def f():', ' handlers[0]()', ''].join('\n'));
51
+ expect(q.findCallsTo(tree, 'handlers').length).toBe(0);
52
+ });
53
+ it('findImports handles relative from-imports', () => {
54
+ const tree = parse(['from . import sibling', 'from .pkg import thing', ''].join('\n'));
55
+ const imports = q.findImports(tree);
56
+ // The relative-import marker is part of the specifier (faithful to source).
57
+ const rel = imports.find((i) => i.names.includes('sibling'));
58
+ expect(rel?.specifier).toBe('.');
59
+ const pkg = imports.find((i) => i.names.includes('thing'));
60
+ expect(pkg?.specifier).toBe('.pkg');
61
+ });
62
+ it('findStringLiterals returns values; getText/getLocation read nodes', () => {
63
+ const tree = parse(['def f():', ' s = "hello"', ''].join('\n'));
64
+ expect(q.findStringLiterals(tree).map((s) => s.value)).toContain('hello');
65
+ const fn = q.findFunctions(tree)[0];
66
+ expect(q.getText(tree, fn.node)).toContain('def f');
67
+ expect(q.getLocation(tree, fn.node).line).toBe(1);
68
+ });
69
+ });
70
+ //# sourceMappingURL=query.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.test.js","sourceRoot":"","sources":["../../src/__tests__/query.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,SAAS,KAAK,CAAC,GAAW;IACxB,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,IAAI,CAAC;AACd,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AI,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACpD,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/adapter.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type PythonTree } from './parse.js';
2
2
  import type { LanguageAdapter } from '@opensip-cli/core';
3
- export declare const pythonAdapter: LanguageAdapter<PythonTree>;
3
+ import type { Node } from '@opensip-cli/tree-sitter';
4
+ export declare const pythonAdapter: LanguageAdapter<PythonTree, Node>;
4
5
  /** Plugin contract — exported as the lang plugin's `adapters` array. */
5
- export declare const adapters: readonly [LanguageAdapter<import("@opensip-cli/tree-sitter").ParsedFile, unknown>];
6
+ export declare const adapters: readonly [LanguageAdapter<import("@opensip-cli/tree-sitter").ParsedFile, Node>];
6
7
  //# sourceMappingURL=adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,UAAU,CAOrD,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,QAAQ,oFAA2B,CAAC"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAI1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAErD,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,UAAU,EAAE,IAAI,CAQ3D,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,QAAQ,iFAA2B,CAAC"}
package/dist/adapter.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parsePython } from './parse.js';
2
+ import { pythonQuery } from './query.js';
2
3
  import { stripComments, stripStrings } from './strip.js';
3
4
  export const pythonAdapter = {
4
5
  id: 'python',
@@ -7,6 +8,7 @@ export const pythonAdapter = {
7
8
  parse: parsePython,
8
9
  stripStrings,
9
10
  stripComments,
11
+ query: pythonQuery,
10
12
  };
11
13
  /** Plugin contract — exported as the lang plugin's `adapters` array. */
12
14
  export const adapters = [pythonAdapter];
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAIzD,MAAM,CAAC,MAAM,aAAa,GAAgC;IACxD,EAAE,EAAE,QAAQ;IACZ,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,WAAW;IAClB,YAAY;IACZ,aAAa;CACd,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,aAAa,CAAU,CAAC"}
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAKzD,MAAM,CAAC,MAAM,aAAa,GAAsC;IAC9D,EAAE,EAAE,QAAQ;IACZ,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,KAAK,EAAE,WAAW;IAClB,YAAY;IACZ,aAAa;IACb,KAAK,EAAE,WAAW;CACnB,CAAC;AAEF,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,aAAa,CAAU,CAAC"}
@@ -2,17 +2,12 @@
2
2
  * Composed enclosing-scope helpers for Python (ADR-0010) — the per-language
3
3
  * layer over the generic `findEnclosing`/`nameOf` from
4
4
  * `@opensip-cli/tree-sitter`. Mirrors `lang-typescript`'s
5
- * `findEnclosingFunction` / `getEnclosingFunctionName`.
5
+ * `findEnclosingFunction` / `getEnclosingFunctionName`. `isMethod` lives in
6
+ * predicates.ts (normalized in M10), alongside the other node-kind predicates.
6
7
  */
7
8
  import { type Node } from '@opensip-cli/tree-sitter';
8
9
  /** The nearest enclosing `def` of `node`, or `null` at module scope. */
9
10
  export declare function findEnclosingFunction(node: Node): Node | null;
10
11
  /** The name of the nearest enclosing `def`, or `null`. */
11
12
  export declare function getEnclosingFunctionName(node: Node): string | null;
12
- /**
13
- * True when `node` is a method — a `function_definition` whose *nearest*
14
- * enclosing function-or-class is a class. A function nested inside another
15
- * function is therefore not a method (its nearest enclosing scope is a `def`).
16
- */
17
- export declare function isMethod(node: Node): boolean;
18
13
  //# sourceMappingURL=enclosing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enclosing.d.ts","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAI5E,wEAAwE;AACxE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED,0DAA0D;AAC1D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAGlE;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAI5C"}
1
+ {"version":3,"file":"enclosing.d.ts","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAI5E,wEAAwE;AACxE,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAE7D;AAED,0DAA0D;AAC1D,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAGlE"}
package/dist/enclosing.js CHANGED
@@ -3,10 +3,11 @@
3
3
  * Composed enclosing-scope helpers for Python (ADR-0010) — the per-language
4
4
  * layer over the generic `findEnclosing`/`nameOf` from
5
5
  * `@opensip-cli/tree-sitter`. Mirrors `lang-typescript`'s
6
- * `findEnclosingFunction` / `getEnclosingFunctionName`.
6
+ * `findEnclosingFunction` / `getEnclosingFunctionName`. `isMethod` lives in
7
+ * predicates.ts (normalized in M10), alongside the other node-kind predicates.
7
8
  */
8
9
  import { findEnclosing, nameOf } from '@opensip-cli/tree-sitter';
9
- import { isClass, isFunction } from './predicates.js';
10
+ import { isFunction } from './predicates.js';
10
11
  /** The nearest enclosing `def` of `node`, or `null` at module scope. */
11
12
  export function findEnclosingFunction(node) {
12
13
  return findEnclosing(node, isFunction);
@@ -16,15 +17,4 @@ export function getEnclosingFunctionName(node) {
16
17
  const fn = findEnclosingFunction(node);
17
18
  return fn ? nameOf(fn) : null;
18
19
  }
19
- /**
20
- * True when `node` is a method — a `function_definition` whose *nearest*
21
- * enclosing function-or-class is a class. A function nested inside another
22
- * function is therefore not a method (its nearest enclosing scope is a `def`).
23
- */
24
- export function isMethod(node) {
25
- if (!isFunction(node))
26
- return false;
27
- const enclosing = findEnclosing(node, (n) => isFunction(n) || isClass(n));
28
- return enclosing !== null && isClass(enclosing);
29
- }
30
20
  //# sourceMappingURL=enclosing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"enclosing.js","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAa,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEtD,wEAAwE;AACxE,MAAM,UAAU,qBAAqB,CAAC,IAAU;IAC9C,OAAO,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,wBAAwB,CAAC,IAAU;IACjD,MAAM,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC"}
1
+ {"version":3,"file":"enclosing.js","sourceRoot":"","sources":["../src/enclosing.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAa,MAAM,0BAA0B,CAAC;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,wEAAwE;AACxE,MAAM,UAAU,qBAAqB,CAAC,IAAU;IAC9C,OAAO,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AACzC,CAAC;AAED,0DAA0D;AAC1D,MAAM,UAAU,wBAAwB,CAAC,IAAU;IACjD,MAAM,EAAE,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAChC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -2,7 +2,8 @@ export { pythonAdapter, adapters } from './adapter.js';
2
2
  export { parsePython, type PythonTree } from './parse.js';
3
3
  export { getSharedTree } from './shared-tree.js';
4
4
  export { stripStrings, stripComments } from './strip.js';
5
- export { isFunction, isClass, isComment, isString, isExcept, isConditional, isLoop, } from './predicates.js';
6
- export { findEnclosingFunction, getEnclosingFunctionName, isMethod } from './enclosing.js';
5
+ export { pythonQuery } from './query.js';
6
+ export { isFunction, isMethod, isClass, isComment, isString, isExcept, isConditional, isLoop, } from './predicates.js';
7
+ export { findEnclosingFunction, getEnclosingFunctionName } from './enclosing.js';
7
8
  export { childrenOf, findEnclosing, getColumn, getLineNumber, nameOf, namedChildrenOf, nodeText, walkNodes, type Node, } from '@opensip-cli/tree-sitter';
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,UAAU,EACV,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO3F,OAAO,EACL,UAAU,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,MAAM,EACN,eAAe,EACf,QAAQ,EACR,SAAS,EACT,KAAK,IAAI,GACV,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAOjF,OAAO,EACL,UAAU,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,MAAM,EACN,eAAe,EACf,QAAQ,EACR,SAAS,EACT,KAAK,IAAI,GACV,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -2,8 +2,9 @@ export { pythonAdapter, adapters } from './adapter.js';
2
2
  export { parsePython } from './parse.js';
3
3
  export { getSharedTree } from './shared-tree.js';
4
4
  export { stripStrings, stripComments } from './strip.js';
5
- export { isFunction, isClass, isComment, isString, isExcept, isConditional, isLoop, } from './predicates.js';
6
- export { findEnclosingFunction, getEnclosingFunctionName, isMethod } from './enclosing.js';
5
+ export { pythonQuery } from './query.js';
6
+ export { isFunction, isMethod, isClass, isComment, isString, isExcept, isConditional, isLoop, } from './predicates.js';
7
+ export { findEnclosingFunction, getEnclosingFunctionName } from './enclosing.js';
7
8
  // Generic tree-sitter traversal/position vocabulary, re-exported so check
8
9
  // packs reach the parser substrate THROUGH the language adapter (ADR-0039):
9
10
  // the adapter owns the parser boundary; check packs depend on lang-python +
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EACL,UAAU,EACV,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE3F,0EAA0E;AAC1E,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,uBAAuB;AACvB,OAAO,EACL,UAAU,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,MAAM,EACN,eAAe,EACf,QAAQ,EACR,SAAS,GAEV,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAmB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,MAAM,GACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAEjF,0EAA0E;AAC1E,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,uBAAuB;AACvB,OAAO,EACL,UAAU,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,MAAM,EACN,eAAe,EACf,QAAQ,EACR,SAAS,GAEV,MAAM,0BAA0B,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * grammar-specific node `type` strings differ per language, and they live here.
5
5
  * Node types are from the tree-sitter-python grammar.
6
6
  */
7
- import type { Node } from '@opensip-cli/tree-sitter';
7
+ import { type Node } from '@opensip-cli/tree-sitter';
8
8
  /** A `def` — both top-level functions and methods are `function_definition`. */
9
9
  export declare const isFunction: (node: Node) => boolean;
10
10
  /** A `class` declaration. */
@@ -19,4 +19,12 @@ export declare const isExcept: (node: Node) => boolean;
19
19
  export declare const isConditional: (node: Node) => boolean;
20
20
  /** A `for` or `while` loop. */
21
21
  export declare const isLoop: (node: Node) => boolean;
22
+ /**
23
+ * True when `node` is a method — a `function_definition` whose *nearest*
24
+ * enclosing function-or-class is a class. A function nested inside another
25
+ * function is therefore not a method (its nearest enclosing scope is a `def`).
26
+ * Normalized into predicates.ts (M10): `isMethod` lives in predicates.ts in
27
+ * every tree-sitter adapter.
28
+ */
29
+ export declare const isMethod: (node: Node) => boolean;
22
30
  //# sourceMappingURL=predicates.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MA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,KAAG,OAC8B,CAAC;AAEnE;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,KAAG,OAIrC,CAAC"}
@@ -5,6 +5,7 @@
5
5
  * grammar-specific node `type` strings differ per language, and they live here.
6
6
  * Node types are from the tree-sitter-python grammar.
7
7
  */
8
+ import { findEnclosing } from '@opensip-cli/tree-sitter';
8
9
  /** A `def` — both top-level functions and methods are `function_definition`. */
9
10
  export const isFunction = (node) => node.type === 'function_definition';
10
11
  /** A `class` declaration. */
@@ -19,4 +20,17 @@ export const isExcept = (node) => node.type === 'except_clause';
19
20
  export const isConditional = (node) => node.type === 'if_statement';
20
21
  /** A `for` or `while` loop. */
21
22
  export const isLoop = (node) => node.type === 'for_statement' || node.type === 'while_statement';
23
+ /**
24
+ * True when `node` is a method — a `function_definition` whose *nearest*
25
+ * enclosing function-or-class is a class. A function nested inside another
26
+ * function is therefore not a method (its nearest enclosing scope is a `def`).
27
+ * Normalized into predicates.ts (M10): `isMethod` lives in predicates.ts in
28
+ * every tree-sitter adapter.
29
+ */
30
+ export const isMethod = (node) => {
31
+ if (!isFunction(node))
32
+ return false;
33
+ const enclosing = findEnclosing(node, (n) => isFunction(n) || isClass(n));
34
+ return enclosing !== null && isClass(enclosing);
35
+ };
22
36
  //# sourceMappingURL=predicates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA,gPAAgP;AAChP;;;;;GAKG;AAIH,gFAAgF;AAChF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,qBAAqB,CAAC;AAEvF,6BAA6B;AAC7B,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC;AAEjF,qBAAqB;AACrB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAA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,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC;AAE/E,yBAAyB;AACzB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC;AAEnF,+BAA+B;AAC/B,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAU,EAAW,EAAE,CAC5C,IAAI,CAAC,IAAI,KAAK,eAAe,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAiB,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAW,EAAE;IAC9C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACpC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Python {@link LanguageQueryAPI} (ADR-0010, M10) — the grammar config for the
3
+ * shared `createTreeSitterQuery` factory. Node types are from tree-sitter-python;
4
+ * the callee extractor mirrors `graph-python`'s resolver so the query agrees
5
+ * with the call graph.
6
+ */
7
+ import { type LanguageQueryAPI, type Node, type ParsedFile } from '@opensip-cli/tree-sitter';
8
+ export declare const pythonQuery: LanguageQueryAPI<ParsedFile, Node>;
9
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAEH,OAAO,EAIL,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,UAAU,EAChB,MAAM,0BAA0B,CAAC;AA6FlC,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAKzD,CAAC"}
package/dist/query.js ADDED
@@ -0,0 +1,107 @@
1
+ // @fitness-ignore-file duplicate-utility-functions -- ADR-0010/M10: the per-language tree-sitter query config intentionally shares helper names (callee/import/string extractors) across lang-* with grammar-specific implementations; consolidating would defeat the substrate design.
2
+ /**
3
+ * Python {@link LanguageQueryAPI} (ADR-0010, M10) — the grammar config for the
4
+ * shared `createTreeSitterQuery` factory. Node types are from tree-sitter-python;
5
+ * the callee extractor mirrors `graph-python`'s resolver so the query agrees
6
+ * with the call graph.
7
+ */
8
+ import { createTreeSitterQuery, namedChildrenOf, } from '@opensip-cli/tree-sitter';
9
+ /** Leaf callee name of a `call` node (`foo()` → `foo`, `o.m()` → `m`). */
10
+ function calleeName(node) {
11
+ const fn = node.childForFieldName('function');
12
+ /* v8 ignore next -- a `call` node always exposes its `function` field */
13
+ if (!fn)
14
+ return null;
15
+ if (fn.type === 'identifier')
16
+ return fn.text;
17
+ if (fn.type === 'attribute') {
18
+ const attr = fn.childForFieldName('attribute');
19
+ /* v8 ignore next -- an attribute node always exposes its `attribute` field */
20
+ return attr ? attr.text : null;
21
+ }
22
+ // Other callee shapes (subscript/computed) — unresolved by name.
23
+ return null;
24
+ }
25
+ /** The terminal segment of a dotted module path (`a.b.c` → `c`). */
26
+ function dottedLeaf(text) {
27
+ /* v8 ignore next -- split('.') on a non-empty path always yields a segment */
28
+ return text.split('.').pop() ?? text;
29
+ }
30
+ /** Resolve a name-bearing import item (identifier / dotted_name / aliased_import). */
31
+ function importItemName(node) {
32
+ if (node.type === 'identifier')
33
+ return node.text;
34
+ if (node.type === 'dotted_name')
35
+ return dottedLeaf(node.text);
36
+ if (node.type === 'aliased_import') {
37
+ // `<path> as <alias>` — keep the underlying leaf name (alias dropped).
38
+ const inner = node.childForFieldName('name') ?? node.namedChild(0);
39
+ /* v8 ignore next -- an aliased_import always wraps a name node */
40
+ return inner ? importItemName(inner) : null;
41
+ }
42
+ // Non-name children (e.g. comments inside a parenthesized import list).
43
+ return null;
44
+ }
45
+ /**
46
+ * Expand a Python import statement into import targets.
47
+ * - `import a.b.c` → specifier `a.b.c`, names `[c]`
48
+ * - `import a.b as x` → specifier `a.b`, names `[b]`
49
+ * - `from m import x, y` → specifier `m`, names `[x, y]`
50
+ * - `from m import *` → specifier `m`, names `[]`
51
+ */
52
+ /** The path text of an import item — the LHS path of an `aliased_import`. */
53
+ function importItemSpecifier(item) {
54
+ if (item.type === 'aliased_import') {
55
+ const inner = item.childForFieldName('name') ?? item.namedChild(0);
56
+ /* v8 ignore next -- an aliased_import always wraps a path node */
57
+ return inner ? inner.text : item.text;
58
+ }
59
+ return item.text;
60
+ }
61
+ function extractImport(node) {
62
+ if (node.type === 'import_statement') {
63
+ const out = [];
64
+ for (const item of namedChildrenOf(node)) {
65
+ const specifier = importItemSpecifier(item);
66
+ const name = importItemName(item);
67
+ out.push({ specifier, names: name ? [name] : [] });
68
+ }
69
+ return out;
70
+ }
71
+ // import_from_statement (the only other configured import node type).
72
+ const moduleNode = node.childForFieldName('module_name');
73
+ /* v8 ignore next -- a from-import always has a module_name (`.` for relatives) */
74
+ const specifier = moduleNode ? moduleNode.text : '';
75
+ const names = [];
76
+ // Imported names are the name-bearing children other than the module
77
+ // itself. A bare `*` (`wildcard_import`) contributes no names.
78
+ for (const child of namedChildrenOf(node)) {
79
+ if (child.startIndex === moduleNode?.startIndex)
80
+ continue;
81
+ if (child.type === 'wildcard_import')
82
+ continue;
83
+ const name = importItemName(child);
84
+ if (name)
85
+ names.push(name);
86
+ }
87
+ return [{ specifier, names }];
88
+ }
89
+ const FUNCTION_NODE_TYPES = new Set(['function_definition', 'lambda']);
90
+ const CALL_NODE_TYPES = new Set(['call']);
91
+ const IMPORT_NODE_TYPES = new Set(['import_statement', 'import_from_statement']);
92
+ const STRING_NODE_TYPES = new Set(['string']);
93
+ /** A `lambda` has no name field — keep `findFunctions` faithful (null). */
94
+ function pythonFunctionName(node) {
95
+ if (node.type === 'lambda')
96
+ return null;
97
+ const name = node.childForFieldName('name');
98
+ /* v8 ignore next -- a function_definition always exposes its name field */
99
+ return name ? name.text : null;
100
+ }
101
+ export const pythonQuery = createTreeSitterQuery({
102
+ functions: { nodeTypes: FUNCTION_NODE_TYPES, nameOf: pythonFunctionName },
103
+ calls: { nodeTypes: CALL_NODE_TYPES, calleeName },
104
+ imports: { nodeTypes: IMPORT_NODE_TYPES, extract: extractImport },
105
+ strings: { nodeTypes: STRING_NODE_TYPES },
106
+ });
107
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,wRAAwR;AACxR;;;;;GAKG;AAEH,OAAO,EACL,qBAAqB,EACrB,eAAe,GAKhB,MAAM,0BAA0B,CAAC;AAElC,0EAA0E;AAC1E,SAAS,UAAU,CAAC,IAAU;IAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAC9C,yEAAyE;IACzE,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC;IACrB,IAAI,EAAE,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,EAAE,CAAC,IAAI,CAAC;IAC7C,IAAI,EAAE,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QAC/C,8EAA8E;QAC9E,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,iEAAiE;IACjE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,oEAAoE;AACpE,SAAS,UAAU,CAAC,IAAY;IAC9B,8EAA8E;IAC9E,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC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QAAQ,CAAC,CAAC,CAAC;AAE9C,2EAA2E;AAC3E,SAAS,kBAAkB,CAAC,IAAU;IACpC,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC5C,2EAA2E;IAC3E,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAuC,qBAAqB,CAAC;IACnF,SAAS,EAAE,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,EAAE,kBAAkB,EAAE;IACzE,KAAK,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE;IACjD,OAAO,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE,OAAO,EAAE,aAAa,EAAE;IACjE,OAAO,EAAE,EAAE,SAAS,EAAE,iBAAiB,EAAE;CAC1C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opensip-cli/lang-python",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Python language adapter for opensip-cli",
6
6
  "keywords": [
@@ -34,8 +34,8 @@
34
34
  "NOTICE"
35
35
  ],
36
36
  "dependencies": {
37
- "@opensip-cli/core": "0.1.8",
38
- "@opensip-cli/tree-sitter": "0.1.8"
37
+ "@opensip-cli/core": "0.1.10",
38
+ "@opensip-cli/tree-sitter": "0.1.10"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^24.13.2",