@alloy-js/python 0.3.0-dev.4 → 0.3.0-dev.6
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/dist/src/components/CallSignature.d.ts +6 -4
- package/dist/src/components/CallSignature.d.ts.map +1 -1
- package/dist/src/components/CallSignature.js +23 -26
- package/dist/src/components/CallSignature.js.map +1 -1
- package/dist/src/components/FutureStatement.d.ts +35 -0
- package/dist/src/components/FutureStatement.d.ts.map +1 -0
- package/dist/src/components/FutureStatement.js +31 -0
- package/dist/src/components/FutureStatement.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +8 -2
- package/dist/src/components/SourceFile.d.ts.map +1 -1
- package/dist/src/components/SourceFile.js +124 -8
- package/dist/src/components/SourceFile.js.map +1 -1
- package/dist/src/components/index.d.ts +1 -0
- package/dist/src/components/index.d.ts.map +1 -1
- package/dist/src/components/index.js +1 -0
- package/dist/src/components/index.js.map +1 -1
- package/dist/test/callsignatures.test.js +127 -0
- package/dist/test/callsignatures.test.js.map +1 -1
- package/dist/test/classdeclarations.test.js +2 -0
- package/dist/test/classdeclarations.test.js.map +1 -1
- package/dist/test/dataclassdeclarations.test.js +13 -0
- package/dist/test/dataclassdeclarations.test.js.map +1 -1
- package/dist/test/enums.test.js +7 -0
- package/dist/test/enums.test.js.map +1 -1
- package/dist/test/externals.test.js +2 -0
- package/dist/test/externals.test.js.map +1 -1
- package/dist/test/functiondeclaration.test.js +2 -0
- package/dist/test/functiondeclaration.test.js.map +1 -1
- package/dist/test/methoddeclaration.test.js +1 -0
- package/dist/test/methoddeclaration.test.js.map +1 -1
- package/dist/test/namepolicies.test.js +1 -0
- package/dist/test/namepolicies.test.js.map +1 -1
- package/dist/test/propertydeclaration.test.js +1 -0
- package/dist/test/propertydeclaration.test.js.map +1 -1
- package/dist/test/pydocs.test.js +1 -1
- package/dist/test/pydocs.test.js.map +1 -1
- package/dist/test/sourcefiles.test.js +921 -39
- package/dist/test/sourcefiles.test.js.map +1 -1
- package/dist/test/utils.d.ts +2 -2
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +9 -9
- package/dist/test/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/components/CallSignature.tsx +41 -36
- package/src/components/FutureStatement.tsx +38 -0
- package/src/components/SourceFile.tsx +128 -8
- package/src/components/index.ts +1 -0
- package/temp/api.json +169 -5
- package/test/callsignatures.test.tsx +110 -0
- package/test/classdeclarations.test.tsx +2 -0
- package/test/dataclassdeclarations.test.tsx +13 -0
- package/test/enums.test.tsx +7 -0
- package/test/externals.test.tsx +2 -0
- package/test/functiondeclaration.test.tsx +2 -0
- package/test/methoddeclaration.test.tsx +1 -0
- package/test/namepolicies.test.tsx +1 -0
- package/test/propertydeclaration.test.tsx +1 -0
- package/test/pydocs.test.tsx +1 -1
- package/test/sourcefiles.test.tsx +754 -48
- package/test/utils.tsx +10 -5
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Children } from "@alloy-js/core";
|
|
2
2
|
import { ParameterDescriptor } from "../parameter-descriptor.js";
|
|
3
|
+
export type ParameterMarker = "*" | "/";
|
|
3
4
|
export interface CallSignatureParametersProps {
|
|
4
|
-
readonly parameters?: (ParameterDescriptor | string)[];
|
|
5
|
+
readonly parameters?: (ParameterDescriptor | ParameterMarker | string)[];
|
|
5
6
|
readonly args?: boolean;
|
|
6
7
|
readonly kwargs?: boolean;
|
|
7
8
|
}
|
|
@@ -21,10 +22,11 @@ export interface CallSignatureParametersProps {
|
|
|
21
22
|
export declare function CallSignatureParameters(props: CallSignatureParametersProps): Children;
|
|
22
23
|
export interface CallSignatureProps {
|
|
23
24
|
/**
|
|
24
|
-
* The parameters to the call signature. Can be an array of strings (for
|
|
25
|
-
*
|
|
25
|
+
* The parameters to the call signature. Can be an array of strings (for simple
|
|
26
|
+
* parameter names), {@link ParameterDescriptor}s, or special markers ("*" for
|
|
27
|
+
* keyword-only, "/" for positional-only).
|
|
26
28
|
*/
|
|
27
|
-
parameters?: (ParameterDescriptor | string)[];
|
|
29
|
+
parameters?: (ParameterDescriptor | ParameterMarker | string)[];
|
|
28
30
|
/**
|
|
29
31
|
* The type parameters of the call signature, e.g. for a generic function.
|
|
30
32
|
* This is only supported in Python 3.12+.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallSignature.d.ts","sourceRoot":"","sources":["../../../src/components/CallSignature.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAMT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,mBAAmB,GAAG,MAAM,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"CallSignature.d.ts","sourceRoot":"","sources":["../../../src/components/CallSignature.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAMT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAKpC,MAAM,MAAM,eAAe,GAAG,GAAG,GAAG,GAAG,CAAC;AAQxC,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,mBAAmB,GAAG,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,YA0B1E;AAqDD,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,CAAC,mBAAmB,GAAG,eAAe,GAAG,MAAM,CAAC,EAAE,CAAC;IAEhE;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,QAAQ,CAAC;CACvB;AACD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,YAuBtD"}
|
|
@@ -3,6 +3,9 @@ import { computed, createSymbolSlot, For, Show } from "@alloy-js/core";
|
|
|
3
3
|
import { isParameterDescriptor } from "../parameter-descriptor.js";
|
|
4
4
|
import { createPythonSymbol } from "../symbol-creation.js";
|
|
5
5
|
import { Atom } from "./Atom.js";
|
|
6
|
+
function isParameterMarker(param) {
|
|
7
|
+
return typeof param === "string" && (param === "*" || param === "/");
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
10
|
* A call signature parameters declaration, which can be used to define the
|
|
8
11
|
* parameters of a function or other callables.
|
|
@@ -17,12 +20,9 @@ import { Atom } from "./Atom.js";
|
|
|
17
20
|
* ```
|
|
18
21
|
*/
|
|
19
22
|
export function CallSignatureParameters(props) {
|
|
20
|
-
const parameters = normalizeAndDeclareParameters(props.parameters ?? []);
|
|
21
23
|
const parameterList = computed(() => {
|
|
22
|
-
const params = []
|
|
23
|
-
|
|
24
|
-
parameters.forEach(param => {
|
|
25
|
-
params.push(parameter(param));
|
|
24
|
+
const params = (props.parameters ?? []).map(p => {
|
|
25
|
+
return isParameterMarker(p) ? p : parameter(normalizeAndDeclareParameter(p));
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
// Add *args if specified
|
|
@@ -83,27 +83,24 @@ function parameter(param) {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
});
|
|
86
|
+
function normalizeAndDeclareParameter(param) {
|
|
87
|
+
if (isParameterDescriptor(param)) {
|
|
88
|
+
const TypeSlot = createSymbolSlot();
|
|
89
|
+
const symbol = createPythonSymbol(param.name, {
|
|
90
|
+
refkeys: param.refkey,
|
|
91
|
+
type: TypeSlot.firstSymbol
|
|
92
|
+
}, "parameter");
|
|
93
|
+
return {
|
|
94
|
+
...param,
|
|
95
|
+
symbol,
|
|
96
|
+
TypeSlot
|
|
97
|
+
};
|
|
98
|
+
} else {
|
|
99
|
+
const symbol = createPythonSymbol(param, {}, "parameter");
|
|
100
|
+
return {
|
|
101
|
+
symbol
|
|
102
|
+
};
|
|
103
|
+
}
|
|
107
104
|
}
|
|
108
105
|
/**
|
|
109
106
|
* A Python call signature, e.g. the part after the `def` keyword and the name in a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["computed","createSymbolSlot","For","Show","isParameterDescriptor","createPythonSymbol","Atom","
|
|
1
|
+
{"version":3,"names":["computed","createSymbolSlot","For","Show","isParameterDescriptor","createPythonSymbol","Atom","isParameterMarker","param","CallSignatureParameters","props","parameterList","params","parameters","map","p","parameter","normalizeAndDeclareParameter","args","push","kwargs","_$createComponent","each","comma","space","children","TypeSlot","_$createIntrinsic","_$memo","symbol","name","when","type","default","undefined","jsValue","refkeys","refkey","firstSymbol","CallSignature","sParams","typeParams","typeParameters","join","sReturnType","returnType"],"sources":["../../../src/components/CallSignature.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAEEA,QAAQ,EACRC,gBAAgB,EAChBC,GAAG,EACHC,IAAI,QAEC,gBAAgB;AACvB,SACEC,qBAAqB,QAEhB,4BAA4B;AACnC,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,SAASC,IAAI;AAIb,SAASC,iBAAiB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AAyB,EAAE;EACvD,MAAM8B,OAAO,GAAAnB,iBAAA,CACVZ,uBAAuB;IAAA,IACtBI,UAAUA,CAAA;MAAA,OAAEH,KAAK,CAACG,UAAU;IAAA;IAAA,IAC5BK,IAAIA,CAAA;MAAA,OAAER,KAAK,CAACQ,IAAI;IAAA;IAAA,IAChBE,MAAMA,CAAA;MAAA,OAAEV,KAAK,CAACU,MAAM;IAAA;EAAA,EAEvB;EACD,MAAMqB,UAAU,GACd/B,KAAK,CAACgC,cAAc,GAAG,IAAIhC,KAAK,CAACgC,cAAc,CAACC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE;EACpE,MAAMC,WAAW,GACflC,KAAK,CAACmC,UAAU,IAEX,MAAM,EAAAjB,MAAA,OACNlB,KAAK,CAACmC,UAAU,KAEnBX,SAAS;EAEb,QAEKO,UAAU,OAAGD,OAAO,OAAGI,WAAW;AAGzC","ignoreList":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Children } from "@alloy-js/core";
|
|
2
|
+
export interface FutureStatementProps {
|
|
3
|
+
/**
|
|
4
|
+
* The name of the feature to import from __future__.
|
|
5
|
+
*/
|
|
6
|
+
feature: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A future statement that imports features from __future__.
|
|
10
|
+
*
|
|
11
|
+
* Future statements are directives to the compiler that a particular module
|
|
12
|
+
* should be compiled using syntax or semantics from a future Python release.
|
|
13
|
+
* They must appear near the top of the module, after the module docstring (if any).
|
|
14
|
+
*
|
|
15
|
+
* Use this in the `futureImports` prop of SourceFile to ensure proper placement.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <SourceFile path="models.py" futureImports={<FutureStatement feature="annotations" />}>
|
|
20
|
+
* <ClassDeclaration name="User">
|
|
21
|
+
* <PropertyDeclaration name="manager" type="User" />
|
|
22
|
+
* </ClassDeclaration>
|
|
23
|
+
* </SourceFile>
|
|
24
|
+
* ```
|
|
25
|
+
* renders to
|
|
26
|
+
* ```py
|
|
27
|
+
* from __future__ import annotations
|
|
28
|
+
*
|
|
29
|
+
*
|
|
30
|
+
* class User:
|
|
31
|
+
* manager: User
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function FutureStatement(props: FutureStatementProps): Children;
|
|
35
|
+
//# sourceMappingURL=FutureStatement.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FutureStatement.d.ts","sourceRoot":"","sources":["../../../src/components/FutureStatement.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,QAAQ,CAErE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A future statement that imports features from __future__.
|
|
4
|
+
*
|
|
5
|
+
* Future statements are directives to the compiler that a particular module
|
|
6
|
+
* should be compiled using syntax or semantics from a future Python release.
|
|
7
|
+
* They must appear near the top of the module, after the module docstring (if any).
|
|
8
|
+
*
|
|
9
|
+
* Use this in the `futureImports` prop of SourceFile to ensure proper placement.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <SourceFile path="models.py" futureImports={<FutureStatement feature="annotations" />}>
|
|
14
|
+
* <ClassDeclaration name="User">
|
|
15
|
+
* <PropertyDeclaration name="manager" type="User" />
|
|
16
|
+
* </ClassDeclaration>
|
|
17
|
+
* </SourceFile>
|
|
18
|
+
* ```
|
|
19
|
+
* renders to
|
|
20
|
+
* ```py
|
|
21
|
+
* from __future__ import annotations
|
|
22
|
+
*
|
|
23
|
+
*
|
|
24
|
+
* class User:
|
|
25
|
+
* manager: User
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function FutureStatement(props) {
|
|
29
|
+
return ["from __future__ import ", _$memo(() => props.feature)];
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=FutureStatement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["FutureStatement","props","_$memo","feature"],"sources":["../../../src/components/FutureStatement.tsx"],"sourcesContent":[null],"mappings":";AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAACC,KAA2B,EAAY;EACrE,mCAAAC,MAAA,OAAiCD,KAAK,CAACE,OAAO;AAChD","ignoreList":[]}
|
|
@@ -17,17 +17,23 @@ export interface SourceFileProps {
|
|
|
17
17
|
*/
|
|
18
18
|
children?: Children;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
20
|
+
* Content to render at the very top of the file, before everything else.
|
|
21
|
+
* Use this for shebang lines, encoding declarations, or license headers.
|
|
21
22
|
*/
|
|
22
23
|
header?: Children;
|
|
23
24
|
/**
|
|
24
|
-
* Comment to add
|
|
25
|
+
* Comment to add at the top of the file, rendered as a Python comment block.
|
|
26
|
+
* This is a convenience prop for adding copyright notices or other comments.
|
|
25
27
|
*/
|
|
26
28
|
headerComment?: string;
|
|
27
29
|
/**
|
|
28
30
|
* Documentation for this module, which will be rendered as a module-level docstring.
|
|
29
31
|
*/
|
|
30
32
|
doc?: Children;
|
|
33
|
+
/**
|
|
34
|
+
* __future__ imports to render after the docstring but before regular imports.
|
|
35
|
+
*/
|
|
36
|
+
futureImports?: Children;
|
|
31
37
|
}
|
|
32
38
|
/**
|
|
33
39
|
* A Python source file component that represents a Python file in the source directory.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SourceFile.d.ts","sourceRoot":"","sources":["../../../src/components/SourceFile.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"SourceFile.d.ts","sourceRoot":"","sources":["../../../src/components/SourceFile.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAShB,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA+CxD,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,iBAAiB,CAAC;IACzB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,uBAAuB,EAAE,gBAAgB,CAAC,uBAAuB,CAC3B,CAAC;AAEpD,wBAAgB,aAAa,4BAE5B;AAED,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;OAGG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,GAAG,CAAC,EAAE,QAAQ,CAAC;IACf;;OAEG;IACH,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,YAqGhD"}
|
|
@@ -1,9 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SourceFile as CoreSourceFile, createNamedContext, List, Scope, Show, SourceDirectoryContext, useContext } from "@alloy-js/core";
|
|
1
|
+
import { memo as _$memo, createIntrinsic as _$createIntrinsic, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { childrenArray, SourceFile as CoreSourceFile, createNamedContext, isComponentCreator, List, Scope, Show, SourceDirectoryContext, useContext } from "@alloy-js/core";
|
|
3
3
|
import { join } from "pathe";
|
|
4
4
|
import { PythonModuleScope } from "../symbols/index.js";
|
|
5
5
|
import { ImportStatements } from "./ImportStatement.js";
|
|
6
|
+
import { SimpleCommentBlock } from "./PyDoc.js";
|
|
6
7
|
import { Reference } from "./Reference.js";
|
|
8
|
+
|
|
9
|
+
// Non top-level definitions
|
|
10
|
+
const NON_DEFINITION_NAMES = new Set(["VariableDeclaration", "MemberExpression", "FunctionCallExpression", "ClassInstantiation", "Reference"]);
|
|
11
|
+
|
|
12
|
+
// Wrapper components that we should look inside to find the actual first child
|
|
13
|
+
const WRAPPER_COMPONENT_NAMES = new Set(["StatementList"]);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the first child is a top-level definition (function or class).
|
|
17
|
+
* PEP 8 requires 2 blank lines before top-level function and class definitions,
|
|
18
|
+
* but not before other statements like variable assignments.
|
|
19
|
+
*
|
|
20
|
+
* Returns true only if there are children and the first child is a definition.
|
|
21
|
+
*/
|
|
22
|
+
function firstChildIsDefinition(children) {
|
|
23
|
+
if (!children) return false;
|
|
24
|
+
const arr = childrenArray(() => children);
|
|
25
|
+
if (arr.length === 0) return false;
|
|
26
|
+
const first = arr[0];
|
|
27
|
+
|
|
28
|
+
// Non-component children (strings, numbers, refkeys, etc.) are not definitions
|
|
29
|
+
if (!isComponentCreator(first)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const name = first.component.name;
|
|
33
|
+
if (NON_DEFINITION_NAMES.has(name)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
// Look inside wrapper components
|
|
37
|
+
if (WRAPPER_COMPONENT_NAMES.has(name) && first.props?.children) {
|
|
38
|
+
return firstChildIsDefinition(first.props.children);
|
|
39
|
+
}
|
|
40
|
+
// If we get here, it's likely a definition (FunctionDeclaration, ClassDeclaration, etc.)
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
7
43
|
export const PythonSourceFileContext = createNamedContext("@alloy-js/python SourceFile");
|
|
8
44
|
export function useSourceFile() {
|
|
9
45
|
return useContext(PythonSourceFileContext);
|
|
@@ -55,14 +91,84 @@ export function SourceFile(props) {
|
|
|
55
91
|
scope: scope,
|
|
56
92
|
module: path
|
|
57
93
|
};
|
|
94
|
+
|
|
95
|
+
// Check if there are any children
|
|
96
|
+
const hasChildren = props.children !== undefined && childrenArray(() => props.children).length > 0;
|
|
97
|
+
|
|
98
|
+
// PEP 8 requires 2 blank lines before top-level function/class definitions
|
|
99
|
+
const needsExtraSpacing = firstChildIsDefinition(props.children);
|
|
100
|
+
|
|
101
|
+
// Check if there's any preamble content (header, doc, imports, etc.)
|
|
102
|
+
const hasPreamble = props.header !== undefined || props.headerComment !== undefined || props.doc !== undefined || props.futureImports !== undefined;
|
|
58
103
|
return _$createComponent(CoreSourceFile, {
|
|
59
104
|
get path() {
|
|
60
105
|
return props.path;
|
|
61
106
|
},
|
|
62
107
|
filetype: "py",
|
|
63
108
|
reference: Reference,
|
|
109
|
+
get header() {
|
|
110
|
+
return props.header;
|
|
111
|
+
},
|
|
64
112
|
get children() {
|
|
65
113
|
return [_$createComponent(Show, {
|
|
114
|
+
get when() {
|
|
115
|
+
return props.header !== undefined && props.headerComment === undefined && (props.doc !== undefined || props.futureImports !== undefined || hasChildren);
|
|
116
|
+
},
|
|
117
|
+
get children() {
|
|
118
|
+
return _$createIntrinsic("hbr", {});
|
|
119
|
+
}
|
|
120
|
+
}), _$createComponent(Show, {
|
|
121
|
+
get when() {
|
|
122
|
+
return props.headerComment !== undefined;
|
|
123
|
+
},
|
|
124
|
+
get children() {
|
|
125
|
+
return [_$createComponent(SimpleCommentBlock, {
|
|
126
|
+
get children() {
|
|
127
|
+
return props.headerComment;
|
|
128
|
+
}
|
|
129
|
+
}), _$createComponent(Show, {
|
|
130
|
+
get when() {
|
|
131
|
+
return props.doc !== undefined;
|
|
132
|
+
},
|
|
133
|
+
get children() {
|
|
134
|
+
return _$createIntrinsic("hbr", {});
|
|
135
|
+
}
|
|
136
|
+
}), _$createComponent(Show, {
|
|
137
|
+
get when() {
|
|
138
|
+
return props.doc === undefined && (props.futureImports !== undefined || hasChildren);
|
|
139
|
+
},
|
|
140
|
+
get children() {
|
|
141
|
+
return [_$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {})];
|
|
142
|
+
}
|
|
143
|
+
})];
|
|
144
|
+
}
|
|
145
|
+
}), _$createComponent(Show, {
|
|
146
|
+
get when() {
|
|
147
|
+
return props.doc !== undefined;
|
|
148
|
+
},
|
|
149
|
+
get children() {
|
|
150
|
+
return [_$memo(() => props.doc), _$createComponent(Show, {
|
|
151
|
+
get when() {
|
|
152
|
+
return props.futureImports !== undefined || hasChildren;
|
|
153
|
+
},
|
|
154
|
+
get children() {
|
|
155
|
+
return _$createIntrinsic("hbr", {});
|
|
156
|
+
}
|
|
157
|
+
})];
|
|
158
|
+
}
|
|
159
|
+
}), _$createComponent(Show, {
|
|
160
|
+
get when() {
|
|
161
|
+
return props.futureImports !== undefined;
|
|
162
|
+
},
|
|
163
|
+
get children() {
|
|
164
|
+
return [_$memo(() => props.futureImports), _$createComponent(Show, {
|
|
165
|
+
when: hasChildren,
|
|
166
|
+
get children() {
|
|
167
|
+
return [_$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {})];
|
|
168
|
+
}
|
|
169
|
+
})];
|
|
170
|
+
}
|
|
171
|
+
}), _$createComponent(Show, {
|
|
66
172
|
get when() {
|
|
67
173
|
return scope.importedModules.size > 0;
|
|
68
174
|
},
|
|
@@ -71,14 +177,19 @@ export function SourceFile(props) {
|
|
|
71
177
|
get records() {
|
|
72
178
|
return scope.importedModules;
|
|
73
179
|
}
|
|
74
|
-
}), _$
|
|
180
|
+
}), _$createComponent(Show, {
|
|
181
|
+
when: hasChildren,
|
|
182
|
+
get children() {
|
|
183
|
+
return [_$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {})];
|
|
184
|
+
}
|
|
185
|
+
})];
|
|
75
186
|
}
|
|
76
187
|
}), _$createComponent(Show, {
|
|
77
188
|
get when() {
|
|
78
|
-
return
|
|
189
|
+
return needsExtraSpacing && (hasPreamble || scope.importedModules.size > 0);
|
|
79
190
|
},
|
|
80
191
|
get children() {
|
|
81
|
-
return
|
|
192
|
+
return _$createIntrinsic("hbr", {});
|
|
82
193
|
}
|
|
83
194
|
}), _$createComponent(PythonSourceFileContext.Provider, {
|
|
84
195
|
value: sfContext,
|
|
@@ -86,10 +197,15 @@ export function SourceFile(props) {
|
|
|
86
197
|
return _$createComponent(Scope, {
|
|
87
198
|
value: scope,
|
|
88
199
|
get children() {
|
|
89
|
-
return _$createComponent(
|
|
90
|
-
|
|
200
|
+
return _$createComponent(Show, {
|
|
201
|
+
when: hasChildren,
|
|
91
202
|
get children() {
|
|
92
|
-
return
|
|
203
|
+
return _$createComponent(List, {
|
|
204
|
+
doubleHardline: true,
|
|
205
|
+
get children() {
|
|
206
|
+
return props.children;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
93
209
|
}
|
|
94
210
|
});
|
|
95
211
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SourceFile","CoreSourceFile","createNamedContext","List","Scope","Show","SourceDirectoryContext","useContext","join","PythonModuleScope","ImportStatements","Reference","
|
|
1
|
+
{"version":3,"names":["childrenArray","SourceFile","CoreSourceFile","createNamedContext","isComponentCreator","List","Scope","Show","SourceDirectoryContext","useContext","join","PythonModuleScope","ImportStatements","SimpleCommentBlock","Reference","NON_DEFINITION_NAMES","Set","WRAPPER_COMPONENT_NAMES","firstChildIsDefinition","children","arr","length","first","name","component","has","props","PythonSourceFileContext","useSourceFile","directoryContext","currentDir","path","replace","scope","undefined","sfContext","module","hasChildren","needsExtraSpacing","hasPreamble","header","headerComment","doc","futureImports","_$createComponent","filetype","reference","when","_$createIntrinsic","_$memo","importedModules","size","records","Provider","value","doubleHardline"],"sources":["../../../src/components/SourceFile.tsx"],"sourcesContent":[null],"mappings":";AAAA,SACEA,aAAa,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jB,uBAAuB,CAAC0B,QAAQ;QAACC,KAAK,EAAEnB,SAAS;QAAA,IAAAhB,SAAA;UAAA,OAAAyB,iBAAA,CAC/CtC,KAAK;YAACgD,KAAK,EAAErB,KAAK;YAAA,IAAAd,SAAA;cAAA,OAAAyB,iBAAA,CAChBrC,IAAI;gBAACwC,IAAI,EAAEV,WAAW;gBAAA,IAAAlB,SAAA;kBAAA,OAAAyB,iBAAA,CACpBvC,IAAI;oBAACkD,cAAc;oBAAA,IAAApC,SAAA;sBAAA,OAAEO,KAAK,CAACP,QAAQ;oBAAA;kBAAA;gBAAA;cAAA;YAAA;UAAA;QAAA;MAAA;IAAA;EAAA;AAMhD","ignoreList":[]}
|
|
@@ -12,6 +12,7 @@ export * from "./EnumMember.js";
|
|
|
12
12
|
export type { CommonFunctionProps } from "./FunctionBase.js";
|
|
13
13
|
export * from "./FunctionCallExpression.js";
|
|
14
14
|
export * from "./FunctionDeclaration.js";
|
|
15
|
+
export * from "./FutureStatement.js";
|
|
15
16
|
export * from "./ImportStatement.js";
|
|
16
17
|
export * from "./LexicalScope.js";
|
|
17
18
|
export * from "./MemberExpression.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAA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cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC"}
|
|
@@ -11,6 +11,7 @@ export * from "./EnumDeclaration.js";
|
|
|
11
11
|
export * from "./EnumMember.js";
|
|
12
12
|
export * from "./FunctionCallExpression.js";
|
|
13
13
|
export * from "./FunctionDeclaration.js";
|
|
14
|
+
export * from "./FutureStatement.js";
|
|
14
15
|
export * from "./ImportStatement.js";
|
|
15
16
|
export * from "./LexicalScope.js";
|
|
16
17
|
export * from "./MemberExpression.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../../src/components/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,oBAAoB;AAClC,cAAc,uBAAuB;AACrC,cAAc,yBAAyB;AACvC,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,8BAA8B;AAC5C,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAE/B,cAAc,6BAA6B;AAC3C,cAAc,0BAA0B;AACxC,cAAc,sBAAsB;AACpC,cAAc,mBAAmB;AACjC,cAAc,uBAAuB;AACrC;AAEA,cAAc,wBAAwB;AACtC,cAAc,0BAA0B;AACxC,cAAc,YAAY;AAC1B,cAAc,kBAAkB;AAChC,cAAc,gBAAgB;AAC9B,cAAc,iBAAiB;AAC/B,cAAc,oBAAoB;AAClC,cAAc,8BAA8B;AAC5C,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["../../../src/components/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,oBAAoB;AAClC,cAAc,uBAAuB;AACrC,cAAc,yBAAyB;AACvC,cAAc,6BAA6B;AAC3C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,8BAA8B;AAC5C,cAAc,sBAAsB;AACpC,cAAc,iBAAiB;AAE/B,cAAc,6BAA6B;AAC3C,cAAc,0BAA0B;AACxC,cAAc,sBAAsB;AACpC,cAAc,sBAAsB;AACpC,cAAc,mBAAmB;AACjC,cAAc,uBAAuB;AACrC;AAEA,cAAc,wBAAwB;AACtC,cAAc,0BAA0B;AACxC,cAAc,YAAY;AAC1B,cAAc,kBAAkB;AAChC,cAAc,gBAAgB;AAC9B,cAAc,iBAAiB;AAC/B,cAAc,oBAAoB;AAClC,cAAc,8BAA8B;AAC5C,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,0BAA0B;AAAC","ignoreList":[]}
|
|
@@ -84,6 +84,41 @@ describe("Call Signature Parameters", () => {
|
|
|
84
84
|
a: int = 5, b: str = "hello"
|
|
85
85
|
`);
|
|
86
86
|
});
|
|
87
|
+
it("renders keyword-only parameters with * marker", () => {
|
|
88
|
+
const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
|
|
89
|
+
parameters: [{
|
|
90
|
+
name: "a",
|
|
91
|
+
type: "str"
|
|
92
|
+
}, "*", {
|
|
93
|
+
name: "b",
|
|
94
|
+
type: "int",
|
|
95
|
+
default: 10
|
|
96
|
+
}, {
|
|
97
|
+
name: "c",
|
|
98
|
+
type: "bool",
|
|
99
|
+
default: true
|
|
100
|
+
}]
|
|
101
|
+
})]);
|
|
102
|
+
expect(result).toRenderTo(d`
|
|
103
|
+
a: str, *, b: int = 10, c: bool = True
|
|
104
|
+
`);
|
|
105
|
+
});
|
|
106
|
+
it("renders only keyword-only parameters with * marker at start", () => {
|
|
107
|
+
const result = toSourceText([_$createComponent(py.CallSignatureParameters, {
|
|
108
|
+
parameters: ["*", {
|
|
109
|
+
name: "a",
|
|
110
|
+
type: "str",
|
|
111
|
+
default: "hello"
|
|
112
|
+
}, {
|
|
113
|
+
name: "b",
|
|
114
|
+
type: "int",
|
|
115
|
+
default: 42
|
|
116
|
+
}]
|
|
117
|
+
})]);
|
|
118
|
+
expect(result).toRenderTo(d`
|
|
119
|
+
*, a: str = "hello", b: int = 42
|
|
120
|
+
`);
|
|
121
|
+
});
|
|
87
122
|
});
|
|
88
123
|
describe("Call Signature", () => {
|
|
89
124
|
it("renders a call signature with strings", () => {
|
|
@@ -251,5 +286,97 @@ describe("Call Signature - Parameter Descriptors", () => {
|
|
|
251
286
|
[T, U](a: int, b: str = "default_value") -> int
|
|
252
287
|
`);
|
|
253
288
|
});
|
|
289
|
+
it("renders a call signature with keyword-only parameters using * marker", () => {
|
|
290
|
+
const result = toSourceText([_$createComponent(py.CallSignature, {
|
|
291
|
+
parameters: [{
|
|
292
|
+
name: "id",
|
|
293
|
+
type: "str"
|
|
294
|
+
}, "*", {
|
|
295
|
+
name: "locale",
|
|
296
|
+
type: "str",
|
|
297
|
+
default: "en-US"
|
|
298
|
+
}, {
|
|
299
|
+
name: "debug",
|
|
300
|
+
type: "bool",
|
|
301
|
+
default: false
|
|
302
|
+
}],
|
|
303
|
+
returnType: "str"
|
|
304
|
+
})]);
|
|
305
|
+
expect(result).toRenderTo(d`
|
|
306
|
+
(id: str, *, locale: str = "en-US", debug: bool = False) -> str
|
|
307
|
+
`);
|
|
308
|
+
});
|
|
309
|
+
it("renders a call signature with only keyword-only parameters", () => {
|
|
310
|
+
const result = toSourceText([_$createComponent(py.CallSignature, {
|
|
311
|
+
parameters: ["*", {
|
|
312
|
+
name: "name",
|
|
313
|
+
type: "str",
|
|
314
|
+
default: "alice"
|
|
315
|
+
}, {
|
|
316
|
+
name: "age",
|
|
317
|
+
type: "int",
|
|
318
|
+
default: 30
|
|
319
|
+
}],
|
|
320
|
+
returnType: "None"
|
|
321
|
+
})]);
|
|
322
|
+
expect(result).toRenderTo(d`
|
|
323
|
+
(*, name: str = "alice", age: int = 30) -> None
|
|
324
|
+
`);
|
|
325
|
+
});
|
|
326
|
+
it("renders a call signature with positional, keyword-only, and *args/**kwargs", () => {
|
|
327
|
+
const result = toSourceText([_$createComponent(py.CallSignature, {
|
|
328
|
+
parameters: [{
|
|
329
|
+
name: "a",
|
|
330
|
+
type: "int"
|
|
331
|
+
}, "*", {
|
|
332
|
+
name: "b",
|
|
333
|
+
type: "str",
|
|
334
|
+
default: "hello"
|
|
335
|
+
}],
|
|
336
|
+
args: true,
|
|
337
|
+
kwargs: true,
|
|
338
|
+
returnType: "None"
|
|
339
|
+
})]);
|
|
340
|
+
expect(result).toRenderTo(d`
|
|
341
|
+
(a: int, *, b: str = "hello", *args, **kwargs) -> None
|
|
342
|
+
`);
|
|
343
|
+
});
|
|
344
|
+
it("renders a call signature with positional-only parameters using / marker", () => {
|
|
345
|
+
const result = toSourceText([_$createComponent(py.CallSignature, {
|
|
346
|
+
parameters: [{
|
|
347
|
+
name: "a",
|
|
348
|
+
type: "int"
|
|
349
|
+
}, {
|
|
350
|
+
name: "b",
|
|
351
|
+
type: "str"
|
|
352
|
+
}, "/", {
|
|
353
|
+
name: "c",
|
|
354
|
+
type: "bool"
|
|
355
|
+
}],
|
|
356
|
+
returnType: "None"
|
|
357
|
+
})]);
|
|
358
|
+
expect(result).toRenderTo(d`
|
|
359
|
+
(a: int, b: str, /, c: bool) -> None
|
|
360
|
+
`);
|
|
361
|
+
});
|
|
362
|
+
it("renders a call signature with positional-only, regular, and keyword-only parameters", () => {
|
|
363
|
+
const result = toSourceText([_$createComponent(py.CallSignature, {
|
|
364
|
+
parameters: [{
|
|
365
|
+
name: "a",
|
|
366
|
+
type: "int"
|
|
367
|
+
}, "/", {
|
|
368
|
+
name: "b",
|
|
369
|
+
type: "str"
|
|
370
|
+
}, "*", {
|
|
371
|
+
name: "c",
|
|
372
|
+
type: "bool",
|
|
373
|
+
default: true
|
|
374
|
+
}],
|
|
375
|
+
returnType: "None"
|
|
376
|
+
})]);
|
|
377
|
+
expect(result).toRenderTo(d`
|
|
378
|
+
(a: int, /, b: str, *, c: bool = True) -> None
|
|
379
|
+
`);
|
|
380
|
+
});
|
|
254
381
|
});
|
|
255
382
|
//# sourceMappingURL=callsignatures.test.js.map
|