Skip to content

Commit a253d3f

Browse files
chore: update Vuetify to 3.12.9
1 parent 8f2c320 commit a253d3f

11 files changed

Lines changed: 16325 additions & 6629 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
python-version: "3.10"
3636
- uses: actions/setup-node@v4
3737
with:
38-
node-version: 18.x
38+
node-version: "24"
3939
- name: Install dependencies
4040
run: |
4141
python -m pip install --upgrade pip

generate_source/build.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/bin/bash
22
if ! test -d "vuetify"; then
33
git clone https://github.com/vuetifyjs/vuetify.git
4-
cd vuetify
5-
git checkout v3.3.22
6-
npm install -g yarn
7-
yarn
8-
yarn build
9-
cd ..
104
fi
5+
cd vuetify
6+
git checkout v3.12.9
7+
npm install -g pnpm@10.26.1
8+
pnpm install --frozen-lockfile
9+
pnpm --filter vuetify build
10+
pnpm --filter @vuetify/api-generator exec node --no-warnings src/index.ts --skip-composables --skip-directives
11+
cd ..
1112
python generate_code.py
1213
pre-commit run --files ../ipyvuetify/generated.py ../js/src/Widgets.js

generate_source/generate_code.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,77 @@ def get_sub(prop: dict):
3838
return "TList(Any())"
3939
if prop["type"] == "object":
4040
return "Dict()"
41-
if prop["type"] in ["anyOf", "function", "record", "ref"]:
41+
if prop["type"] == "record":
42+
return "Dict()"
43+
if prop["type"] == "ref" and prop.get("ref", "").startswith("RouteLocation"):
44+
return "Any()"
45+
if prop["type"] == "allOf" and "string & {}" in prop.get("text", ""):
46+
return "Unicode()"
47+
if prop["type"] == "anyOf":
48+
sub = [get_sub(e) for e in prop["items"] if get_sub(e) is not None]
49+
if "Any()" in sub:
50+
return "Any()"
51+
if len(set(sub)) == 1:
52+
return sub[0]
53+
if sub:
54+
return f"Union([{', '.join(sub)}])"
55+
return "Any()"
56+
if prop["type"] in ["allOf", "constructor", "function", "ref", "UNSUPPORTED"]:
4257
return None
4358
raise Exception(f"Unknown sub type {prop['type']}")
4459

4560

61+
def supports_record(prop: dict):
62+
return "record<" in prop.get("text", "").casefold()
63+
64+
65+
def with_default(traitlet: str):
66+
if traitlet.startswith("Union("):
67+
return traitlet[:-1] + ", default_value=None, allow_none=True).tag(sync=True)\n"
68+
return traitlet.replace("()", "(default_value=None, allow_none=True).tag(sync=True)\n")
69+
70+
4671
def generate_traitlet(prop: dict):
72+
mixed_string_union = (
73+
prop["type"] == "anyOf"
74+
and "string & {}" in prop["text"]
75+
and {item["type"] for item in prop["items"]}.issuperset({"boolean", "number"})
76+
)
4777
if (
48-
"string & {}" in prop["text"]
78+
("string & {}" in prop["text"] and not mixed_string_union)
4979
or prop["type"] == "string"
5080
or prop["type"] == "ref"
5181
or prop["type"] == "function"
5282
):
5383
return "Unicode(default_value=None, allow_none=True).tag(sync=True)\n"
5484
if prop["type"] == "anyOf":
5585
sub = [get_sub(e) for e in prop["items"] if get_sub(e) is not None]
86+
if "Any()" in sub:
87+
return "Any().tag(sync=True)\n"
88+
if mixed_string_union:
89+
sub.sort(key=lambda traitlet: traitlet != "Bool()")
90+
sub = list(dict.fromkeys(sub))
91+
if not sub:
92+
return "Any().tag(sync=True)\n"
5693
if len(set(sub)) == 1:
5794
if sub[0] == "TList(Any())":
5895
return "TList(Any(), default_value=None, allow_none=True).tag(sync=True)\n"
59-
return sub[0].replace("()", "(default_value=None, allow_none=True).tag(sync=True)\n")
96+
return with_default(sub[0])
6097
return f"Union([{', '.join(sub)}], default_value=None, allow_none=True).tag(sync=True)\n"
6198
if prop["type"] == "boolean":
6299
return "Bool(default_value=None, allow_none=True).tag(sync=True)\n"
63100
if prop["type"] == "array":
101+
if supports_record(prop):
102+
return "Union([TList(Any()), Dict()], default_value=None, allow_none=True).tag(sync=True)\n"
64103
return "TList(Any(), default_value=None, allow_none=True).tag(sync=True)\n"
65104
if prop["type"] == "object":
66105
return "Dict(default_value=None, allow_none=True).tag(sync=True)\n"
67106
if prop["type"] == "number":
68107
return "Float(default_value=None, allow_none=True).tag(sync=True)\n"
69108
if prop["type"] == "any":
70109
return "Any().tag(sync=True)\n"
110+
if prop["type"] == "unknown":
111+
return "Any().tag(sync=True)\n"
71112
raise Exception(f"Unknown type {prop['type']}")
72113

73114

@@ -82,7 +123,7 @@ class {name[1:]}(VuetifyWidget):
82123
data = json.load(f)
83124
props = data["props"]
84125
for prop_name, prop in sorted(props.items()):
85-
if prop["type"] in ["record", "unknown"]:
126+
if prop["type"] == "record":
86127
continue
87128

88129
code += dedent_with_offset(
@@ -152,6 +193,9 @@ def generate_js_class(name, path):
152193

153194
with open(path) as f:
154195
data = json.load(f)
196+
component_name = (
197+
"IpyvuetifyDatePicker" if data["fileName"] == "VDatePicker" else data["fileName"]
198+
)
155199
props = data["props"]
156200
for prop_name, prop in props.items():
157201
if prop["type"] in ["record", "unknown"]:
@@ -170,7 +214,7 @@ def generate_js_class(name, path):
170214
}}
171215
172216
getVueTag() {{ // eslint-disable-line class-methods-use-this
173-
return "{data["fileName"]}";
217+
return "{component_name}";
174218
}}
175219
}}
176220

0 commit comments

Comments
 (0)