|
16 | 16 | import keyword |
17 | 17 | from argparse import ArgumentParser |
18 | 18 | from functools import cached_property |
| 19 | +from itertools import dropwhile |
19 | 20 | from pathlib import Path |
20 | 21 | from re import Pattern |
21 | 22 | from re import compile as regex_compile |
|
95 | 96 | 'link-watchers': 'LinkWatchers', |
96 | 97 | } |
97 | 98 |
|
| 99 | +setting_name_replacement: dict[str, str] = { |
| 100 | + 'x': 'eapol', |
| 101 | +} |
| 102 | + |
98 | 103 |
|
99 | 104 | def must_replace_name(name: str) -> bool: |
100 | 105 | return (keyword.iskeyword(name) |
@@ -143,15 +148,32 @@ def __init__(self, name: str, description: str, name_upper: str, |
143 | 148 | self.name = name |
144 | 149 | self.description = description |
145 | 150 | self.name_upper = name_upper |
146 | | - self.python_class_name = name.capitalize() + 'Settings' |
147 | 151 |
|
148 | 152 | self.typing_imports = {'Optional'} |
149 | 153 |
|
150 | 154 | self.properties: List[NmSettingPropertyIntrospection] = [] |
151 | 155 |
|
| 156 | + @cached_property |
| 157 | + def python_class_name(self) -> str: |
| 158 | + |
| 159 | + camel_case = ''.join( |
| 160 | + map(str.title, self.snake_name.split('_')) |
| 161 | + ) |
| 162 | + |
| 163 | + return camel_case + 'Settings' |
| 164 | + |
152 | 165 | @cached_property |
153 | 166 | def snake_name(self) -> str: |
154 | | - return self.name_upper.lower() |
| 167 | + underscore_name = self.name.replace('-', '_') |
| 168 | + |
| 169 | + no_first_digits_name = ''.join( |
| 170 | + dropwhile( |
| 171 | + lambda s: not str.isalpha(s), underscore_name)) |
| 172 | + |
| 173 | + return setting_name_replacement.get( |
| 174 | + no_first_digits_name, |
| 175 | + no_first_digits_name, |
| 176 | + ) |
155 | 177 |
|
156 | 178 | @cached_property |
157 | 179 | def datatypes_imports(self) -> list[str]: |
|
0 commit comments