From 14bac7de836d1e8f5ad0e47713919190a2531a7d Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 25 Aug 2025 14:55:52 +0200 Subject: [PATCH 1/3] Only sort selected class --- scripts/sort_class.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/sort_class.py b/scripts/sort_class.py index 89cf9fda33..07f6cfa701 100644 --- a/scripts/sort_class.py +++ b/scripts/sort_class.py @@ -130,6 +130,8 @@ def sort_func_defs(funcs: list[cst.FunctionDef]) -> list[cst.FunctionDef]: return sorted(funcs, key=lambda d: d.name.value) def leave_FunctionDef(self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef): + if self.class_name is not None and self.current_class_name != self.class_name: + return updated_node if updated_node.name.value == "_initAttributes": attrs = list( [ From 1c90f3de4e7d5b17a2f0221a1b5a8d2bda5f1f3c Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 25 Aug 2025 15:21:11 +0200 Subject: [PATCH 2/3] Make creating classes in arbitrary github path work --- scripts/openapi.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/openapi.py b/scripts/openapi.py index 16e17d4121..67711fb282 100644 --- a/scripts/openapi.py +++ b/scripts/openapi.py @@ -193,7 +193,9 @@ def full_class_name(self) -> str: return f"{self.package}.{self.module}.{self.name}" @staticmethod - def from_class_name(class_name: str, index: dict[str, Any] | None = None) -> GithubClass: + def from_class_name(class_name: str, index: dict[str, Any] | None = None, github_parent_path: str = "") -> GithubClass: + if github_parent_path and not github_parent_path.endswith("/"): + github_parent_path = f"{github_parent_path}/" if "." in class_name: full_class_name = class_name package, module, class_name = full_class_name.split(".", 2) @@ -208,8 +210,8 @@ def from_class_name(class_name: str, index: dict[str, Any] | None = None) -> Git package="github", module=class_name, name=class_name, - filename=f"{package}/{module}.py", - test_filename=f"tests/{module}.py", + filename=f"{github_parent_path}{package}/{module}.py", + test_filename=f"{github_parent_path}tests/{module}.py", bases=[], inheritance=[], methods={}, @@ -227,7 +229,7 @@ def from_class_name(class_name: str, index: dict[str, Any] | None = None) -> Git raise KeyError(f"Missing package, module or name in {cls}") return GithubClass(**cls) else: - return GithubClass.from_class_name(f"github.{class_name}.{class_name}") + return GithubClass.from_class_name(f"github.{class_name}.{class_name}", github_parent_path=github_parent_path) @dataclasses.dataclass(frozen=True) @@ -2666,7 +2668,8 @@ def create_class( with open(index_filename) as r: index = json.load(r) - clazz = GithubClass.from_class_name(class_name) + github_parent_path = str(Path(github_path).parent) + clazz = GithubClass.from_class_name(class_name, github_parent_path=github_parent_path) parent_class = GithubClass.from_class_name(parent_name, index) print(f"Creating class {clazz.full_class_name} with parent {parent_class.full_class_name} in {clazz.filename}") if os.path.exists(clazz.filename): From 3b4954b469fadc813dc3d8c020747ed45439780a Mon Sep 17 00:00:00 2001 From: Enrico Minack Date: Mon, 25 Aug 2025 15:55:05 +0200 Subject: [PATCH 3/3] Fix linting --- scripts/openapi.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/openapi.py b/scripts/openapi.py index 67711fb282..14d0ca0664 100644 --- a/scripts/openapi.py +++ b/scripts/openapi.py @@ -193,7 +193,9 @@ def full_class_name(self) -> str: return f"{self.package}.{self.module}.{self.name}" @staticmethod - def from_class_name(class_name: str, index: dict[str, Any] | None = None, github_parent_path: str = "") -> GithubClass: + def from_class_name( + class_name: str, index: dict[str, Any] | None = None, github_parent_path: str = "" + ) -> GithubClass: if github_parent_path and not github_parent_path.endswith("/"): github_parent_path = f"{github_parent_path}/" if "." in class_name: @@ -229,7 +231,9 @@ def from_class_name(class_name: str, index: dict[str, Any] | None = None, github raise KeyError(f"Missing package, module or name in {cls}") return GithubClass(**cls) else: - return GithubClass.from_class_name(f"github.{class_name}.{class_name}", github_parent_path=github_parent_path) + return GithubClass.from_class_name( + f"github.{class_name}.{class_name}", github_parent_path=github_parent_path + ) @dataclasses.dataclass(frozen=True)