MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / process_module

Function process_module

tools/generate_proxy_methods.py:361–400  ·  view source on GitHub ↗
(modname: str, filename: str, cmd: code_writer_cmd)

Source from the content-addressed store, hash-verified

359
360
361def process_module(modname: str, filename: str, cmd: code_writer_cmd) -> str:
362 class_entries = classes[modname]
363
364 # use tempfile in same path as the module, or at least in the
365 # current working directory, so that black / zimports use
366 # local pyproject.toml
367 with (
368 NamedTemporaryFile(
369 mode="w",
370 delete=False,
371 suffix=".py",
372 ) as buf,
373 open(filename) as orig_py,
374 ):
375 in_block = False
376 current_clsname = None
377 for line in orig_py:
378 m = re.match(r" # START PROXY METHODS (.+)$", line)
379 if m:
380 current_clsname = m.group(1)
381 args = class_entries[current_clsname]
382 cmd.write_status(
383 f"Generating attributes for class {current_clsname}\n"
384 )
385 in_block = True
386 buf.write(line)
387 buf.write(
388 "\n # code within this block is "
389 "**programmatically, \n"
390 " # statically generated** by"
391 f" tools/{os.path.basename(__file__)}\n\n"
392 )
393
394 process_class(buf, *args)
395 if line.startswith(f" # END PROXY METHODS {current_clsname}"):
396 in_block = False
397
398 if not in_block:
399 buf.write(line)
400 return buf.name
401
402
403def run_module(modname: str, cmd: code_writer_cmd) -> None:

Callers 1

run_moduleFunction · 0.70

Calls 6

openFunction · 0.85
process_classFunction · 0.85
write_statusMethod · 0.80
matchMethod · 0.45
writeMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected