Created
June 23, 2020 22:11
-
-
Save Qalthos/ddcc0e0b7ddb43429cb4437db4cd5b5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def slurp_file(filename): | |
with open(filename) as file_obj: | |
return file_obj.readlines() | |
def main(): | |
lines = slurp_file("tests/sanity/ignore-2.9.txt") | |
# lines = slurp_file("tests/sanity/ignore-2.10.txt") | |
future = [] | |
meta = [] | |
for line in lines: | |
filename, test = line.strip().split(" ", 1) | |
if test == "future-import-boilerplate": | |
future.append(filename) | |
if test == "metaclass-boilerplate": | |
meta.append(filename) | |
print(f"Found {len(future)} future and {len(meta)} meta") | |
for filename in future: | |
print(f"Reading {filename}") | |
lines = slurp_file(filename) | |
for index, line in enumerate(lines): | |
if not line.startswith("#"): | |
lines.insert(index, "from __future__ import absolute_import, division, print_function\n") | |
break | |
with open(filename, "w") as file_obj: | |
file_obj.writelines(lines) | |
for filename in meta: | |
print(f"Reading {filename}") | |
lines = slurp_file(filename) | |
for index, line in enumerate(lines): | |
if line.startswith("from __future__"): | |
lines.insert(index + 1, "__metaclass__ = type\n") | |
lines.insert(index + 1, "\n") | |
break | |
with open(filename, "w") as file_obj: | |
file_obj.writelines(lines) | |
# Run sed -i -e '/.*boilerplate/d' tests/sanity/ignore-2.* | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment