(
self,
github_path: str,
spec_file: str,
index_filename: str,
class_names: list[str] | None,
dry_run: bool,
tests: bool,
handle_new_schemas: HandleNewSchemas,
)
| 2096 | return True |
| 2097 | |
| 2098 | def apply( |
| 2099 | self, |
| 2100 | github_path: str, |
| 2101 | spec_file: str, |
| 2102 | index_filename: str, |
| 2103 | class_names: list[str] | None, |
| 2104 | dry_run: bool, |
| 2105 | tests: bool, |
| 2106 | handle_new_schemas: HandleNewSchemas, |
| 2107 | ) -> bool: |
| 2108 | print(f"Using spec {spec_file}") |
| 2109 | with open(spec_file) as r: |
| 2110 | spec = json.load(r) |
| 2111 | with open(index_filename) as r: |
| 2112 | index = json.load(r) |
| 2113 | classes = index.get("classes", {}) |
| 2114 | |
| 2115 | if not class_names: |
| 2116 | class_names = classes.keys() |
| 2117 | if len(class_names) == 1: |
| 2118 | print(f"Applying API schemas to PyGithub class {class_names[0]}") |
| 2119 | else: |
| 2120 | print(f"Applying API schemas to {len(class_names)} PyGithub classes") |
| 2121 | |
| 2122 | new_schemas_as_dict = handle_new_schemas == HandleNewSchemas.as_dict |
| 2123 | new_schemas_create_class = handle_new_schemas == HandleNewSchemas.create_class |
| 2124 | any_change = False |
| 2125 | for class_name in class_names: |
| 2126 | clazz = GithubClass.from_class_name(class_name, index) |
| 2127 | |
| 2128 | print(f"Applying spec {spec_file} to {clazz.full_class_name} ({clazz.filename})") |
| 2129 | cls = classes.get(clazz.short_class_name, {}) |
| 2130 | irrelevant_bases = { |
| 2131 | inheritance |
| 2132 | for base in ["GithubObject", "CompletableGithubObject", "NonCompletableGithubObject"] |
| 2133 | for inheritance in classes.get(base, {}).get("inheritance", []) |
| 2134 | } |
| 2135 | relevant_bases = set(cls.get("inheritance", [])).difference(irrelevant_bases) |
| 2136 | inherited_properties = { |
| 2137 | property for base in relevant_bases for property in classes.get(base, {}).get("properties", {}).keys() |
| 2138 | } |
| 2139 | completable = "CompletableGithubObject" in cls.get("inheritance", []) |
| 2140 | cls_schemas = cls.get("schemas", []) |
| 2141 | cls_properties = cls.get("properties", []) |
| 2142 | class_change = False |
| 2143 | test_change = False |
| 2144 | for schema_name in cls_schemas: |
| 2145 | print(f"Applying schema {schema_name}") |
| 2146 | schema_path, schema = self.get_schema(spec, schema_name) |
| 2147 | |
| 2148 | if new_schemas_create_class: |
| 2149 | new_schemas = [] |
| 2150 | for k, v in schema.get("properties", {}).items(): |
| 2151 | # only check for new schemas of new attributes |
| 2152 | if k not in cls_properties: |
| 2153 | self.as_python_type(v, schema_path + ["properties", k], collect_new_schemas=new_schemas) |
| 2154 | # handle new schemas |
| 2155 | for new_schema in new_schemas: |
no test coverage detected