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

Commit a371869

Browse files
GDYendellgilesknap
authored andcommitted
Add check that skeleton is not already adopted
1 parent a30a40e commit a371869

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/dls_python3_skeleton/__main__.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from argparse import ArgumentParser
44
from configparser import ConfigParser
55
from pathlib import Path
6-
from subprocess import STDOUT, CalledProcessError, check_output
6+
from subprocess import STDOUT, CalledProcessError, call, check_output
77
from tempfile import TemporaryDirectory
88
from typing import List
99

@@ -27,6 +27,7 @@
2727
"https://github.com/dls-controls/versiongit",
2828
),
2929
}
30+
SKELETON_ROOT_COMMIT = "ededf00035e6ccfac78946213009c1ecd7c110a9"
3031

3132

3233
def git(*args, cwd=None) -> str:
@@ -139,6 +140,25 @@ def validate_package(args) -> str:
139140
return package
140141

141142

143+
def verify_not_adopted(root: Path):
144+
"""Verify that module has not already adopted skeleton"""
145+
146+
# This call does not print anything - the return code is 0 if it is an ancestor
147+
not_adopted = call( # 0 -> adopted and 1 -> not adopted, so invert here
148+
[
149+
"git",
150+
"-C",
151+
f"{root}",
152+
"merge-base",
153+
"--is-ancestor",
154+
SKELETON_ROOT_COMMIT,
155+
"HEAD",
156+
]
157+
)
158+
159+
assert not_adopted, f"Package {root} has already adopted skeleton"
160+
161+
142162
def new(args):
143163
path: Path = args.path
144164

@@ -175,6 +195,8 @@ def existing(args):
175195
package = validate_package(args)
176196
file_path: Path = path / "setup.cfg"
177197
assert file_path.is_file(), "Expected a setup.cfg file in the directory."
198+
verify_not_adopted(args.path)
199+
178200
conf = ConfigParser()
179201
conf.read(path / "setup.cfg")
180202
assert "metadata" in conf, cfg_issue

tests/test_dls_python3_skeleton.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,23 @@ def test_existing_module(tmp_path: Path):
125125
assert output.strip("\n") == f"{MERGE_BRANCH} deleted from existing repo"
126126
branches = __main__.list_branches(module)
127127
assert MERGE_BRANCH not in branches
128+
129+
130+
def test_existing_module_already_adopted(tmp_path: Path):
131+
module = tmp_path / "scanspec"
132+
__main__.git(
133+
"clone",
134+
"--branch",
135+
"0.5.4", # dls-python3-skeleton was adopted in this release
136+
"https://github.com/dls-controls/scanspec",
137+
str(module),
138+
)
139+
with pytest.raises(Exception) as excinfo:
140+
check_output(
141+
sys.executable,
142+
"-m",
143+
"dls_python3_skeleton",
144+
"existing",
145+
str(module),
146+
)
147+
assert "already adopted skeleton" in str(excinfo.value)

0 commit comments

Comments
 (0)