@vx-oss/docs-python 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/badge.js +11 -0
- package/dist/build.js +179 -0
- package/dist/components/collapsible.js +16 -0
- package/dist/components/index.d.ts +33 -0
- package/dist/components/index.js +150 -0
- package/dist/convert.d.ts +29 -0
- package/dist/convert.js +31 -0
- package/dist/generated.d.ts +83 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +3 -0
- package/dist/plugin.js +28 -0
- package/dist/renderer.d.ts +24 -0
- package/dist/renderer.js +57 -0
- package/dist/source.d.ts +53 -0
- package/dist/source.js +73 -0
- package/fumapy/__init__.py +65 -0
- package/fumapy/mksource/__init__.py +10 -0
- package/fumapy/mksource/document_module.py +93 -0
- package/fumapy/mksource/json_encoder.py +29 -0
- package/fumapy/mksource/models.py +60 -0
- package/fumapy/mksource/simplify_docstring.py +166 -0
- package/fumapy/mksource/utils.py +59 -0
- package/package.json +95 -0
- package/pyproject.toml +15 -0
- package/styles/preset.css +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Fuma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
|
+
let target = {};
|
|
5
|
+
for (var name in all) __defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true
|
|
8
|
+
});
|
|
9
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
+
return target;
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { __exportAll };
|
package/dist/badge.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { cva } from "class-variance-authority";
|
|
2
|
+
//#region src/badge.ts
|
|
3
|
+
const badgeVariants = cva("text-xs font-medium border p-1 rounded-lg not-prose", { variants: { color: {
|
|
4
|
+
func: "bg-fdpy-func/10 text-fdpy-func border-fdpy-func/50",
|
|
5
|
+
attribute: "bg-fdpy-attribute/10 text-fdpy-attribute border-fdpy-attribute/50",
|
|
6
|
+
class: "bg-fdpy-class/10 text-fdpy-class border-fdpy-class/50",
|
|
7
|
+
module: "bg-fdpy-module/10 text-fdpy-module border-fdpy-module/50",
|
|
8
|
+
primary: "bg-fd-primary/10 text-fd-primary border-fd-primary/10"
|
|
9
|
+
} } });
|
|
10
|
+
//#endregion
|
|
11
|
+
export { badgeVariants };
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { remarkGfm } from "@vx-oss/docs-core/mdx-plugins/remark-gfm";
|
|
2
|
+
import { remark } from "remark";
|
|
3
|
+
//#region src/build.ts
|
|
4
|
+
const parser = remark().use(remarkGfm).use(function() {
|
|
5
|
+
(this.data().micromarkExtensions ??= []).push({ disable: { null: ["htmlFlow", "htmlText"] } });
|
|
6
|
+
});
|
|
7
|
+
/** One page per module and class, a class page comes before its module. */
|
|
8
|
+
function buildPages(root, groupBy = "module") {
|
|
9
|
+
const pages = [];
|
|
10
|
+
/** file path of an object, without extension */
|
|
11
|
+
function file(path) {
|
|
12
|
+
if (groupBy === "none") path = path === root.path ? "" : path.slice(root.path.length + 1);
|
|
13
|
+
return path.replaceAll(".", "/");
|
|
14
|
+
}
|
|
15
|
+
function classPage(cls) {
|
|
16
|
+
return {
|
|
17
|
+
path: `${file(cls.path)}.mdx`,
|
|
18
|
+
title: cls.name,
|
|
19
|
+
kind: "class",
|
|
20
|
+
build() {
|
|
21
|
+
const content = describe(cls.description, cls.docstring);
|
|
22
|
+
if (cls.attributes.length > 0) content.push(heading("Attributes"), attributes(cls.attributes));
|
|
23
|
+
const functions = Object.values(cls.functions).sort((a, b) => Number(isConstructor(b)) - Number(isConstructor(a)));
|
|
24
|
+
if (functions.length > 0) content.push(heading("Functions"), ...functions.map(fn));
|
|
25
|
+
return {
|
|
26
|
+
type: "root",
|
|
27
|
+
children: content
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function module(mod) {
|
|
33
|
+
const classes = Object.values(mod.classes).map(classPage);
|
|
34
|
+
pages.push(...classes);
|
|
35
|
+
const modules = Object.values(mod.modules).map(module);
|
|
36
|
+
const dir = file(mod.path);
|
|
37
|
+
const folder = classes.length > 0 || modules.length > 0;
|
|
38
|
+
const page = {
|
|
39
|
+
path: !dir ? "index.mdx" : folder ? `${dir}/index.mdx` : `${dir}.mdx`,
|
|
40
|
+
title: mod.name,
|
|
41
|
+
kind: "module",
|
|
42
|
+
build(href) {
|
|
43
|
+
const content = describe(mod.description, mod.docstring);
|
|
44
|
+
if (mod.attributes.length > 0) content.push(attributes(mod.attributes));
|
|
45
|
+
const tabs = [];
|
|
46
|
+
const panels = [];
|
|
47
|
+
function tab(name, children) {
|
|
48
|
+
tabs.push(name);
|
|
49
|
+
panels.push(jsx("Tab", { value: name }, children));
|
|
50
|
+
}
|
|
51
|
+
if (classes.length > 0) tab("Class", [cards(classes, href)]);
|
|
52
|
+
const functions = Object.values(mod.functions);
|
|
53
|
+
if (functions.length > 0) tab("Functions", functions.map(fn));
|
|
54
|
+
if (modules.length > 0) tab("Modules", [cards(modules, href)]);
|
|
55
|
+
if (tabs.length > 0) content.push(jsx("Tabs", { items: tabs }, panels));
|
|
56
|
+
return {
|
|
57
|
+
type: "root",
|
|
58
|
+
children: content
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
pages.push(page);
|
|
63
|
+
return page;
|
|
64
|
+
}
|
|
65
|
+
module(root);
|
|
66
|
+
return pages;
|
|
67
|
+
}
|
|
68
|
+
function cards(targets, href) {
|
|
69
|
+
return jsx("Cards", {}, targets.map((target) => jsx("Card", {
|
|
70
|
+
title: target.title,
|
|
71
|
+
href: href(target)
|
|
72
|
+
})));
|
|
73
|
+
}
|
|
74
|
+
function fn(func) {
|
|
75
|
+
const content = describe(func.description, func.docstring);
|
|
76
|
+
if (func.source.length > 0) content.push(jsx("PySourceCode", {}, [code("python", func.source)]));
|
|
77
|
+
if (func.parameters.length > 0) content.push(jsx("div", {}, func.parameters.map(parameter)));
|
|
78
|
+
content.push(jsx("PyFunctionReturn", { type: func.returns.annotation }, func.returns.description ? markdown(func.returns.description) : []));
|
|
79
|
+
return jsx("PyFunction", {
|
|
80
|
+
name: func.name,
|
|
81
|
+
type: func.signature,
|
|
82
|
+
kind: isConstructor(func) ? "constructor" : null
|
|
83
|
+
}, content);
|
|
84
|
+
}
|
|
85
|
+
function isConstructor(func) {
|
|
86
|
+
return func.name === "__init__";
|
|
87
|
+
}
|
|
88
|
+
function parameter(param) {
|
|
89
|
+
return jsx("PyParameter", {
|
|
90
|
+
name: param.name,
|
|
91
|
+
type: param.annotation,
|
|
92
|
+
value: param.value
|
|
93
|
+
}, typeof param.description === "string" ? markdown(param.description) : docstring(param.description));
|
|
94
|
+
}
|
|
95
|
+
function attributes(attrs) {
|
|
96
|
+
return jsx("PyAttributes", {}, attrs.map((attr) => jsx("PyAttribute", {
|
|
97
|
+
name: attr.name,
|
|
98
|
+
type: attr.annotation,
|
|
99
|
+
value: attr.value
|
|
100
|
+
}, docstring(attr.description))));
|
|
101
|
+
}
|
|
102
|
+
function describe(description, sections) {
|
|
103
|
+
const content = description ? markdown(description) : [];
|
|
104
|
+
content.push(...docstring(sections));
|
|
105
|
+
return content;
|
|
106
|
+
}
|
|
107
|
+
function docstring(sections) {
|
|
108
|
+
const content = [];
|
|
109
|
+
for (const section of sections ?? []) if (section.kind === "text") content.push(...markdown(section.value));
|
|
110
|
+
else if (section.kind === "admonition") content.push(jsx("Callout", {
|
|
111
|
+
title: section.title,
|
|
112
|
+
type: section.value.annotation
|
|
113
|
+
}, markdown(section.value.description)));
|
|
114
|
+
else if (section.kind === "examples") for (const [kind, value] of section.value) if (kind === "text") content.push(...markdown(value));
|
|
115
|
+
else content.push(code("python", value));
|
|
116
|
+
return content;
|
|
117
|
+
}
|
|
118
|
+
function markdown(text) {
|
|
119
|
+
return parser.parse(text).children;
|
|
120
|
+
}
|
|
121
|
+
function heading(text) {
|
|
122
|
+
return {
|
|
123
|
+
type: "heading",
|
|
124
|
+
depth: 2,
|
|
125
|
+
children: [{
|
|
126
|
+
type: "text",
|
|
127
|
+
value: text
|
|
128
|
+
}]
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function code(lang, value) {
|
|
132
|
+
return {
|
|
133
|
+
type: "code",
|
|
134
|
+
lang,
|
|
135
|
+
value
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function jsx(name, props, children = []) {
|
|
139
|
+
const attributes = [];
|
|
140
|
+
for (const name in props) {
|
|
141
|
+
const value = props[name];
|
|
142
|
+
if (value == null) continue;
|
|
143
|
+
attributes.push({
|
|
144
|
+
type: "mdxJsxAttribute",
|
|
145
|
+
name,
|
|
146
|
+
value: typeof value === "string" ? value : expression(value)
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
type: "mdxJsxFlowElement",
|
|
151
|
+
name,
|
|
152
|
+
attributes,
|
|
153
|
+
children
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** an array of strings as an attribute expression, with the estree the renderer evaluates */
|
|
157
|
+
function expression(value) {
|
|
158
|
+
const estree = {
|
|
159
|
+
type: "Program",
|
|
160
|
+
sourceType: "module",
|
|
161
|
+
body: [{
|
|
162
|
+
type: "ExpressionStatement",
|
|
163
|
+
expression: {
|
|
164
|
+
type: "ArrayExpression",
|
|
165
|
+
elements: value.map((item) => ({
|
|
166
|
+
type: "Literal",
|
|
167
|
+
value: item
|
|
168
|
+
}))
|
|
169
|
+
}
|
|
170
|
+
}]
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
type: "mdxJsxAttributeValueExpression",
|
|
174
|
+
value: JSON.stringify(value),
|
|
175
|
+
data: { estree }
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { buildPages };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from "cnfast";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { Collapsible } from "@base-ui/react/collapsible";
|
|
5
|
+
//#region src/components/collapsible.tsx
|
|
6
|
+
const Collapsible$1 = Collapsible.Root;
|
|
7
|
+
const CollapsibleTrigger = Collapsible.Trigger;
|
|
8
|
+
function CollapsibleContent({ children, className, ...props }) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Collapsible.Panel, {
|
|
10
|
+
...props,
|
|
11
|
+
className: (s) => cn("overflow-hidden [&[hidden]:not([hidden='until-found'])]:hidden h-(--collapsible-panel-height) transition-[height,opacity] data-starting-style:opacity-0 data-starting-style:h-0 data-ending-style:h-0 data-ending-style:opacity-0", typeof className === "function" ? className(s) : className),
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Collapsible$1 as Collapsible, CollapsibleContent, CollapsibleTrigger };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Tab, Tabs } from "@vx-oss/docs-react/components/tabs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
//#region src/components/index.d.ts
|
|
4
|
+
declare function PyFunction(props: {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
kind?: 'func' | 'constructor';
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
declare function PyAttributes({ children }: {
|
|
11
|
+
children?: ReactNode;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
13
|
+
declare function PyAttribute(props: {
|
|
14
|
+
name: string;
|
|
15
|
+
type?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
declare function PyParameter(props: {
|
|
20
|
+
name: string;
|
|
21
|
+
type?: string;
|
|
22
|
+
value?: string;
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
}): import("react").JSX.Element;
|
|
25
|
+
declare function PySourceCode({ children }: {
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
28
|
+
declare function PyFunctionReturn({ type, children }: {
|
|
29
|
+
type?: string;
|
|
30
|
+
children: ReactNode;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { PyAttribute, PyAttributes, PyFunction, PyFunctionReturn, PyParameter, PySourceCode, Tab, Tabs };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { badgeVariants } from "../badge.js";
|
|
3
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./collapsible.js";
|
|
4
|
+
import { cn } from "cnfast";
|
|
5
|
+
import { cva } from "class-variance-authority";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { buttonVariants } from "@vx-oss/docs-react/components/ui/button";
|
|
8
|
+
import { ChevronRight } from "lucide-react";
|
|
9
|
+
import { highlight } from "@vx-oss/docs-core/highlight";
|
|
10
|
+
import { Tab, Tabs } from "@vx-oss/docs-react/components/tabs";
|
|
11
|
+
//#region src/components/index.tsx
|
|
12
|
+
var components_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
PyAttribute: () => PyAttribute,
|
|
14
|
+
PyAttributes: () => PyAttributes,
|
|
15
|
+
PyFunction: () => PyFunction,
|
|
16
|
+
PyFunctionReturn: () => PyFunctionReturn,
|
|
17
|
+
PyParameter: () => PyParameter,
|
|
18
|
+
PySourceCode: () => PySourceCode,
|
|
19
|
+
Tab: () => Tab,
|
|
20
|
+
Tabs: () => Tabs
|
|
21
|
+
});
|
|
22
|
+
const cardVariants = cva("bg-fd-card rounded-lg text-sm my-6 p-3 border");
|
|
23
|
+
function PyFunction(props) {
|
|
24
|
+
return /* @__PURE__ */ jsxs("figure", {
|
|
25
|
+
className: cn(cardVariants()),
|
|
26
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
27
|
+
className: "flex gap-2 items-center font-mono flex-wrap mb-4",
|
|
28
|
+
children: [
|
|
29
|
+
/* @__PURE__ */ jsx("code", {
|
|
30
|
+
className: cn(badgeVariants({ color: "func" })),
|
|
31
|
+
children: props.kind ?? "func"
|
|
32
|
+
}),
|
|
33
|
+
props.name,
|
|
34
|
+
/* @__PURE__ */ jsx(InlineCode, {
|
|
35
|
+
lang: "python",
|
|
36
|
+
className: "not-prose text-xs text-fd-muted-foreground",
|
|
37
|
+
code: props.type
|
|
38
|
+
})
|
|
39
|
+
]
|
|
40
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
41
|
+
className: "text-fd-muted-foreground prose-no-margin",
|
|
42
|
+
children: props.children
|
|
43
|
+
})]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function PyAttributes({ children }) {
|
|
47
|
+
return /* @__PURE__ */ jsx("figure", {
|
|
48
|
+
className: cn(cardVariants(), "p-0 divide-y"),
|
|
49
|
+
children
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function PyAttribute(props) {
|
|
53
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
54
|
+
className: "p-3",
|
|
55
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
56
|
+
className: "flex gap-2 items-center flex-wrap font-mono",
|
|
57
|
+
children: [
|
|
58
|
+
/* @__PURE__ */ jsx("code", {
|
|
59
|
+
className: cn(badgeVariants({ color: "attribute" })),
|
|
60
|
+
children: "attribute"
|
|
61
|
+
}),
|
|
62
|
+
props.name,
|
|
63
|
+
props.type && /* @__PURE__ */ jsx(InlineCode, {
|
|
64
|
+
lang: "python",
|
|
65
|
+
className: "not-prose text-fd-muted-foreground text-xs",
|
|
66
|
+
code: props.type
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
70
|
+
className: "text-fd-muted-foreground prose-no-margin mt-2 empty:hidden",
|
|
71
|
+
children: [props.value && /* @__PURE__ */ jsx(InlineCode, {
|
|
72
|
+
lang: "python",
|
|
73
|
+
className: "not-prose text-xs",
|
|
74
|
+
code: `= ${props.value}`
|
|
75
|
+
}), props.children]
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function PyParameter(props) {
|
|
80
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
81
|
+
"data-parameter": "",
|
|
82
|
+
className: "bg-fd-secondary rounded-lg text-sm p-3 border shadow-md rounded-none first:rounded-t-lg last:rounded-b-lg",
|
|
83
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
84
|
+
className: "flex flex-wrap gap-2 items-center font-mono text-fd-foreground",
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ jsx("code", {
|
|
87
|
+
className: cn(badgeVariants({ color: "primary" })),
|
|
88
|
+
children: "param"
|
|
89
|
+
}),
|
|
90
|
+
props.name,
|
|
91
|
+
props.type && /* @__PURE__ */ jsx(InlineCode, {
|
|
92
|
+
lang: "python",
|
|
93
|
+
className: "ms-auto text-fd-muted-foreground not-prose text-xs",
|
|
94
|
+
code: props.type
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
98
|
+
className: "text-fd-muted-foreground prose-no-margin mt-4 empty:hidden",
|
|
99
|
+
children: [props.value ? /* @__PURE__ */ jsx(InlineCode, {
|
|
100
|
+
lang: "python",
|
|
101
|
+
code: `= ${props.value}`,
|
|
102
|
+
className: "not-prose text-xs"
|
|
103
|
+
}) : null, props.children]
|
|
104
|
+
})]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function PySourceCode({ children }) {
|
|
108
|
+
return /* @__PURE__ */ jsxs(Collapsible, {
|
|
109
|
+
className: "my-6",
|
|
110
|
+
children: [/* @__PURE__ */ jsxs(CollapsibleTrigger, {
|
|
111
|
+
className: cn(buttonVariants({
|
|
112
|
+
color: "secondary",
|
|
113
|
+
size: "sm",
|
|
114
|
+
className: "group"
|
|
115
|
+
})),
|
|
116
|
+
children: ["Source Code", /* @__PURE__ */ jsx(ChevronRight, { className: "size-3.5 text-fd-muted-foreground group-data-[panel-open]:rotate-90" })]
|
|
117
|
+
}), /* @__PURE__ */ jsx(CollapsibleContent, {
|
|
118
|
+
className: "prose-no-margin",
|
|
119
|
+
children
|
|
120
|
+
})]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
function PyFunctionReturn({ type, children }) {
|
|
124
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
125
|
+
className: "border bg-fd-secondary rounded-lg p-3 mt-2",
|
|
126
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
127
|
+
className: "flex flex-wrap gap-2 not-prose",
|
|
128
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
129
|
+
className: "font-medium me-auto",
|
|
130
|
+
children: "Returns"
|
|
131
|
+
}), /* @__PURE__ */ jsx(InlineCode, {
|
|
132
|
+
lang: "python",
|
|
133
|
+
code: type ?? "None",
|
|
134
|
+
className: "text-xs"
|
|
135
|
+
})]
|
|
136
|
+
}), children]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async function InlineCode({ lang, code, ...rest }) {
|
|
140
|
+
return highlight(code, {
|
|
141
|
+
lang,
|
|
142
|
+
components: { pre: (props) => /* @__PURE__ */ jsx("span", {
|
|
143
|
+
...props,
|
|
144
|
+
...rest,
|
|
145
|
+
className: cn(rest.className, props.className)
|
|
146
|
+
}) }
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { PyAttribute, PyAttributes, PyFunction, PyFunctionReturn, PyParameter, PySourceCode, Tab, Tabs, components_exports };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ModuleInterface } from "./generated.js";
|
|
2
|
+
import { PythonGroupBy } from "./source.js";
|
|
3
|
+
//#region src/convert.d.ts
|
|
4
|
+
interface ConvertOptions {
|
|
5
|
+
/** base URL of the generated pages, used to link classes and modules from their parent module */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/**
|
|
8
|
+
* group generated pages in a directory:
|
|
9
|
+
*
|
|
10
|
+
* - `module`: the name of the root module
|
|
11
|
+
* - `none`: place them at the root of the output directory
|
|
12
|
+
*
|
|
13
|
+
* @defaultValue 'module'
|
|
14
|
+
*/
|
|
15
|
+
groupBy?: PythonGroupBy;
|
|
16
|
+
}
|
|
17
|
+
interface OutputFile {
|
|
18
|
+
/** relative to the output directory, e.g. `httpx/_client/index.mdx` */
|
|
19
|
+
path: string;
|
|
20
|
+
title: string;
|
|
21
|
+
/** MDX content, without frontmatter */
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
/** Convert a module into MDX files, one per module and class. */
|
|
25
|
+
declare function convert(mod: ModuleInterface, options?: ConvertOptions): OutputFile[];
|
|
26
|
+
/** Write the converted files into your content directory. */
|
|
27
|
+
declare function write(files: OutputFile[], outDir?: string): Promise<void>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ConvertOptions, OutputFile, convert, write };
|
package/dist/convert.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildPages } from "./build.js";
|
|
2
|
+
import * as fs$1 from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { mdxToMarkdown } from "mdast-util-mdx";
|
|
5
|
+
import { remarkGfm } from "@vx-oss/docs-core/mdx-plugins/remark-gfm";
|
|
6
|
+
import { remark } from "remark";
|
|
7
|
+
import { getSlugs } from "@vx-oss/docs-core/source";
|
|
8
|
+
//#region src/convert.ts
|
|
9
|
+
const stringifier = remark().use(remarkGfm).use(function() {
|
|
10
|
+
(this.data().toMarkdownExtensions ??= []).push(mdxToMarkdown());
|
|
11
|
+
});
|
|
12
|
+
/** Convert a module into MDX files, one per module and class. */
|
|
13
|
+
function convert(mod, options = {}) {
|
|
14
|
+
const { baseUrl = "/" } = options;
|
|
15
|
+
const href = (target) => "/" + [...baseUrl.split("/"), ...getSlugs(target.path)].filter(Boolean).join("/");
|
|
16
|
+
return buildPages(mod, options.groupBy).map((page) => ({
|
|
17
|
+
path: page.path,
|
|
18
|
+
title: page.title,
|
|
19
|
+
content: stringifier.stringify(page.build(href))
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
/** Write the converted files into your content directory. */
|
|
23
|
+
async function write(files, outDir = "./") {
|
|
24
|
+
await Promise.all(files.map(async (file) => {
|
|
25
|
+
const filePath = path.resolve(outDir, file.path);
|
|
26
|
+
await fs$1.mkdir(path.dirname(filePath), { recursive: true });
|
|
27
|
+
await fs$1.writeFile(filePath, `---\ntitle: ${JSON.stringify(file.title)}\n---\n\n${file.content}`);
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { convert, write };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region src/generated.d.ts
|
|
2
|
+
interface ModuleInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
|
+
description: string | null;
|
|
6
|
+
docstring: DocstringSection[] | null;
|
|
7
|
+
modules: {
|
|
8
|
+
[key: string]: ModuleInterface;
|
|
9
|
+
};
|
|
10
|
+
attributes: AttributeInterface[];
|
|
11
|
+
classes: {
|
|
12
|
+
[key: string]: ClassInterface;
|
|
13
|
+
};
|
|
14
|
+
functions: {
|
|
15
|
+
[key: string]: FunctionInterface;
|
|
16
|
+
};
|
|
17
|
+
version?: string;
|
|
18
|
+
}
|
|
19
|
+
interface ClassInterface {
|
|
20
|
+
name: string;
|
|
21
|
+
path: string;
|
|
22
|
+
description: string | null;
|
|
23
|
+
docstring: DocstringSection[] | null;
|
|
24
|
+
parameters: ParameterInterface[];
|
|
25
|
+
attributes: AttributeInterface[];
|
|
26
|
+
functions: {
|
|
27
|
+
[key: string]: FunctionInterface;
|
|
28
|
+
};
|
|
29
|
+
source: string;
|
|
30
|
+
inherited_members: {
|
|
31
|
+
[key: string]: {
|
|
32
|
+
kind: string;
|
|
33
|
+
path: string;
|
|
34
|
+
}[];
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface FunctionInterface {
|
|
38
|
+
name: string;
|
|
39
|
+
path: string;
|
|
40
|
+
signature: string;
|
|
41
|
+
description: string | null;
|
|
42
|
+
docstring: DocstringSection[];
|
|
43
|
+
parameters: ParameterInterface[];
|
|
44
|
+
returns: ReturnInterface;
|
|
45
|
+
source: string;
|
|
46
|
+
}
|
|
47
|
+
interface AttributeInterface {
|
|
48
|
+
name: string;
|
|
49
|
+
annotation: string | null;
|
|
50
|
+
description: DocstringSection[] | null;
|
|
51
|
+
value: string | null;
|
|
52
|
+
}
|
|
53
|
+
type DocstringSection = {
|
|
54
|
+
kind: 'text';
|
|
55
|
+
value: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'admonition';
|
|
58
|
+
value: {
|
|
59
|
+
annotation: string;
|
|
60
|
+
description: string;
|
|
61
|
+
};
|
|
62
|
+
title: string;
|
|
63
|
+
} | {
|
|
64
|
+
kind: 'examples';
|
|
65
|
+
value: [string, string][];
|
|
66
|
+
} | {
|
|
67
|
+
kind: string;
|
|
68
|
+
value: any;
|
|
69
|
+
title?: string;
|
|
70
|
+
};
|
|
71
|
+
interface ParameterInterface {
|
|
72
|
+
name: string;
|
|
73
|
+
annotation: string | null;
|
|
74
|
+
description: string | DocstringSection[] | null;
|
|
75
|
+
value?: string | null;
|
|
76
|
+
}
|
|
77
|
+
interface ReturnInterface {
|
|
78
|
+
name: string;
|
|
79
|
+
annotation: string | null;
|
|
80
|
+
description: string | null;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export type { AttributeInterface, ClassInterface, DocstringSection, FunctionInterface, ModuleInterface, ParameterInterface, ReturnInterface };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AttributeInterface, ClassInterface, DocstringSection, FunctionInterface, ModuleInterface, ParameterInterface, ReturnInterface } from "./generated.js";
|
|
2
|
+
import { PythonRenderer, PythonRendererResult } from "./renderer.js";
|
|
3
|
+
import { PythonConfig, PythonGroupBy, PythonPage, PythonPageKind, PythonSource, SourceOptions, createPython } from "./source.js";
|
|
4
|
+
import { ConvertOptions, OutputFile, convert, write } from "./convert.js";
|
|
5
|
+
export { type AttributeInterface, type ClassInterface, ConvertOptions, type DocstringSection, type FunctionInterface, type ModuleInterface, OutputFile, type ParameterInterface, PythonConfig, PythonGroupBy, PythonPage, PythonPageKind, type PythonRenderer, type PythonRendererResult, PythonSource, type ReturnInterface, SourceOptions, convert, createPython, write };
|
package/dist/index.js
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { badgeVariants } from "./badge.js";
|
|
2
|
+
import { cn } from "cnfast";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
//#region src/plugin.tsx
|
|
5
|
+
/** Adds a `module`/`class` badge to generated pages in the page tree. */
|
|
6
|
+
function pythonPlugin() {
|
|
7
|
+
return {
|
|
8
|
+
name: "fumadocs:python",
|
|
9
|
+
transformPageTree: { file(node, filePath) {
|
|
10
|
+
if (!filePath || filePath.endsWith("/index.mdx")) return node;
|
|
11
|
+
const file = this.storage.read(filePath);
|
|
12
|
+
if (file?.format !== "page") return node;
|
|
13
|
+
const python = file.data._python;
|
|
14
|
+
if (!python) return node;
|
|
15
|
+
node.name = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
16
|
+
node.name,
|
|
17
|
+
" ",
|
|
18
|
+
/* @__PURE__ */ jsx("span", {
|
|
19
|
+
className: cn(badgeVariants({ color: python.kind }), "ms-auto py-0 text-nowrap"),
|
|
20
|
+
children: python.kind
|
|
21
|
+
})
|
|
22
|
+
] });
|
|
23
|
+
return node;
|
|
24
|
+
} }
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { pythonPlugin };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { StructuredData } from "@vx-oss/docs-core/mdx-plugins";
|
|
3
|
+
import { TOCItemType } from "@vx-oss/docs-core/toc";
|
|
4
|
+
import "hast";
|
|
5
|
+
import { MDXComponents } from "mdx/types";
|
|
6
|
+
//#region src/renderer.d.ts
|
|
7
|
+
interface PythonRendererResult {
|
|
8
|
+
toc: TOCItemType[];
|
|
9
|
+
body: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders a compiled page. The tree only references components by name, so
|
|
13
|
+
* rendering maps it to JSX without evaluating any JavaScript.
|
|
14
|
+
*/
|
|
15
|
+
interface PythonRenderer {
|
|
16
|
+
structuredData: StructuredData;
|
|
17
|
+
/**
|
|
18
|
+
* Fumadocs UI's default MDX components and `@vx-oss/docs-python/components`
|
|
19
|
+
* are included, pass your own to override them.
|
|
20
|
+
*/
|
|
21
|
+
render: (components?: MDXComponents) => Promise<PythonRendererResult>;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { PythonRenderer, PythonRendererResult };
|