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

Commit f388790

Browse files
committed
Don't change versiongit URL in api.rst
1 parent 29ec0cc commit f388790

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/dls_python3_skeleton/__main__.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
CHANGE_SUFFIXES = [".py", ".rst", ".cfg", ""]
1919
# Files not to change
2020
IGNORE_FILES = ["CHANGELOG.rst", "test_boilerplate_removed.py", "_version_git.py"]
21-
# Markers to ignore from
22-
IGNORE_MARKERS = {"CONTRIBUTING.rst": "\nUpdating the tools\n"}
21+
# Ranges to ignore between
22+
IGNORE_RANGES = {
23+
"CONTRIBUTING.rst": ("\nUpdating the tools\n", None),
24+
"api.rst": (
25+
"Version number as calculated by",
26+
"https://github.com/dls-controls/versiongit",
27+
),
28+
}
2329

2430

2531
def git(*args, cwd=None) -> str:
@@ -54,6 +60,15 @@ def merge_skeleton(
5460
package = override_package or repo
5561
valid = re.match("[a-zA-Z][a-zA-Z_0-9]*$", package)
5662
assert valid, f"'{package}' is not a valid python package name"
63+
64+
def replace_text(text: str) -> str:
65+
text = text.replace("dls-controls", org)
66+
text = text.replace("dls-python3-skeleton", repo)
67+
text = text.replace("dls_python3_skeleton", package)
68+
text = text.replace("Firstname Lastname", full_name)
69+
text = text.replace("[email protected]", email)
70+
return text
71+
5772
with GitTemporaryDirectory() as git_tmp:
5873
# Clone existing repo into tmp so we don't mess up if we fail
5974
# half way through
@@ -75,17 +90,25 @@ def merge_skeleton(
7590
child = Path(git_tmp.name) / relative_child
7691
if child.suffix in CHANGE_SUFFIXES and child.name not in IGNORE_FILES:
7792
text = child.read_text()
78-
marker = IGNORE_MARKERS.get(child.name, "")
79-
if marker:
80-
text, marker, ignore = text.partition(marker)
93+
start_search, end_search = IGNORE_RANGES.get(child.name, (None, None))
94+
if start_search:
95+
start_ignore = text.find(start_search)
96+
assert start_ignore > 0, f"{start_search} not in {child.name}"
97+
if end_search:
98+
end_ignore = text.find(end_search, start_ignore) + len(
99+
end_search
100+
)
101+
assert end_ignore > 0, f"{end_search} not in {child.name}"
102+
else:
103+
end_ignore = len(text)
81104
else:
82-
ignore = ""
83-
text = text.replace("dls-controls", org)
84-
text = text.replace("dls-python3-skeleton", repo)
85-
text = text.replace("dls_python3_skeleton", package)
86-
text = text.replace("Firstname Lastname", full_name)
87-
text = text.replace("[email protected]", email)
88-
child.write_text(text + marker + ignore)
105+
start_ignore = 0
106+
end_ignore = 0
107+
child.write_text(
108+
replace_text(text[:start_ignore])
109+
+ text[start_ignore:end_ignore]
110+
+ replace_text(text[end_ignore:])
111+
)
89112
# Commit what we have and push to the original repo
90113
git_tmp("commit", "-a", "-m", f"Rename dls-python3-skeleton -> {repo}")
91114
git_tmp("push", "origin", MERGE_BRANCH)

tests/test_dls_python3_skeleton.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def test_new_module(tmp_path: Path):
2929
"-m",
3030
"dls_python3_skeleton",
3131
"new",
32+
"--org=myorg",
3233
"--package=my_module",
3334
"--full-name=Firstname Lastname",
3435
@@ -42,6 +43,15 @@ def test_new_module(tmp_path: Path):
4243
conf.read(module / "setup.cfg")
4344
assert conf["metadata"]["author"] == "Firstname Lastname"
4445
assert conf["metadata"]["author_email"] == "[email protected]"
46+
versiongit_lines = [
47+
line
48+
for line in (module / "docs" / "reference" / "api.rst").read_text().splitlines()
49+
if "versiongit" in line
50+
]
51+
assert (
52+
" Version number as calculated by https://github.com/dls-controls/versiongit"
53+
in versiongit_lines
54+
)
4555
assert (module / "src" / "my_module").is_dir()
4656
assert check_output("git", "branch", cwd=module).strip() == "* master"
4757
check_output("pipenv", "install", "--dev", cwd=module)

0 commit comments

Comments
 (0)