Skip to content

Commit

Permalink
{release,config}.py: consistently treat --{only,exclude}
Browse files Browse the repository at this point in the history
fixes #35
  • Loading branch information
suvayu committed Oct 2, 2024
1 parent 71b7cb3 commit b60b7a1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
8 changes: 2 additions & 6 deletions orchestra/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ def release(
),
):
"""Tag releases for all packages."""
conf = read_conf(f"{config}")
if only and exclude:
raise BadArgumentUsage("`--only` and `--exclude` are mutually exclusive")
elif exclude:
only = [pkg for pkg in conf["repos"].keys() if pkg not in exclude]
make_release(conf, bump_version, output, only)
conf = read_conf(f"{config}", only=only, exclude=exclude)
make_release(conf, bump_version, output)


@cli.command()
Expand Down
15 changes: 14 additions & 1 deletion orchestra/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
from typing import Any

from click.exceptions import BadArgumentUsage
from rich.console import Console
import tomlkit

Expand Down Expand Up @@ -38,7 +39,7 @@ def check_pkgnames(CONF: dict[str, Any], key: str) -> str:
return msg.format(f"{', '.join(unk)}") if len(unk) > 0 else ""


def read_conf(path: str) -> dict:
def read_conf(path: str, /, only: list[str] = [], exclude: list[str] = []) -> dict:
CONF = deepcopy(_CONF)
config = read_toml(path)
if "tool" in config and "conductor" in config["tool"]:
Expand Down Expand Up @@ -83,4 +84,16 @@ def read_conf(path: str) -> dict:
branches = CONF["branches"] if "branches" in CONF else {}
CONF["branches"].update({**branches_default, **branches})

if only and exclude:
raise BadArgumentUsage("`--only` and `--exclude` are mutually exclusive")
elif exclude:
only = [pkg for pkg in config["repos"].keys() if pkg not in exclude]

if len(only) > 0:
CONF["repos"] = {pkg: CONF["repos"][pkg] for pkg in only}
branches = {
pkg: branch for pkg, branch in CONF["branches"].items() if pkg in only
}
CONF["branches"] = branches

return CONF
9 changes: 2 additions & 7 deletions orchestra/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,9 @@ def create_tags(
return summary


def make_release(
CONF: dict, bump_version: VersionPart, output: Path, only: list[str] = []
):
def make_release(CONF: dict, bump_version: VersionPart, output: Path):
"""Make release tag for all packages, and print a summary."""
branches = CONF["branches"]
if len(only) > 0:
CONF["repos"] = {pkg: CONF["repos"][pkg] for pkg in only}
branches = {pkg: branches[pkg] for pkg in only}
try:
check_current_branch(CONF["repos"], branches)
except RuntimeError as err:
Expand Down Expand Up @@ -373,6 +368,6 @@ def main(
only: list[str] = [],
):
CONF = read_conf(f"{config}")
make_release(CONF, bump_version, output, only)
make_release(CONF, bump_version, output)

typer.run(main)
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pathlib import Path

from click.exceptions import BadArgumentUsage
import pytest

from orchestra.config import read_conf


@pytest.mark.parametrize("pkg", ["sa-bar", "sa-foo"])
def test_read_conf(pkg):
conf_file = Path(__file__).parent / "scm.toml"

conf = read_conf(f"{conf_file}", only=[pkg])
assert list(conf["repos"]) == [pkg]
assert list(conf["branches"]) == [pkg]

conf = read_conf(f"{conf_file}", exclude=[pkg])
assert pkg not in list(conf["repos"])
assert pkg not in list(conf["branches"])

with pytest.raises(BadArgumentUsage, match="mutually exclusive"):
read_conf(f"{conf_file}", only=[pkg], exclude=[pkg])

0 comments on commit b60b7a1

Please sign in to comment.