|
52 | 52 | print(file=f) |
53 | 53 | for enumname in sorted(enums): |
54 | 54 | if enumname.lower().startswith('tidy'): |
55 | | - print(f" ctypedef struct __Enum__{enumname}", file=f) |
| 55 | + print(" ctypedef struct __Enum__", enumname, file=f, sep='') |
56 | 56 |
|
57 | 57 | print(file=f) |
58 | 58 | for enumname in sorted(enums): |
59 | 59 | if enumname.lower().startswith('tidy'): |
60 | | - print(f" ctypedef __Enum__{enumname} *{enumname} {enumname!r}", file=f) |
| 60 | + print(" ctypedef __Enum__", enumname, " *", enumname, " ", repr(enumname), file=f, sep='') |
61 | 61 |
|
62 | 62 | for enumname, definition in sorted(enums.items()): |
63 | 63 | if enumname.lower().startswith('tidy'): |
64 | 64 | print(file=f) |
65 | 65 | for valuename in sorted(definition['values']): |
66 | | - print(f" const {enumname} {valuename}", file=f) |
| 66 | + print(" const ", enumname, " ", valuename, file=f, sep='') |
67 | 67 |
|
68 | 68 |
|
69 | 69 | clsnames = { |
|
88 | 88 |
|
89 | 89 | with open(join(root, 'lib', '_tidy_enum.pyx'), 'wt') as f: |
90 | 90 | print("# GENERATED FILE: all modifications will be overwritten.", file=f) |
| 91 | + |
91 | 92 | print(file=f) |
92 | | - for clsname in sorted(clsnames): |
93 | | - print(f'cdef type _{clsname}', file=f) |
| 93 | + for clsname, (prefix, suffix, enumname) in sorted(clsnames.items()): |
| 94 | + print("cdef object _", clsname, file=f, sep='') |
| 95 | + |
| 96 | + print(file=f) |
| 97 | + for clsname, (prefix, suffix, enumname) in sorted(clsnames.items()): |
| 98 | + print("global ", clsname, file=f, sep='') |
94 | 99 |
|
| 100 | + print(file=f) |
95 | 101 | for clsname in sorted(clsnames): |
96 | 102 | print(file=f) |
97 | | - print(file=f) |
98 | | - print(f"cdef object {underscore(clsname)}_for_name(name):", file=f) |
99 | | - print(f" return _generic_id_for_name(_{clsname}, name)", file=f) |
| 103 | + print("cdef object ", underscore(clsname), "_for_name(name):", file=f, sep='') |
| 104 | + print(" return _generic_id_for_name(_", clsname, ", name)", file=f, sep='') |
100 | 105 |
|
101 | 106 | for clsname, (prefix, suffix, enumname) in sorted(clsnames.items()): |
| 107 | + definition = enums[enumname] |
| 108 | + |
102 | 109 | print(file=f) |
103 | 110 | print(file=f) |
104 | | - print(f"class _{clsname}(IntEnum):", file=f) |
105 | | - print(f" __name__ = __qualname__ = {clsname!r}", file=f) |
106 | | - print(f" for_name = staticmethod({underscore(clsname)}_for_name)", file=f) |
107 | | - print(file=f) |
108 | | - definition = enums[enumname] |
| 111 | + print("_", clsname, " = IntEnum(", repr(clsname), ", {", file=f, sep='') |
109 | 112 | for valuename in sorted(definition['values']): |
110 | 113 | pretty_name = valuename |
111 | 114 | if prefix and pretty_name.startswith(prefix): |
112 | 115 | pretty_name = pretty_name[len(prefix):] |
113 | 116 | if suffix and pretty_name.endswith(suffix): |
114 | 117 | pretty_name = pretty_name[:-len(suffix)] |
115 | 118 | pretty_name = underscore(pretty_name) |
| 119 | + |
| 120 | + if pretty_name.startswith('n_tidy_'): |
| 121 | + continue |
| 122 | + |
116 | 123 | if iskeyword(pretty_name): |
117 | 124 | pretty_name = f'{pretty_name}_' |
118 | 125 |
|
119 | | - print(f" {pretty_name} = <{definition['type']}> {valuename}", file=f) |
| 126 | + print(" ", repr(pretty_name), ": <", definition['type'], "> ", valuename, ",", file=f, sep='') |
120 | 127 |
|
121 | | - print(file=f) |
122 | | - print(file=f) |
123 | | - for clsname in sorted(clsnames): |
124 | | - print(f"{clsname} = _{clsname}", file=f) |
| 128 | + print("})", file=f) |
| 129 | + print(file=f) |
| 130 | + print("_", clsname, ".for_name = ", underscore(clsname), "_for_name", file=f, sep='') |
| 131 | + print(file=f) |
| 132 | + print(clsname, " = _", clsname, file=f, sep='') |
0 commit comments