(modname: str, filename: str, cmd: code_writer_cmd)
| 371 | |
| 372 | |
| 373 | def 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 | |
| 415 | def run_module(modname: str, cmd: code_writer_cmd) -> None: |
no test coverage detected