Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions scripts/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ 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)
Expand All @@ -208,8 +212,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={},
Expand All @@ -227,7 +231,9 @@ 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)
Expand Down Expand Up @@ -2666,7 +2672,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):
Expand Down
2 changes: 2 additions & 0 deletions scripts/sort_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down
Loading