Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 12179a8

Browse files
committed
Changed the ignore functionality so individual lines in files can be ignored
1 parent 572eff9 commit 12179a8

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/python3_pip_skeleton/__main__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pathlib import Path
66
from subprocess import STDOUT, CalledProcessError, call, check_output
77
from tempfile import TemporaryDirectory
8-
from typing import List
8+
from typing import Dict, List
99

1010
from . import __version__
1111

@@ -17,12 +17,15 @@
1717
MERGE_BRANCH = "skeleton-merge-branch"
1818
# Extensions to change
1919
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+
}
2629

2730
SKELETON_ROOT_COMMIT = "ededf00035e6ccfac78946213009c1ecd7c110a9"
2831

@@ -98,6 +101,19 @@ def replace_text(text: str) -> str:
98101
if child.suffix in CHANGE_SUFFIXES and child.name not in IGNORE_FILES:
99102
text = replace_text(child.read_text())
100103
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+
101117
# Commit what we have and push to the original repo
102118
git_tmp("commit", "-a", "-m", f"Rename python3-pip-skeleton -> {repo}")
103119
git_tmp("push", "origin", MERGE_BRANCH)

0 commit comments

Comments
 (0)