Automate Python stub generation for builtin structs#10983
Automate Python stub generation for builtin structs#10983burhankhanzada merged 3 commits intoslint-ui:masterfrom
Conversation
c8b5a7d to
958e508
Compare
api/python/slint/build.rs
Outdated
| #[path = "stub-gen/language.rs"] | ||
| mod language; | ||
|
|
||
| fn main() { |
There was a problem hiding this comment.
language.pyi is checked in, it's also generated in build.rs. We need to pick one ;-).
When I suggested to put this into stub-get, I had in mind that stub-gen is run manually and the generated file is checked in.
If it's possible to do this all in build.rs and the file is saved in the right location, that would also be nice. Are you sure that works?
(If it does, that would be great)
There was a problem hiding this comment.
Well i have try to check first delete the language.pyi file then run cargo build -p slint-python and it build that file. So if you went i can remove language.pyi from git history.
There was a problem hiding this comment.
Yes, that sounds good. At least I think that's the general direction we want also later then with the pyo3 exposed types, too. In that case, I suggest to fold language.rs into build.rs.
api/python/slint/build.rs
Outdated
| mod language; | ||
|
|
||
| fn main() { | ||
| println!("cargo:rerun-if-changed=../../internal/common/builtin_structs.rs"); |
There was a problem hiding this comment.
Why is this needed? Doesn't rustc take care of the as the .rs files are included via mod?
There was a problem hiding this comment.
Yes you are right its not need coz it will be detected automatically as we include i-slint-common as dependency.
| writeln!(writer, "import typing").unwrap(); | ||
|
|
||
| $( | ||
| if stringify!($NameTy) == "BuiltinPublicStruct" { |
There was a problem hiding this comment.
Instead of stringify, would it perhaps possible to use a trick similar to export_builtin_structs in api/rs/slint/lib.rs ? So invoke the macro on for_each_builtin_structs, match for "big" pattern as you do here, produces tokens for the scaffolding (leading and trailing stuff), and then invoke recursively, but with a tag to disambiguate and with $NameTy so that then you can match for BuiltinPrivateStruct ?
… handling public and private structs.
…nd add the generated file to `.gitignore`.
This PR automates the maintenance of Python type stubs
.pyifor Slint's builtin structs, ensuring they stay perfectly in sync with the internal Rust definitions.