|
5 | 5 | from pathlib import Path |
6 | 6 | from subprocess import STDOUT, CalledProcessError, call, check_output |
7 | 7 | from tempfile import TemporaryDirectory |
8 | | -from typing import List |
| 8 | +from typing import Dict, List |
9 | 9 |
|
10 | 10 | from . import __version__ |
11 | 11 |
|
|
17 | 17 | MERGE_BRANCH = "skeleton-merge-branch" |
18 | 18 | # Extensions to change |
19 | 19 | CHANGE_SUFFIXES = [".py", ".rst", ".cfg", "", ".toml"] |
20 | | -# Files not to change |
21 | | -IGNORE_FILES = [ |
22 | | - "update-tools.rst", |
23 | | - "test_boilerplate_removed.py", |
24 | | - "pin-requirements.rst", |
25 | | -] |
| 20 | +# Files not to change where IGNORE_FILES[x] is a list containing line numbers |
| 21 | +# in the file x to be ignored. An empty list will ignore the whole file. |
| 22 | +IGNORE_FILES: Dict[str, List[int]] = { |
| 23 | + "update-tools.rst": [], |
| 24 | + "test_boilerplate_removed.py": [], |
| 25 | + "pin-requirements.rst": [], |
| 26 | + "0002-switched-to-pip-skeleton.rst:": [], |
| 27 | + "README.rst": [10], |
| 28 | +} |
26 | 29 |
|
27 | 30 | SKELETON_ROOT_COMMIT = "ededf00035e6ccfac78946213009c1ecd7c110a9" |
28 | 31 |
|
@@ -98,6 +101,19 @@ def replace_text(text: str) -> str: |
98 | 101 | if child.suffix in CHANGE_SUFFIXES and child.name not in IGNORE_FILES: |
99 | 102 | text = replace_text(child.read_text()) |
100 | 103 | child.write_text(text) |
| 104 | + # Replace the file, ignoring line numbers |
| 105 | + elif ( |
| 106 | + child.suffix in CHANGE_SUFFIXES |
| 107 | + and child.name in IGNORE_FILES |
| 108 | + and IGNORE_FILES[child.name] |
| 109 | + ): |
| 110 | + original_text = child.read_text() |
| 111 | + original_lines = original_text.splitlines() |
| 112 | + replaced_lines = replace_text(original_text).splitlines() |
| 113 | + for ignored_line in IGNORE_FILES[child.name]: |
| 114 | + replaced_lines[ignored_line - 1] = original_lines[ignored_line - 1] |
| 115 | + child.write_text("\n".join(replaced_lines)) |
| 116 | + |
101 | 117 | # Commit what we have and push to the original repo |
102 | 118 | git_tmp("commit", "-a", "-m", f"Rename python3-pip-skeleton -> {repo}") |
103 | 119 | git_tmp("push", "origin", MERGE_BRANCH) |
|
0 commit comments