MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / process_module

Function process_module

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

Source from the content-addressed store, hash-verified

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