Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/python3_pip_skeleton/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def merge_skeleton(
org: str,
full_name: str,
email: str,
from_branch: str,
package,
):
path = path.resolve()
Expand All @@ -63,6 +64,7 @@ def replace_text(text: str) -> str:
text = text.replace("python3_pip_skeleton", package)
text = text.replace("Firstname Lastname", full_name)
text = text.replace("email@address.com", email)
text = text.replace("main", from_branch)
return text

branches = list_branches(path)
Expand All @@ -82,7 +84,7 @@ def replace_text(text: str) -> str:
# will do the wrong thing
shutil.rmtree(git_tmp / "src", ignore_errors=True)
# Merge in the skeleton commits
git_tmp("pull", "--rebase=false", SKELETON, "main")
git_tmp("pull", "--rebase=false", SKELETON, from_branch)
# Move things around
if package != "python3_pip_skeleton":
git_tmp("mv", "src/python3_pip_skeleton", f"src/{package}")
Expand Down Expand Up @@ -156,6 +158,7 @@ def new(args):
org=args.org,
full_name=args.full_name or git("config", "--get", "user.name").strip(),
email=args.email or git("config", "--get", "user.email").strip(),
from_branch=args.from_branch or "main",
package=package,
)

Expand Down Expand Up @@ -188,6 +191,7 @@ def existing(args):
org=args.org,
full_name=conf["metadata"]["author"],
email=conf["metadata"]["author_email"],
from_branch=args.from_branch or "main",
package=package,
)

Expand Down Expand Up @@ -225,6 +229,11 @@ def main(args=None):
sub.add_argument(
"--email", default=None, help="Email address, defaults to git config user.email"
)
sub.add_argument(
"--from-branch",
default=None,
help="Merge from skeleton branch, defaults to main",
)
# Add a command for adopting in existing repo
sub = subparsers.add_parser("existing", help="Adopt skeleton in existing repo")
sub.set_defaults(func=existing)
Expand All @@ -234,6 +243,11 @@ def main(args=None):
sub.add_argument(
"--package", default=None, help="Package name, defaults to directory name"
)
sub.add_argument(
"--from-branch",
default=None,
Comment thread
AlexanderWells-diamond marked this conversation as resolved.
help="Merge from skeleton branch, defaults to main",
)
# Add a command for cleaning an existing repo of skeleton code
sub = subparsers.add_parser(
"clean", help="Clean up branch from failed skeleton merge"
Expand Down
63 changes: 63 additions & 0 deletions tests/test_adopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,45 @@ def test_new_module_existing_dir(tmp_path: Path):
assert "to not exist, or be an empty dir" in str(excinfo.value)


def test_new_module_merge_from_valid_branch(tmp_path: Path):
module = tmp_path / "my-module"
check_output(
sys.executable,
"-m",
"python3_pip_skeleton",
"new",
"--org=myorg",
"--package=my_module",
"--full-name=Firstname Lastname",
"--email=me@myaddress.com",
"--from-branch=main",
str(module),
)
# Test basic functionality
assert (module / "src" / "my_module").is_dir()
check_output("python", "-m", "venv", "venv", cwd=module)
check_output("venv/bin/pip", "install", ".[dev]", cwd=module)


def test_new_module_merge_from_invalid_branch(tmp_path: Path):
module = tmp_path / "my-module"

with pytest.raises(ValueError) as excinfo:
check_output(
sys.executable,
"-m",
"python3_pip_skeleton",
"new",
"--org=myorg",
"--package=my_module",
"--full-name=Firstname Lastname",
"--email=me@myaddress.com",
"--from-branch=fail",
str(module),
)
assert "couldn't find remote ref fail" in str(excinfo.value)


def test_existing_module(tmp_path: Path):
module = tmp_path / "scanspec"
__main__.git(
Expand Down Expand Up @@ -169,3 +208,27 @@ def test_existing_module_already_adopted(tmp_path: Path):
str(module),
)
assert "already adopted skeleton" in str(excinfo.value)


def test_existing_module_merge_from_invalid_branch(tmp_path: Path):
module = tmp_path / "scanspec"
__main__.git(
"clone",
"--depth",
"1",
"--branch",
"0.5.3",
"https://github.com/dls-controls/scanspec",
str(module),
)
with pytest.raises(ValueError) as excinfo:
check_output(
sys.executable,
"-m",
"python3_pip_skeleton",
"existing",
"--org=epics-containers",
"--from-branch=fail",
str(module),
)
assert "couldn't find remote ref fail" in str(excinfo.value)