rn-forge-tooling 0.3.1__py3-none-any.whl

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,186 @@
1
+ """Release sources, download verification, and extraction."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import shutil
7
+ import urllib.error
8
+ import urllib.request
9
+ from dataclasses import dataclass
10
+ from pathlib import Path
11
+ from typing import Protocol, runtime_checkable
12
+
13
+ from rn_forge.commons.exceptions import AppException
14
+ from rn_forge.commons.fs.hashing import ContentHash
15
+ from rn_forge.commons.logging import AppLogger
16
+ from rn_forge.tooling.install.archive import extract_archive
17
+
18
+ __all__ = ["GitHubReleases", "LocalArchive", "ReleaseSource", "fetch_release"]
19
+
20
+ _LOGGER = AppLogger.get_logger(__name__)
21
+
22
+ _TIMEOUT = 60.0
23
+ """Seconds before a network request to a release host is abandoned."""
24
+
25
+
26
+ @runtime_checkable
27
+ class ReleaseSource(Protocol):
28
+ """Where a product's releases are published."""
29
+
30
+ def latest(self) -> str:
31
+ """Return the newest released version."""
32
+ ...
33
+
34
+ def download(self, version: str, destination: Path) -> Path:
35
+ """Write the archive for *version* into the directory *destination*.
36
+
37
+ Returns:
38
+ The archive file.
39
+ """
40
+ ...
41
+
42
+ def checksum(self, version: str) -> str | None:
43
+ """Return the SHA-256 hex digest *version*'s archive must match, if published."""
44
+ ...
45
+
46
+
47
+ @dataclass(frozen=True, slots=True)
48
+ class GitHubReleases:
49
+ """Releases published as tags of a GitHub repository.
50
+
51
+ The archive is GitHub's generated source tarball for the tag. GitHub
52
+ publishes no checksum for those, so :meth:`checksum` returns ``None`` and
53
+ the download is trusted to TLS; a product that attaches a checksum asset
54
+ to its releases implements :class:`ReleaseSource` to verify it.
55
+
56
+ Args:
57
+ repo: ``owner/name``.
58
+ tag_prefix: What the tag carries before the version — ``"v"`` for
59
+ ``v1.2.0``, ``"golden-tool-v"`` in a monorepo.
60
+ api_url: The GitHub API root, for GitHub Enterprise.
61
+ web_url: The GitHub web root the tarball is served from.
62
+ """
63
+
64
+ repo: str
65
+ tag_prefix: str = "v"
66
+ api_url: str = "https://api.github.com"
67
+ web_url: str = "https://github.com"
68
+
69
+ def latest(self) -> str:
70
+ """Return the version of the repository's latest release.
71
+
72
+ Raises:
73
+ AppException: The request failed, or the latest release's tag does
74
+ not carry :attr:`tag_prefix`.
75
+ """
76
+ url = f"{self.api_url}/repos/{self.repo}/releases/latest"
77
+ try:
78
+ with urllib.request.urlopen(url, timeout=_TIMEOUT) as response: # noqa: S310 # URL built from the configured GitHub host
79
+ tag = str(json.load(response).get("tag_name") or "")
80
+ except (urllib.error.URLError, ValueError) as error:
81
+ raise AppException(
82
+ "Cannot resolve the latest release of {}: {}", self.repo, error
83
+ ) from error
84
+ if not tag.startswith(self.tag_prefix) or tag == self.tag_prefix:
85
+ raise AppException(
86
+ "Latest release tag {!r} of {} does not start with {!r}",
87
+ tag,
88
+ self.repo,
89
+ self.tag_prefix,
90
+ )
91
+ return tag.removeprefix(self.tag_prefix)
92
+
93
+ def download(self, version: str, destination: Path) -> Path:
94
+ """Download the tag's source tarball into *destination*.
95
+
96
+ Raises:
97
+ AppException: The download failed.
98
+ """
99
+ tag = f"{self.tag_prefix}{version}"
100
+ url = f"{self.web_url}/{self.repo}/archive/refs/tags/{tag}.tar.gz"
101
+ archive = destination / f"{tag}.tar.gz"
102
+ try:
103
+ with (
104
+ urllib.request.urlopen(url, timeout=_TIMEOUT) as response, # noqa: S310 # URL built from the configured GitHub host
105
+ archive.open("wb") as out,
106
+ ):
107
+ shutil.copyfileobj(response, out)
108
+ except urllib.error.URLError as error:
109
+ raise AppException("Cannot download {}: {}", url, error) from error
110
+ return archive
111
+
112
+ def checksum(self, version: str) -> str | None:
113
+ """``None``: GitHub publishes no checksum for a generated tarball."""
114
+ return None
115
+
116
+
117
+ @dataclass(frozen=True, slots=True)
118
+ class LocalArchive:
119
+ """One archive already on disk, standing in for a release.
120
+
121
+ Args:
122
+ path: The archive file.
123
+ version: The version the archive holds. Not inferred from its
124
+ contents: reading a version out of a tree is the product's
125
+ convention, not this module's.
126
+ sha256: The digest to verify against, when known.
127
+ """
128
+
129
+ path: Path
130
+ version: str
131
+ sha256: str | None = None
132
+
133
+ def latest(self) -> str:
134
+ """The archive's own version — it is the only one there is."""
135
+ return self.version
136
+
137
+ def download(self, version: str, destination: Path) -> Path:
138
+ """Copy the archive into *destination*.
139
+
140
+ Raises:
141
+ AppException: *version* is not the archive's, or the file is missing.
142
+ """
143
+ if version != self.version:
144
+ raise AppException(
145
+ "{} holds version {}, not {}", self.path, self.version, version
146
+ )
147
+ if not self.path.is_file():
148
+ raise AppException("Archive not found: {}", self.path)
149
+ return Path(shutil.copy2(self.path, destination / self.path.name))
150
+
151
+ def checksum(self, version: str) -> str | None:
152
+ """The digest given at construction, if any."""
153
+ return self.sha256
154
+
155
+
156
+ def fetch_release(source: ReleaseSource, version: str, workdir: str | Path) -> Path:
157
+ """Download *version* from *source* into *workdir*, verify it, and extract it.
158
+
159
+ Args:
160
+ source: Where the release is published.
161
+ version: The version to fetch.
162
+ workdir: A scratch directory; created if absent. The archive and its
163
+ extracted tree are left here for the caller to clean up.
164
+
165
+ Returns:
166
+ The archive's single root directory.
167
+
168
+ Raises:
169
+ AppException: The download failed, the archive does not match the
170
+ published checksum, or it does not have exactly one root directory.
171
+ """
172
+ work = Path(workdir)
173
+ work.mkdir(parents=True, exist_ok=True)
174
+ archive = source.download(version, work)
175
+ expected = source.checksum(version)
176
+ if expected is not None:
177
+ actual = ContentHash.of_file(archive)
178
+ if actual != expected.strip().lower():
179
+ raise AppException(
180
+ "Checksum mismatch for {}: expected {}, got {}",
181
+ archive.name,
182
+ expected,
183
+ actual,
184
+ )
185
+ _LOGGER.verbose("install.release: fetched {} into {}", version, work)
186
+ return extract_archive(archive, work / "extracted")
File without changes
@@ -0,0 +1,95 @@
1
+ Metadata-Version: 2.4
2
+ Name: rn-forge-tooling
3
+ Version: 0.3.1
4
+ Summary: Developer-tool lifecycle verbs and install mechanics for the rn-forge-* CLIs
5
+ Author: Rohit Narayanan
6
+ Author-email: Rohit Narayanan <rohit.nn@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Typing :: Typed
16
+ Requires-Dist: rn-forge-commons>=0.8.0,<0.9
17
+ Requires-Dist: rn-forge-cli>=0.1.1,<0.2
18
+ Requires-Dist: assertpy>=1.1 ; extra == 'testing'
19
+ Requires-Dist: pytest>=9.1.1 ; extra == 'testing'
20
+ Requires-Python: >=3.14
21
+ Project-URL: Documentation, https://rn-forge.github.io/pykit/packages/rn-forge-tooling/latest/
22
+ Project-URL: Source, https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-tooling
23
+ Project-URL: Changelog, https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-tooling/CHANGELOG.md
24
+ Project-URL: Issues, https://github.com/rn-forge/pykit/issues
25
+ Provides-Extra: testing
26
+ Description-Content-Type: text/markdown
27
+
28
+ # rn-forge-tooling
29
+
30
+ [Documentation](https://rn-forge.github.io/pykit/packages/rn-forge-tooling/latest/)
31
+ ·
32
+ [Changelog](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-tooling/CHANGELOG.md)
33
+ ·
34
+ [Source](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-tooling)
35
+ · [All pykit packages](https://rn-forge.github.io/pykit/)
36
+
37
+ The lifecycle and install layer of the developer-tooling stack: for command-line
38
+ tools that install themselves and manage their own versions. File generation,
39
+ local state and templates live in `rn-forge-commons`.
40
+
41
+ Where
42
+ [`rn-forge-commons`](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-commons)
43
+ is runtime-neutral — safe in a web server, a worker or a container — and
44
+ [`rn-forge-cli`](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-cli)
45
+ is the command-line shape every application wants, this package is deliberately
46
+ workstation-shaped: it assumes a developer's filesystem and a tool that owns
47
+ files in it. It owns:
48
+
49
+ - `install` — the tool lifecycle: `$RNF_HOME` layout (`ToolHome`), release
50
+ sources and verification, archive extraction, the `ToolProduct` seam, and
51
+ the transactional
52
+ `install`/`upgrade`/`uninstall`/`cleanup`/`status`/`doctor` verbs.
53
+ - `cli` — `build_tool_app`, which builds an `rn-forge-cli` application from a
54
+ `[cli]` table and adds the lifecycle verbs declared in a `[lifecycle]`
55
+ table.
56
+
57
+ A repository that only needs a command line takes `rn-forge-cli` and stops
58
+ there. A package that ships into a deployed runtime (`rn-forge-django`,
59
+ `rn-forge-fastapi`) must never depend on this package outside a `codegen` extra.
60
+ Tooling may import cli and commons; neither may import tooling, and
61
+ `uv run lint-imports` proves it.
62
+
63
+ ## Install
64
+
65
+ Require the package by version range:
66
+
67
+ ```toml
68
+ [project]
69
+ dependencies = ["rn-forge-tooling>=0.3,<0.4"]
70
+ ```
71
+
72
+ `rn-forge-cli` and `rn-forge-commons` come with it, as version ranges.
73
+
74
+ ## Docs
75
+
76
+ Full API reference and guides are built with mkdocs:
77
+
78
+ ```bash
79
+ uv run --group docs mkdocs serve # or `mkdocs build`
80
+ ```
81
+
82
+ Source lives in
83
+ [`docs/`](https://github.com/rn-forge/pykit/tree/main/packages/rn-forge-tooling/docs),
84
+ configured via
85
+ [`mkdocs.yml`](https://github.com/rn-forge/pykit/blob/main/packages/rn-forge-tooling/mkdocs.yml).
86
+
87
+ ## Development
88
+
89
+ From the repo root or this directory:
90
+
91
+ ```bash
92
+ uv run pytest packages/rn-forge-tooling
93
+ uv run ruff check packages/rn-forge-tooling
94
+ uv run pyright
95
+ ```
@@ -0,0 +1,14 @@
1
+ rn_forge/tooling/__init__.py,sha256=srmUEL7PpyeCJhQkML73encq073M7Uhde0xIJyemqKc,923
2
+ rn_forge/tooling/cli/__init__.py,sha256=fmWyA9LbV5vjuVumIpbt0uWtgb23MfwlWQhEwzA29yI,56
3
+ rn_forge/tooling/cli/lifecycle.py,sha256=Q5Lf8hgpSRF6P0EQybdwzVvMCgqrzcp-5nu5VX3tbOE,11464
4
+ rn_forge/tooling/install/__init__.py,sha256=57SteW2JMqpQLQ13H8wH3JQntofIPUCrf984dCoJ9BI,930
5
+ rn_forge/tooling/install/archive.py,sha256=ScHPwQBaOWhiaDpx6S6Bzku2o0gJmJScGzEqa-LdZPU,1859
6
+ rn_forge/tooling/install/home.py,sha256=ZGpKYcc1K6PRKGjkrsykEvkodCZ4LsC5IWE3RKoCVdM,4120
7
+ rn_forge/tooling/install/lifecycle.py,sha256=pY62REsO6tTdy74EZTGKz5M8BqnN3K6d0hdgehsG8Fw,14840
8
+ rn_forge/tooling/install/product.py,sha256=lrKCl8ariOR7STEZ-qIqmy28rHfmq-KknsUzCo1k0jU,4211
9
+ rn_forge/tooling/install/release.py,sha256=viq9eTOLR4FnNfaIAGIP9tdU-YAqvu8a_JAroCnPVJ0,6671
10
+ rn_forge/tooling/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ rn_forge_tooling-0.3.1.dist-info/licenses/LICENSE,sha256=buwykOASkbZdpj0j_JmFbwNzbUiuLzOiaMQmVQt5lr8,1072
12
+ rn_forge_tooling-0.3.1.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
13
+ rn_forge_tooling-0.3.1.dist-info/METADATA,sha256=jqtGrOmehtLebu4BaJl21FQ2xbOE3uod4sYSt4y1xH0,3653
14
+ rn_forge_tooling-0.3.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.13.6
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rohit Narayanan
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.