MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / run_file

Function run_file

tools/normalize_file_headers.py:26–47  ·  view source on GitHub ↗
(cmd: code_writer_cmd, file: Path, update_year: bool)

Source from the content-addressed store, hash-verified

24
25
26def run_file(cmd: code_writer_cmd, file: Path, update_year: bool):
27 content = file.read_text("utf-8")
28 path = str(file.relative_to(sa_path)).replace("\\", "/") # handle windows
29 path_comment = f"# {path}"
30 has_license = bool(license_re.search(content))
31 if file_re.match(content.strip()):
32 if has_license:
33 to_sub = path_comment
34 else:
35 to_sub = path_comment + license_
36 content = file_re.sub(to_sub, content, count=1)
37 else:
38 content = path_comment + ("\n" if has_license else license_) + content
39
40 if has_license and update_year:
41 content = license_re.sub(
42 rf"Copyright (C) \1-{this_year} the SQLAlchemy "
43 "authors and contributors",
44 content,
45 1,
46 )
47 cmd.write_output_file_from_text(content, file)
48
49
50def run(cmd: code_writer_cmd, update_year: bool):

Callers 1

runFunction · 0.70

Calls 5

stripMethod · 0.80
subMethod · 0.80
replaceMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected