scriv-release 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yuichiro Tachibana (Tsuchiya)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: scriv-release
3
+ Version: 0.2.2
4
+ Summary: Changesets-style release automation on top of scriv
5
+ Author: Yuichiro Tachibana (Tsuchiya)
6
+ Author-email: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Build Tools
13
+ Requires-Dist: scriv>=1.7
14
+ Requires-Dist: tomli>=2.0 ; python_full_version < '3.11'
15
+ Requires-Dist: scriv-release[bump-my-version,hatch] ; extra == 'all'
16
+ Requires-Dist: bump-my-version>=0.28 ; extra == 'bump-my-version'
17
+ Requires-Dist: hatch>=1.12 ; extra == 'hatch'
18
+ Requires-Python: >=3.10
19
+ Project-URL: Homepage, https://github.com/whitphx/scriv-release
20
+ Project-URL: Issues, https://github.com/whitphx/scriv-release/issues
21
+ Provides-Extra: all
22
+ Provides-Extra: bump-my-version
23
+ Provides-Extra: hatch
24
+ Description-Content-Type: text/markdown
25
+
26
+ # scriv-release
27
+
28
+ Changesets-style release automation on top of [`scriv`](https://github.com/nedbat/scriv).
29
+
30
+ `scriv` already manages per-PR changelog fragments. `scriv-release` adds the missing pieces for fully automated releases:
31
+
32
+ 1. A **policy** for mapping changelog categories to semver bump levels.
33
+ 2. **Orchestration** commands (`bump-level`, `next-version`, `collect`, `tag`) that wrap `scriv` and a configurable version provider.
34
+ 3. A **GitHub Action** that opens a "Changelog Preview" PR when fragments are pending, and tags a release once that PR is merged — the same flow popularized by [Changesets](https://github.com/changesets/changesets) in the JS ecosystem.
35
+
36
+ ## Quickstart
37
+
38
+ ```bash
39
+ pip install "scriv-release[bump-my-version]"
40
+ ```
41
+
42
+ ```toml
43
+ # pyproject.toml
44
+ [tool.scriv-release]
45
+ version_provider = "bump-my-version"
46
+ ```
47
+
48
+ In your repo's `.github/workflows/release.yml`:
49
+
50
+ ```yaml
51
+ on:
52
+ push:
53
+ branches: [main]
54
+
55
+ jobs:
56
+ release:
57
+ uses: whitphx/scriv-release/.github/workflows/reusable.yml@v1
58
+ secrets:
59
+ app-id: ${{ vars.RELEASE_APP_ID }}
60
+ app-private-key: ${{ secrets.RELEASE_APP_KEY }}
61
+ ```
62
+
63
+ See [`docs/quickstart.md`](docs/quickstart.md) and [`docs/token-setup.md`](docs/token-setup.md).
64
+
65
+ ## How it works
66
+
67
+ Two phases, branched on whether changelog fragments are present on `HEAD`:
68
+
69
+ - **Fragments present** → `scriv collect` into a `scriv-release-preview` branch and open/update a "Changelog Preview" PR.
70
+ - **No fragments on `HEAD`, but fragments on `HEAD~1`** → that means the preview PR was just merged. Determine the bump level from `HEAD~1`'s fragments, tag the release, push the tag.
71
+
72
+ This is the same file-presence-based detection Changesets uses, so it survives squash, rebase, and merge commits alike.
73
+
74
+ ## Status
75
+
76
+ Early scaffold. Public API and config keys may shift before `1.0`.
77
+
78
+ ## License
79
+
80
+ MIT — see [`LICENSE`](LICENSE).
@@ -0,0 +1,55 @@
1
+ # scriv-release
2
+
3
+ Changesets-style release automation on top of [`scriv`](https://github.com/nedbat/scriv).
4
+
5
+ `scriv` already manages per-PR changelog fragments. `scriv-release` adds the missing pieces for fully automated releases:
6
+
7
+ 1. A **policy** for mapping changelog categories to semver bump levels.
8
+ 2. **Orchestration** commands (`bump-level`, `next-version`, `collect`, `tag`) that wrap `scriv` and a configurable version provider.
9
+ 3. A **GitHub Action** that opens a "Changelog Preview" PR when fragments are pending, and tags a release once that PR is merged — the same flow popularized by [Changesets](https://github.com/changesets/changesets) in the JS ecosystem.
10
+
11
+ ## Quickstart
12
+
13
+ ```bash
14
+ pip install "scriv-release[bump-my-version]"
15
+ ```
16
+
17
+ ```toml
18
+ # pyproject.toml
19
+ [tool.scriv-release]
20
+ version_provider = "bump-my-version"
21
+ ```
22
+
23
+ In your repo's `.github/workflows/release.yml`:
24
+
25
+ ```yaml
26
+ on:
27
+ push:
28
+ branches: [main]
29
+
30
+ jobs:
31
+ release:
32
+ uses: whitphx/scriv-release/.github/workflows/reusable.yml@v1
33
+ secrets:
34
+ app-id: ${{ vars.RELEASE_APP_ID }}
35
+ app-private-key: ${{ secrets.RELEASE_APP_KEY }}
36
+ ```
37
+
38
+ See [`docs/quickstart.md`](docs/quickstart.md) and [`docs/token-setup.md`](docs/token-setup.md).
39
+
40
+ ## How it works
41
+
42
+ Two phases, branched on whether changelog fragments are present on `HEAD`:
43
+
44
+ - **Fragments present** → `scriv collect` into a `scriv-release-preview` branch and open/update a "Changelog Preview" PR.
45
+ - **No fragments on `HEAD`, but fragments on `HEAD~1`** → that means the preview PR was just merged. Determine the bump level from `HEAD~1`'s fragments, tag the release, push the tag.
46
+
47
+ This is the same file-presence-based detection Changesets uses, so it survives squash, rebase, and merge commits alike.
48
+
49
+ ## Status
50
+
51
+ Early scaffold. Public API and config keys may shift before `1.0`.
52
+
53
+ ## License
54
+
55
+ MIT — see [`LICENSE`](LICENSE).
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "scriv-release"
3
+ version = "0.2.2"
4
+ description = "Changesets-style release automation on top of scriv"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [
9
+ { name = "Yuichiro Tachibana (Tsuchiya)", email = "t.yic.yt@gmail.com" }
10
+ ]
11
+ requires-python = ">=3.10"
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python :: 3",
16
+ "Topic :: Software Development :: Build Tools",
17
+ ]
18
+ dependencies = [
19
+ "scriv>=1.7",
20
+ "tomli>=2.0; python_version<'3.11'",
21
+ ]
22
+
23
+ [project.optional-dependencies]
24
+ bump-my-version = ["bump-my-version>=0.28"]
25
+ hatch = ["hatch>=1.12"]
26
+ all = ["scriv-release[bump-my-version,hatch]"]
27
+
28
+ [project.scripts]
29
+ scriv-release = "scriv_release.cli:main"
30
+
31
+ [project.entry-points."scriv_release.version_providers"]
32
+ bump-my-version = "scriv_release.versioning.bump_my_version:Provider"
33
+ hatch = "scriv_release.versioning.hatch:Provider"
34
+ uv = "scriv_release.versioning.uv:Provider"
35
+ shell = "scriv_release.versioning.shell:Provider"
36
+
37
+ [project.urls]
38
+ Homepage = "https://github.com/whitphx/scriv-release"
39
+ Issues = "https://github.com/whitphx/scriv-release/issues"
40
+
41
+ [dependency-groups]
42
+ dev = [
43
+ "pytest>=8",
44
+ "ruff>=0.6",
45
+ "mypy>=1.10",
46
+ ]
47
+
48
+ [build-system]
49
+ requires = ["uv_build>=0.11.6,<0.12.0"]
50
+ build-backend = "uv_build"
51
+
52
+ [tool.ruff.lint]
53
+ extend-select = ["I"]
54
+
55
+ [tool.pytest.ini_options]
56
+ testpaths = ["tests"]
57
+
58
+ [[tool.mypy.overrides]]
59
+ module = ["scriv.*"]
60
+ follow_untyped_imports = true
@@ -0,0 +1,13 @@
1
+ from .config import Config, load_config
2
+ from .orchestrate import collect_for_release, print_changelog, tag_release
3
+ from .policy import BumpLevel, compute_bump_level
4
+
5
+ __all__ = [
6
+ "BumpLevel",
7
+ "Config",
8
+ "collect_for_release",
9
+ "compute_bump_level",
10
+ "load_config",
11
+ "print_changelog",
12
+ "tag_release",
13
+ ]
@@ -0,0 +1,106 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+
6
+ from .config import load_config
7
+ from .orchestrate import (
8
+ collect_for_release,
9
+ detect_release,
10
+ print_changelog,
11
+ tag_release,
12
+ )
13
+ from .policy import compute_bump_level
14
+ from .versioning import get_provider
15
+
16
+
17
+ def _build_parser() -> argparse.ArgumentParser:
18
+ parser = argparse.ArgumentParser(prog="scriv-release")
19
+ sub = parser.add_subparsers(dest="cmd", required=True)
20
+
21
+ sub.add_parser("bump-level", help="Print the bump level (major|minor|patch).")
22
+ sub.add_parser("next-version", help="Print the next version string.")
23
+ sub.add_parser(
24
+ "detect-release",
25
+ help=(
26
+ "Print the bump level for an in-progress release based on "
27
+ "the configured detection mode, or empty if none."
28
+ ),
29
+ )
30
+
31
+ sub.add_parser("collect", help="Run scriv collect with the auto-computed version.")
32
+
33
+ p_print = sub.add_parser("print", help="Print the changelog for a version.")
34
+ g = p_print.add_mutually_exclusive_group(required=True)
35
+ g.add_argument("--next", action="store_true", dest="use_next")
36
+ g.add_argument("--version", default=None)
37
+
38
+ p_tag = sub.add_parser("tag", help="Bump and tag a release.")
39
+ p_tag.add_argument("--push", action="store_true")
40
+ p_tag.add_argument(
41
+ "--level",
42
+ choices=["major", "minor", "patch"],
43
+ default=None,
44
+ help="Override the level instead of inferring from current fragments.",
45
+ )
46
+
47
+ return parser
48
+
49
+
50
+ def main(argv: list[str] | None = None) -> int:
51
+ parser = _build_parser()
52
+ args = parser.parse_args(argv)
53
+ config = load_config()
54
+
55
+ if args.cmd == "bump-level":
56
+ level = compute_bump_level(config=config)
57
+ if level:
58
+ print(level)
59
+ return 0
60
+
61
+ if args.cmd == "detect-release":
62
+ level = detect_release(config=config)
63
+ if level:
64
+ print(level)
65
+ return 0
66
+
67
+ if args.cmd == "next-version":
68
+ level = compute_bump_level(config=config)
69
+ if level is None:
70
+ print("No version bump needed.", file=sys.stderr)
71
+ return 0
72
+ print(get_provider(config.version_provider).next(level))
73
+ return 0
74
+
75
+ if args.cmd == "collect":
76
+ next_version = collect_for_release(config=config)
77
+ if next_version is None:
78
+ print("No fragments to collect.", file=sys.stderr)
79
+ return 0
80
+ print(next_version)
81
+ return 0
82
+
83
+ if args.cmd == "print":
84
+ if args.use_next:
85
+ level = compute_bump_level(config=config)
86
+ if level is None:
87
+ return 0
88
+ version = get_provider(config.version_provider).next(level)
89
+ else:
90
+ version = args.version
91
+ sys.stdout.write(print_changelog(version=version))
92
+ return 0
93
+
94
+ if args.cmd == "tag":
95
+ level = args.level or compute_bump_level(config=config)
96
+ if level is None:
97
+ print("No version bump needed.", file=sys.stderr)
98
+ return 0
99
+ tag_release(level=level, config=config, push=args.push)
100
+ return 0
101
+
102
+ return 2
103
+
104
+
105
+ if __name__ == "__main__":
106
+ raise SystemExit(main())
@@ -0,0 +1,55 @@
1
+ from __future__ import annotations
2
+
3
+ import sys
4
+ from dataclasses import dataclass, field
5
+ from pathlib import Path
6
+ from typing import Literal
7
+
8
+ if sys.version_info >= (3, 11):
9
+ import tomllib
10
+ else:
11
+ import tomli as tomllib
12
+
13
+ UnknownCategoryPolicy = Literal["warn", "error", "patch"]
14
+ ReleaseDetection = Literal["history", "pr-body-marker", "auto"]
15
+
16
+
17
+ _DEFAULT_CATEGORY_MAP: dict[str, str] = {
18
+ "Added": "minor",
19
+ "Changed": "minor",
20
+ "Deprecated": "minor",
21
+ "Removed": "major",
22
+ "Fixed": "patch",
23
+ "Security": "patch",
24
+ "Chore": "patch",
25
+ }
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class Config:
30
+ category_semver_map: dict[str, str] = field(
31
+ default_factory=lambda: dict(_DEFAULT_CATEGORY_MAP)
32
+ )
33
+ unknown_category_policy: UnknownCategoryPolicy = "warn"
34
+ version_provider: str = "bump-my-version"
35
+ preview_branch: str = "scriv-release-preview"
36
+ release_detection: ReleaseDetection = "history"
37
+ pr_body_marker_key: str = "scriv-release-bump"
38
+
39
+
40
+ def load_config(pyproject_path: Path | None = None) -> Config:
41
+ path = pyproject_path or Path("pyproject.toml")
42
+ if not path.exists():
43
+ return Config()
44
+ data = tomllib.loads(path.read_text(encoding="utf-8"))
45
+ section = data.get("tool", {}).get("scriv-release", {})
46
+ return Config(
47
+ category_semver_map=dict(
48
+ section.get("category_semver_map", _DEFAULT_CATEGORY_MAP)
49
+ ),
50
+ unknown_category_policy=section.get("unknown_category_policy", "warn"),
51
+ version_provider=section.get("version_provider", "bump-my-version"),
52
+ preview_branch=section.get("preview_branch", "scriv-release-preview"),
53
+ release_detection=section.get("release_detection", "history"),
54
+ pr_body_marker_key=section.get("pr_body_marker_key", "scriv-release-bump"),
55
+ )
@@ -0,0 +1,103 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import re
5
+ import subprocess
6
+
7
+ from .config import Config, load_config
8
+ from .policy import BumpLevel, compute_bump_level
9
+ from .versioning import get_provider
10
+
11
+
12
+ def collect_for_release(*, config: Config) -> str | None:
13
+ level = compute_bump_level(config=config)
14
+ if level is None:
15
+ return None
16
+ provider = get_provider(config.version_provider)
17
+ next_version = provider.next(level)
18
+ subprocess.run(
19
+ ["scriv", "collect", "--version", next_version],
20
+ check=True,
21
+ )
22
+ return next_version
23
+
24
+
25
+ def print_changelog(*, version: str) -> str:
26
+ result = subprocess.run(
27
+ ["scriv", "print", "--version", version],
28
+ check=True,
29
+ capture_output=True,
30
+ text=True,
31
+ )
32
+ return result.stdout
33
+
34
+
35
+ def tag_release(*, level: BumpLevel, config: Config, push: bool = False) -> str:
36
+ provider = get_provider(config.version_provider)
37
+ return provider.apply(level, tag=True, commit=False, push=push)
38
+
39
+
40
+ def parse_marker(body: str, *, key: str) -> BumpLevel | None:
41
+ pattern = re.compile(
42
+ rf"^[ \t]*{re.escape(key)}[ \t]*:[ \t]*(major|minor|patch)[ \t]*$",
43
+ re.MULTILINE | re.IGNORECASE,
44
+ )
45
+ match = pattern.search(body)
46
+ if match is None:
47
+ return None
48
+ return match.group(1).lower() # type: ignore[return-value]
49
+
50
+
51
+ def detect_release(*, config: Config) -> BumpLevel | None:
52
+ mode = config.release_detection
53
+ if mode in ("pr-body-marker", "auto"):
54
+ body = _fetch_head_pr_body()
55
+ if body is not None:
56
+ level = parse_marker(body, key=config.pr_body_marker_key)
57
+ if level is not None:
58
+ return level
59
+ if mode == "pr-body-marker":
60
+ return None
61
+ return _detect_via_fragment_history()
62
+
63
+
64
+ def _fetch_head_pr_body() -> str | None:
65
+ repo = os.environ.get("GITHUB_REPOSITORY")
66
+ if not repo:
67
+ return None
68
+ head = subprocess.run(
69
+ ["git", "rev-parse", "HEAD"],
70
+ check=True,
71
+ capture_output=True,
72
+ text=True,
73
+ ).stdout.strip()
74
+ result = subprocess.run(
75
+ [
76
+ "gh",
77
+ "api",
78
+ f"/repos/{repo}/commits/{head}/pulls",
79
+ "--jq",
80
+ ".[0].body // empty",
81
+ ],
82
+ check=False,
83
+ capture_output=True,
84
+ text=True,
85
+ )
86
+ if result.returncode != 0:
87
+ return None
88
+ body = result.stdout.strip()
89
+ return body or None
90
+
91
+
92
+ def _detect_via_fragment_history() -> BumpLevel | None:
93
+ head = subprocess.run(
94
+ ["git", "rev-parse", "HEAD"],
95
+ check=True,
96
+ capture_output=True,
97
+ text=True,
98
+ ).stdout.strip()
99
+ subprocess.run(["git", "checkout", "--quiet", "HEAD~1"], check=True)
100
+ try:
101
+ return compute_bump_level(config=load_config())
102
+ finally:
103
+ subprocess.run(["git", "checkout", "--quiet", head], check=True)
@@ -0,0 +1,42 @@
1
+ from __future__ import annotations
2
+
3
+ import warnings
4
+ from typing import Literal
5
+
6
+ from scriv.scriv import Scriv
7
+
8
+ from .config import Config
9
+
10
+ BumpLevel = Literal["major", "minor", "patch"]
11
+
12
+ _PRECEDENCE: tuple[BumpLevel, ...] = ("major", "minor", "patch")
13
+
14
+
15
+ def compute_bump_level(*, config: Config) -> BumpLevel | None:
16
+ scriv = Scriv()
17
+ fragments = scriv.fragments_to_combine()
18
+ if not fragments:
19
+ return None
20
+
21
+ entries = scriv.combine_fragments(fragments)
22
+ levels: set[BumpLevel] = set()
23
+ for category in entries.keys():
24
+ mapped = (
25
+ config.category_semver_map.get(category) if category is not None else None
26
+ )
27
+ if mapped is not None:
28
+ levels.add(mapped) # type: ignore[arg-type]
29
+ continue
30
+ if config.unknown_category_policy == "error":
31
+ raise ValueError(f"Unknown changelog category: {category!r}")
32
+ if config.unknown_category_policy == "warn":
33
+ warnings.warn(
34
+ f"Unknown changelog category {category!r}; treating as 'patch'.",
35
+ stacklevel=2,
36
+ )
37
+ levels.add("patch")
38
+
39
+ for level in _PRECEDENCE:
40
+ if level in levels:
41
+ return level
42
+ return None
File without changes
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ from importlib.metadata import entry_points
4
+ from typing import Protocol, runtime_checkable
5
+
6
+ from ..policy import BumpLevel
7
+
8
+
9
+ @runtime_checkable
10
+ class VersionProvider(Protocol):
11
+ name: str
12
+
13
+ def current(self) -> str: ...
14
+ def next(self, level: BumpLevel) -> str: ...
15
+ def apply(
16
+ self,
17
+ level: BumpLevel,
18
+ *,
19
+ tag: bool = True,
20
+ commit: bool = False,
21
+ push: bool = False,
22
+ ) -> str: ...
23
+
24
+
25
+ def get_provider(name: str) -> VersionProvider:
26
+ matches = entry_points(group="scriv_release.version_providers", name=name)
27
+ if not matches:
28
+ raise LookupError(f"No version provider registered as {name!r}")
29
+ cls = next(iter(matches)).load()
30
+ return cls()
@@ -0,0 +1,24 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+
5
+
6
+ def finalize(
7
+ new_version: str,
8
+ *,
9
+ tag: bool,
10
+ commit: bool,
11
+ push: bool,
12
+ tag_format: str = "v{version}",
13
+ ) -> None:
14
+ tag_name = tag_format.format(version=new_version)
15
+ if commit:
16
+ subprocess.run(["git", "add", "-A"], check=True)
17
+ subprocess.run(
18
+ ["git", "commit", "-m", f"Release {tag_name}"],
19
+ check=True,
20
+ )
21
+ if tag:
22
+ subprocess.run(["git", "tag", tag_name], check=True)
23
+ if push:
24
+ subprocess.run(["git", "push", "--follow-tags"], check=True)
@@ -0,0 +1,14 @@
1
+ from __future__ import annotations
2
+
3
+ from packaging.version import Version
4
+
5
+ from ..policy import BumpLevel
6
+
7
+
8
+ def bump_semver(current: str, level: BumpLevel) -> str:
9
+ v = Version(current)
10
+ if level == "major":
11
+ return f"{v.major + 1}.0.0"
12
+ if level == "minor":
13
+ return f"{v.major}.{v.minor + 1}.0"
14
+ return f"{v.major}.{v.minor}.{v.micro + 1}"
@@ -0,0 +1,41 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+
5
+ from ..policy import BumpLevel
6
+
7
+
8
+ class Provider:
9
+ name = "bump-my-version"
10
+
11
+ def current(self) -> str:
12
+ return _run("bump-my-version", "show", "current_version").strip()
13
+
14
+ def next(self, level: BumpLevel) -> str:
15
+ return _run(
16
+ "bump-my-version", "show", "--increment", level, "new_version"
17
+ ).strip()
18
+
19
+ def apply(
20
+ self,
21
+ level: BumpLevel,
22
+ *,
23
+ tag: bool = True,
24
+ commit: bool = False,
25
+ push: bool = False,
26
+ ) -> str:
27
+ args = ["bump-my-version", "bump", level, "--verbose"]
28
+ if tag:
29
+ args.append("--tag")
30
+ if not commit:
31
+ args.append("--no-commit")
32
+ _run(*args)
33
+ new_version = self.current()
34
+ if push:
35
+ subprocess.run(["git", "push", "--follow-tags"], check=True)
36
+ return new_version
37
+
38
+
39
+ def _run(*args: str) -> str:
40
+ result = subprocess.run(args, check=True, capture_output=True, text=True)
41
+ return result.stdout
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+
5
+ from ..policy import BumpLevel
6
+ from . import _git
7
+ from ._semver import bump_semver
8
+
9
+
10
+ class Provider:
11
+ name = "hatch"
12
+
13
+ def current(self) -> str:
14
+ return _run("hatch", "version").strip()
15
+
16
+ def next(self, level: BumpLevel) -> str:
17
+ return bump_semver(self.current(), level)
18
+
19
+ def apply(
20
+ self,
21
+ level: BumpLevel,
22
+ *,
23
+ tag: bool = True,
24
+ commit: bool = False,
25
+ push: bool = False,
26
+ ) -> str:
27
+ new_version = self.next(level)
28
+ _run("hatch", "version", level)
29
+ _git.finalize(new_version, tag=tag, commit=commit, push=push)
30
+ return new_version
31
+
32
+
33
+ def _run(*args: str) -> str:
34
+ result = subprocess.run(args, check=True, capture_output=True, text=True)
35
+ return result.stdout
@@ -0,0 +1,78 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import subprocess
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ if sys.version_info >= (3, 11):
9
+ import tomllib
10
+ else:
11
+ import tomli as tomllib
12
+
13
+ from ..policy import BumpLevel
14
+ from . import _git
15
+ from ._semver import bump_semver
16
+
17
+
18
+ class Provider:
19
+ name = "shell"
20
+
21
+ def __init__(self) -> None:
22
+ self._cmds = _load_commands()
23
+
24
+ def current(self) -> str:
25
+ return _run(self._require("current")).strip()
26
+
27
+ def next(self, level: BumpLevel) -> str:
28
+ cmd = self._cmds.get("next")
29
+ if cmd:
30
+ return _run(cmd, env={"LEVEL": level}).strip()
31
+ return bump_semver(self.current(), level)
32
+
33
+ def apply(
34
+ self,
35
+ level: BumpLevel,
36
+ *,
37
+ tag: bool = True,
38
+ commit: bool = False,
39
+ push: bool = False,
40
+ ) -> str:
41
+ new_version = self.next(level)
42
+ _run(
43
+ self._require("apply"),
44
+ env={"LEVEL": level, "NEW_VERSION": new_version},
45
+ )
46
+ _git.finalize(new_version, tag=tag, commit=commit, push=push)
47
+ return new_version
48
+
49
+ def _require(self, key: str) -> str:
50
+ cmd = self._cmds.get(key)
51
+ if not cmd:
52
+ raise RuntimeError(
53
+ f"shell provider requires [tool.scriv-release.shell].{key} "
54
+ "in pyproject.toml"
55
+ )
56
+ return cmd
57
+
58
+
59
+ def _load_commands(pyproject_path: Path | None = None) -> dict[str, str]:
60
+ path = pyproject_path or Path("pyproject.toml")
61
+ if not path.exists():
62
+ return {}
63
+ data = tomllib.loads(path.read_text(encoding="utf-8"))
64
+ section = data.get("tool", {}).get("scriv-release", {}).get("shell", {})
65
+ return {k: str(v) for k, v in section.items()}
66
+
67
+
68
+ def _run(command: str, *, env: dict[str, str] | None = None) -> str:
69
+ merged = {**os.environ, **(env or {})}
70
+ result = subprocess.run(
71
+ command,
72
+ shell=True,
73
+ check=True,
74
+ capture_output=True,
75
+ text=True,
76
+ env=merged,
77
+ )
78
+ return result.stdout
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ import subprocess
4
+
5
+ from ..policy import BumpLevel
6
+ from . import _git
7
+
8
+
9
+ class Provider:
10
+ name = "uv"
11
+
12
+ def current(self) -> str:
13
+ return _run("uv", "version", "--short").strip()
14
+
15
+ def next(self, level: BumpLevel) -> str:
16
+ return _run("uv", "version", "--bump", level, "--dry-run", "--short").strip()
17
+
18
+ def apply(
19
+ self,
20
+ level: BumpLevel,
21
+ *,
22
+ tag: bool = True,
23
+ commit: bool = False,
24
+ push: bool = False,
25
+ ) -> str:
26
+ new_version = _run(
27
+ "uv", "version", "--bump", level, "--short", "--frozen"
28
+ ).strip()
29
+ _git.finalize(new_version, tag=tag, commit=commit, push=push)
30
+ return new_version
31
+
32
+
33
+ def _run(*args: str) -> str:
34
+ result = subprocess.run(args, check=True, capture_output=True, text=True)
35
+ return result.stdout