swarmauri_storage_github_release 0.3.0.dev4__py3-none-any.whl → 0.3.0.dev24__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.
- swarmauri_storage_github_release/gh_release_storage_adapter.py +20 -8
- swarmauri_storage_github_release-0.3.0.dev24.dist-info/METADATA +175 -0
- swarmauri_storage_github_release-0.3.0.dev24.dist-info/RECORD +7 -0
- {swarmauri_storage_github_release-0.3.0.dev4.dist-info → swarmauri_storage_github_release-0.3.0.dev24.dist-info}/WHEEL +1 -1
- swarmauri_storage_github_release-0.3.0.dev4.dist-info/METADATA +0 -48
- swarmauri_storage_github_release-0.3.0.dev4.dist-info/RECORD +0 -7
- {swarmauri_storage_github_release-0.3.0.dev4.dist-info → swarmauri_storage_github_release-0.3.0.dev24.dist-info}/entry_points.txt +0 -0
- {swarmauri_storage_github_release-0.3.0.dev4.dist-info → swarmauri_storage_github_release-0.3.0.dev24.dist-info/licenses}/LICENSE +0 -0
|
@@ -14,7 +14,6 @@ from typing import BinaryIO, Optional
|
|
|
14
14
|
from swarmauri_base.ComponentBase import ComponentBase
|
|
15
15
|
from swarmauri_base.storage import StorageAdapterBase
|
|
16
16
|
|
|
17
|
-
from peagen._utils.config_loader import load_peagen_toml
|
|
18
17
|
from github import Github, UnknownObjectException
|
|
19
18
|
|
|
20
19
|
|
|
@@ -144,16 +143,34 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
|
|
|
144
143
|
def download_dir(self, prefix: str, dest_dir: str | os.PathLike) -> None:
|
|
145
144
|
"""Download all assets under *prefix* into *dest_dir*."""
|
|
146
145
|
dest = Path(dest_dir)
|
|
146
|
+
base = prefix.strip("/")
|
|
147
147
|
for rel_key in self.iter_prefix(prefix):
|
|
148
|
-
|
|
148
|
+
rel = rel_key
|
|
149
|
+
if base:
|
|
150
|
+
rel = (
|
|
151
|
+
rel_key[len(base) :].lstrip("/")
|
|
152
|
+
if rel_key.startswith(base)
|
|
153
|
+
else rel
|
|
154
|
+
)
|
|
155
|
+
if not rel:
|
|
156
|
+
continue
|
|
157
|
+
target = dest / rel
|
|
149
158
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
150
159
|
data = self.download(rel_key)
|
|
151
160
|
with target.open("wb") as fh:
|
|
152
161
|
shutil.copyfileobj(data, fh)
|
|
153
162
|
|
|
163
|
+
async def remove_object(self, object_key: str) -> None:
|
|
164
|
+
"""Delete an asset when present in the release."""
|
|
165
|
+
key = self._full_key(object_key)
|
|
166
|
+
for asset in self._release.get_assets():
|
|
167
|
+
if asset.name == key:
|
|
168
|
+
asset.delete_asset()
|
|
169
|
+
return
|
|
170
|
+
|
|
154
171
|
# --------------------------------------------------------------------- class
|
|
155
172
|
@classmethod
|
|
156
|
-
def from_uri(cls, uri: str) -> "GithubReleaseStorageAdapter":
|
|
173
|
+
def from_uri(cls, uri: str, token) -> "GithubReleaseStorageAdapter":
|
|
157
174
|
from urllib.parse import urlparse
|
|
158
175
|
|
|
159
176
|
p = urlparse(uri)
|
|
@@ -161,11 +178,6 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
|
|
|
161
178
|
repo, tag, *rest = p.path.lstrip("/").split("/", 2)
|
|
162
179
|
prefix = rest[0] if rest else ""
|
|
163
180
|
|
|
164
|
-
cfg = load_peagen_toml()
|
|
165
|
-
gh_cfg = cfg.get("storage", {}).get("adapters", {}).get("gh_release", {})
|
|
166
|
-
|
|
167
|
-
token = gh_cfg.get("token") or os.getenv("GITHUB_TOKEN", "")
|
|
168
|
-
|
|
169
181
|
return cls(
|
|
170
182
|
token=token,
|
|
171
183
|
org=org,
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_storage_github_release
|
|
3
|
+
Version: 0.3.0.dev24
|
|
4
|
+
Summary: GitHub Release storage adapter for Peagen
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,sdk,standards,storage,github,release
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.13
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Requires-Dist: PyGithub
|
|
20
|
+
Requires-Dist: swarmauri_base
|
|
21
|
+
Requires-Dist: swarmauri_core
|
|
22
|
+
Requires-Dist: swarmauri_standard
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
<p align="center">
|
|
28
|
+
<a href="https://pypi.org/project/swarmauri_storage_github_release/">
|
|
29
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_storage_github_release" alt="PyPI - Downloads"/></a>
|
|
30
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_github_release/">
|
|
31
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_github_release.svg"/></a>
|
|
32
|
+
<a href="https://pypi.org/project/swarmauri_storage_github_release/">
|
|
33
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_storage_github_release" alt="PyPI - Python Version"/></a>
|
|
34
|
+
<a href="https://pypi.org/project/swarmauri_storage_github_release/">
|
|
35
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_storage_github_release" alt="PyPI - License"/></a>
|
|
36
|
+
<a href="https://pypi.org/project/swarmauri_storage_github_release/">
|
|
37
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_storage_github_release?label=swarmauri_storage_github_release&color=green" alt="PyPI - swarmauri_storage_github_release"/></a>
|
|
38
|
+
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
# Swarmauri GitHub Release Storage Adapter
|
|
44
|
+
|
|
45
|
+
Stores and retrieves artifacts as assets on a GitHub release. The adapter is
|
|
46
|
+
designed to plug directly into the Swarmauri/Peagen storage interfaces while
|
|
47
|
+
still being usable as a standalone utility.
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Automatic release management** – a release is created on-demand when the
|
|
52
|
+
requested tag does not already exist.
|
|
53
|
+
- **`ghrel://` addressing** – the adapter exposes a `root_uri` and returns
|
|
54
|
+
fully-qualified URIs (e.g. `ghrel://org/repo/tag/path`) from `upload` calls.
|
|
55
|
+
- **Prefix-aware paths** – supply an optional `prefix` to group related assets
|
|
56
|
+
underneath a pseudo-directory on the release.
|
|
57
|
+
- **Bulk helpers** – use `upload_dir` and `download_dir` to synchronise entire
|
|
58
|
+
directories, or `iter_prefix` to discover stored assets.
|
|
59
|
+
- **Configuration friendly** – `GithubReleaseStorageAdapter.from_uri` reads
|
|
60
|
+
credentials from the `GITHUB_TOKEN` environment variable for simple
|
|
61
|
+
environment-driven configuration in workflows.
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- A GitHub personal access token (PAT) or GitHub App token with sufficient
|
|
66
|
+
permissions to view, create and manage releases on the target repository.
|
|
67
|
+
- Network access to the GitHub REST API (provided by `PyGithub`).
|
|
68
|
+
- Python 3.10 through 3.12.
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
### Install uv (optional)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Add the package with uv
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
uv add swarmauri_storage_github_release
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Add with Poetry
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
poetry add swarmauri_storage_github_release
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Install with pip
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install swarmauri_storage_github_release
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from io import BytesIO
|
|
100
|
+
|
|
101
|
+
from pydantic import SecretStr
|
|
102
|
+
|
|
103
|
+
from swarmauri_storage_github_release import GithubReleaseStorageAdapter
|
|
104
|
+
|
|
105
|
+
adapter = GithubReleaseStorageAdapter(
|
|
106
|
+
token=SecretStr("ghp_example-token"),
|
|
107
|
+
org="example-org",
|
|
108
|
+
repo="example-repo",
|
|
109
|
+
tag="v1.0.0",
|
|
110
|
+
prefix="artifacts",
|
|
111
|
+
release_name="Example release",
|
|
112
|
+
message="Artifacts published by our workflow.",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
print(adapter.root_uri)
|
|
116
|
+
|
|
117
|
+
uri = adapter.upload("artifact.txt", BytesIO(b"important payload"))
|
|
118
|
+
downloaded_payload = adapter.download("artifact.txt").read()
|
|
119
|
+
assets = list(adapter.iter_prefix(""))
|
|
120
|
+
|
|
121
|
+
print(uri)
|
|
122
|
+
print(downloaded_payload)
|
|
123
|
+
print(assets)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The code above demonstrates:
|
|
127
|
+
|
|
128
|
+
- `SecretStr` support for securely passing tokens.
|
|
129
|
+
- Automatic release creation when the `v1.0.0` tag does not exist.
|
|
130
|
+
- Prefix-aware uploads that produce the URI
|
|
131
|
+
`ghrel://example-org/example-repo/v1.0.0/artifacts/artifacts/artifact.txt`
|
|
132
|
+
(the asset key itself contains the prefix, so it appears in the base URI and
|
|
133
|
+
the returned asset key).
|
|
134
|
+
- Round-tripping an asset and enumerating stored keys via `iter_prefix`.
|
|
135
|
+
|
|
136
|
+
## Working with directories
|
|
137
|
+
|
|
138
|
+
Use the bulk helper methods to synchronise entire directory trees:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
adapter.upload_dir("dist", prefix="binaries")
|
|
142
|
+
adapter.download_dir("binaries", "./downloads")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Both helpers respect the adapter-level prefix and will mirror nested folders.
|
|
146
|
+
|
|
147
|
+
## Using `ghrel://` URIs and configuration
|
|
148
|
+
|
|
149
|
+
The `from_uri` class method creates adapters from an address such as:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
adapter = GithubReleaseStorageAdapter.from_uri(
|
|
153
|
+
"ghrel://example-org/example-repo/v1.0.0/artifacts",
|
|
154
|
+
)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
When invoked this way the adapter builds an unauthenticated client
|
|
158
|
+
(`token=""`).
|
|
159
|
+
|
|
160
|
+
Any prefix encoded in the URI is respected, and the resulting instance exposes
|
|
161
|
+
the same API shown above. For private repositories or higher rate limits,
|
|
162
|
+
instantiate the adapter directly and provide a token.
|
|
163
|
+
|
|
164
|
+
### Controlling release metadata
|
|
165
|
+
|
|
166
|
+
The constructor accepts additional keyword arguments to fine tune release
|
|
167
|
+
creation, including `release_name`, `message`, `draft`, and `prerelease`. These
|
|
168
|
+
parameters map directly to GitHub's release settings, allowing you to reuse the
|
|
169
|
+
adapter for production, staging, or nightly build workflows.
|
|
170
|
+
|
|
171
|
+
## Want to help?
|
|
172
|
+
|
|
173
|
+
If you want to contribute to swarmauri-sdk, read up on our
|
|
174
|
+
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
175
|
+
that will help you get started.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
swarmauri_storage_github_release/__init__.py,sha256=zVY7XpMAyATHsPoIlF2Uhvu3jIWYXjxhYQoZV9P7OGY,470
|
|
2
|
+
swarmauri_storage_github_release/gh_release_storage_adapter.py,sha256=iOAAKc8Qe3GkbT74v3ZKOkab7j5BD5pmvtn4ljegwKc,6382
|
|
3
|
+
swarmauri_storage_github_release-0.3.0.dev24.dist-info/METADATA,sha256=LammwcYq-258wTELacf562-nUrhRBDJs5g7FmWQPkO0,6246
|
|
4
|
+
swarmauri_storage_github_release-0.3.0.dev24.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
5
|
+
swarmauri_storage_github_release-0.3.0.dev24.dist-info/entry_points.txt,sha256=6d91NDUup0HedFEyI0MOA6PJiSTZMJ5xA9IvE9p5w8k,280
|
|
6
|
+
swarmauri_storage_github_release-0.3.0.dev24.dist-info/licenses/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
|
|
7
|
+
swarmauri_storage_github_release-0.3.0.dev24.dist-info/RECORD,,
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.3
|
|
2
|
-
Name: swarmauri_storage_github_release
|
|
3
|
-
Version: 0.3.0.dev4
|
|
4
|
-
Summary: GitHub Release storage adapter for Peagen
|
|
5
|
-
License: Apache-2.0
|
|
6
|
-
Author: Jacob Stewart
|
|
7
|
-
Author-email: jacob@swarmauri.com
|
|
8
|
-
Requires-Python: >=3.10,<3.13
|
|
9
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
-
Classifier: Operating System :: OS Independent
|
|
15
|
-
Requires-Dist: PyGithub
|
|
16
|
-
Requires-Dist: peagen
|
|
17
|
-
Requires-Dist: swarmauri_base
|
|
18
|
-
Requires-Dist: swarmauri_core
|
|
19
|
-
Requires-Dist: swarmauri_standard
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
|
|
22
|
-
# Swarmauri GitHub Release Storage Adapter
|
|
23
|
-
|
|
24
|
-
Stores artifacts as assets on a GitHub release for use with Peagen.
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
# pip install swarmauri_storage_github_release (when published)
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
## Usage
|
|
33
|
-
|
|
34
|
-
```python
|
|
35
|
-
from swarmauri_storage_github_release import GithubReleaseStorageAdapter
|
|
36
|
-
from pydantic import SecretStr
|
|
37
|
-
import io
|
|
38
|
-
|
|
39
|
-
adapter = GithubReleaseStorageAdapter(
|
|
40
|
-
token=SecretStr("ghp_..."),
|
|
41
|
-
org="my-org",
|
|
42
|
-
repo="my-repo",
|
|
43
|
-
tag="v1.0.0",
|
|
44
|
-
)
|
|
45
|
-
uri = adapter.upload("artifact.txt", io.BytesIO(b"data"))
|
|
46
|
-
print(uri)
|
|
47
|
-
```
|
|
48
|
-
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
swarmauri_storage_github_release/__init__.py,sha256=zVY7XpMAyATHsPoIlF2Uhvu3jIWYXjxhYQoZV9P7OGY,470
|
|
2
|
-
swarmauri_storage_github_release/gh_release_storage_adapter.py,sha256=swwwaP6OlqXAZ6yvJKf_URLaNiBJk14II-lXJKmAhmw,6017
|
|
3
|
-
swarmauri_storage_github_release-0.3.0.dev4.dist-info/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
|
|
4
|
-
swarmauri_storage_github_release-0.3.0.dev4.dist-info/METADATA,sha256=vxyFHIYCh_DCbDPEJ_cr_PhKgbp_NVQtgHjJe9YGlrw,1275
|
|
5
|
-
swarmauri_storage_github_release-0.3.0.dev4.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
6
|
-
swarmauri_storage_github_release-0.3.0.dev4.dist-info/entry_points.txt,sha256=6d91NDUup0HedFEyI0MOA6PJiSTZMJ5xA9IvE9p5w8k,280
|
|
7
|
-
swarmauri_storage_github_release-0.3.0.dev4.dist-info/RECORD,,
|
|
File without changes
|