MCPcopy Index your code
hub / github.com/RustPython/RustPython / main

Function main

scripts/generate_sre_constants.py:86–133  ·  view source on GitHub ↗
(
    infile="Lib/re/_constants.py",
    outfile_constants="crates/sre_engine/src/constants.rs",
)

Source from the content-addressed store, hash-verified

84
85
86def main(
87 infile="Lib/re/_constants.py",
88 outfile_constants="crates/sre_engine/src/constants.rs",
89):
90 ns = {}
91 with open(infile) as fp:
92 code = fp.read()
93 exec(code, ns)
94
95 content = [sre_constants_header]
96 content.append("use bitflags::bitflags;\n\n")
97 content.append(f"pub const SRE_MAGIC: usize = {ns['MAGIC']};\n")
98 content.extend(
99 dump_enum(
100 ns["OPCODES"],
101 "SreOpcode",
102 "#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]",
103 )
104 )
105 content.extend(
106 dump_enum(
107 ns["ATCODES"],
108 "SreAtCode",
109 "#[derive(num_enum::TryFromPrimitive, Debug, PartialEq, Eq)]",
110 "AT_",
111 )
112 )
113 content.extend(
114 dump_enum(
115 ns["CHCODES"],
116 "SreCatCode",
117 "#[derive(num_enum::TryFromPrimitive, Debug)]",
118 "CATEGORY_",
119 )
120 )
121
122 content.extend(
123 dump_bitflags(
124 ns,
125 "SRE_FLAG_",
126 "#[derive(Debug, PartialEq, Eq, Clone, Copy)]",
127 "SreFlag",
128 "u16",
129 )
130 )
131 content.extend(dump_bitflags(ns, "SRE_INFO_", "", "SreInfo", "u32"))
132
133 update_file(outfile_constants, "".join(content))
134
135
136if __name__ == "__main__":

Callers 1

Calls 9

dump_enumFunction · 0.85
dump_bitflagsFunction · 0.85
update_fileFunction · 0.85
openFunction · 0.50
execFunction · 0.50
readMethod · 0.45
appendMethod · 0.45
extendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected