swarmauri_storage_github_release 0.3.0.dev36__py3-none-any.whl → 0.11.0.dev1__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.
@@ -19,7 +19,9 @@ from github import Github, UnknownObjectException
19
19
 
20
20
  @ComponentBase.register_type(StorageAdapterBase, "GithubReleaseStorageAdapter")
21
21
  class GithubReleaseStorageAdapter(StorageAdapterBase):
22
- """Storage adapter that uses GitHub Releases to store and retrieve assets."""
22
+ """
23
+ Storage adapter that uses GitHub Releases to store and retrieve assets.
24
+ """
23
25
 
24
26
  def __init__(
25
27
  self,
@@ -36,11 +38,13 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
36
38
  **kwargs,
37
39
  ) -> None:
38
40
  super().__init__(**kwargs)
39
- token_val = token.get_secret_value() if isinstance(token, SecretStr) else token
41
+ token_val = (
42
+ token.get_secret_value() if isinstance(token, SecretStr) else token
43
+ )
40
44
  self._client = Github(token_val)
41
45
  self._repo = self._client.get_organization(org).get_repo(repo)
42
46
  self._tag = tag
43
- self._prefix = prefix.lstrip("/")
47
+ self._prefix = self.normalize_prefix(prefix)
44
48
  self._release = self._get_or_create_release(
45
49
  tag=tag,
46
50
  name=release_name or tag,
@@ -51,10 +55,7 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
51
55
 
52
56
  # ----------------------------------------------------------------- helpers
53
57
  def _full_key(self, key: str) -> str:
54
- key = key.lstrip("/")
55
- if self._prefix:
56
- return f"{self._prefix.rstrip('/')}/{key}"
57
- return key
58
+ return self.compose_key(self._prefix, key, allow_empty=True)
58
59
 
59
60
  @property
60
61
  def root_uri(self) -> str:
@@ -82,9 +83,12 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
82
83
  prerelease=prerelease,
83
84
  )
84
85
 
85
- # ------------------------------------------------------------------- public
86
+ # -------------------------------------------------------------------
87
+ # public
86
88
  def upload(self, key: str, data: BinaryIO) -> str:
87
- """Upload ``data`` under ``key`` as a release asset and return the artifact URI."""
89
+ """Upload ``data`` under ``key`` as a release asset and return the
90
+ artifact URI."""
91
+ normalized_key = self.normalize_key(key)
88
92
  key = self._full_key(key)
89
93
 
90
94
  data.seek(0)
@@ -95,12 +99,15 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
95
99
  asset.delete_asset()
96
100
  break
97
101
 
98
- with tempfile.NamedTemporaryFile() as tmp:
102
+ with tempfile.NamedTemporaryFile(delete=False) as tmp:
99
103
  tmp.write(content)
100
- tmp.flush()
101
- self._release.upload_asset(path=tmp.name, name=key, label=key)
104
+ tmp_path = tmp.name
105
+ try:
106
+ self._release.upload_asset(path=tmp_path, name=key, label=key)
107
+ finally:
108
+ Path(tmp_path).unlink(missing_ok=True)
102
109
 
103
- return f"{self.root_uri}{key.lstrip('/')}"
110
+ return f"{self.root_uri}{normalized_key}"
104
111
 
105
112
  def download(self, key: str) -> BinaryIO:
106
113
  """Return the bytes of asset ``key`` as a BytesIO object."""
@@ -116,16 +123,19 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
116
123
  buf = io.BytesIO(raw)
117
124
  buf.seek(0)
118
125
  return buf
119
- raise FileNotFoundError(f"Asset '{key}' not found in release '{self._tag}'")
126
+ raise FileNotFoundError(
127
+ f"Asset '{key}' not found in release '{self._tag}'"
128
+ )
120
129
 
121
- # --------------------------------------------------------------- convenience
130
+ # ---------------------------------------------------------------
131
+ # convenience
122
132
  def upload_dir(self, src: str | os.PathLike, *, prefix: str = "") -> None:
123
133
  """Upload all files under *src* using an optional *prefix*."""
124
134
  base = Path(src)
125
135
  for path in base.rglob("*"):
126
136
  if path.is_file():
127
137
  rel = path.relative_to(base).as_posix()
128
- key = f"{prefix.rstrip('/')}/{rel}" if prefix else rel
138
+ key = self.compose_key(prefix, rel)
129
139
  with path.open("rb") as fh:
130
140
  self.upload(key, fh)
131
141
 
@@ -136,14 +146,16 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
136
146
  name = asset.name
137
147
  if name.startswith(full.rstrip("/")):
138
148
  key = name
139
- if self._prefix and key.startswith(self._prefix.rstrip("/") + "/"):
149
+ if self._prefix and key.startswith(
150
+ self._prefix.rstrip("/") + "/"
151
+ ):
140
152
  key = key[len(self._prefix.rstrip("/")) + 1 :]
141
153
  yield key
142
154
 
143
155
  def download_dir(self, prefix: str, dest_dir: str | os.PathLike) -> None:
144
156
  """Download all assets under *prefix* into *dest_dir*."""
145
157
  dest = Path(dest_dir)
146
- base = prefix.strip("/")
158
+ base = self.normalize_prefix(prefix)
147
159
  for rel_key in self.iter_prefix(prefix):
148
160
  rel = rel_key
149
161
  if base:
@@ -154,7 +166,7 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
154
166
  )
155
167
  if not rel:
156
168
  continue
157
- target = dest / rel
169
+ target = self.download_target_for_key(dest, rel)
158
170
  target.parent.mkdir(parents=True, exist_ok=True)
159
171
  data = self.download(rel_key)
160
172
  with target.open("wb") as fh:
@@ -168,7 +180,8 @@ class GithubReleaseStorageAdapter(StorageAdapterBase):
168
180
  asset.delete_asset()
169
181
  return
170
182
 
171
- # --------------------------------------------------------------------- class
183
+ # ---------------------------------------------------------------------
184
+ # class
172
185
  @classmethod
173
186
  def from_uri(
174
187
  cls,
@@ -1,44 +1,44 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swarmauri_storage_github_release
3
- Version: 0.3.0.dev36
3
+ Version: 0.11.0.dev1
4
4
  Summary: GitHub Release storage adapter for Peagen
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Keywords: swarmauri,sdk,standards,storage,github,release
8
8
  Author: Jacob Stewart
9
9
  Author-email: jacob@swarmauri.com
10
- Requires-Python: >=3.10,<3.13
10
+ Requires-Python: >=3.10,<3.15
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
12
14
  Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
13
16
  Classifier: Programming Language :: Python :: 3.10
14
17
  Classifier: Programming Language :: Python :: 3.11
15
18
  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
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
19
21
  Requires-Dist: PyGithub
20
22
  Requires-Dist: swarmauri_base
21
23
  Requires-Dist: swarmauri_core
22
24
  Requires-Dist: swarmauri_standard
23
25
  Description-Content-Type: text/markdown
24
26
 
25
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
27
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
26
28
 
27
29
  <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://pepy.tech/project/swarmauri_storage_github_release/">
31
+ <img src="https://static.pepy.tech/badge/swarmauri_storage_github_release/month" alt="PyPI - Downloads"/></a>
30
32
  <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_github_release/">
31
33
  <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_github_release.svg"/></a>
32
34
  <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>
35
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
34
36
  <a href="https://pypi.org/project/swarmauri_storage_github_release/">
35
37
  <img src="https://img.shields.io/pypi/l/swarmauri_storage_github_release" alt="PyPI - License"/></a>
36
38
  <a href="https://pypi.org/project/swarmauri_storage_github_release/">
37
39
  <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
- ---
40
+ <a href="https://discord.gg/N4UpBuQv8T">
41
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
42
42
 
43
43
  # Swarmauri GitHub Release Storage Adapter
44
44
 
@@ -48,15 +48,15 @@ still being usable as a standalone utility.
48
48
 
49
49
  ## Features
50
50
 
51
- - **Automatic release management** – a release is created on-demand when the
51
+ - **Automatic release management** ? a release is created on-demand when the
52
52
  requested tag does not already exist.
53
- - **`ghrel://` addressing** – the adapter exposes a `root_uri` and returns
53
+ - **`ghrel://` addressing** ? the adapter exposes a `root_uri` and returns
54
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
55
+ - **Prefix-aware paths** ? supply an optional `prefix` to group related assets
56
56
  underneath a pseudo-directory on the release.
57
- - **Bulk helpers** – use `upload_dir` and `download_dir` to synchronise entire
57
+ - **Bulk helpers** ? use `upload_dir` and `download_dir` to synchronise entire
58
58
  directories, or `iter_prefix` to discover stored assets.
59
- - **Configuration friendly** – `GithubReleaseStorageAdapter.from_uri` reads
59
+ - **Configuration friendly** ? `GithubReleaseStorageAdapter.from_uri` reads
60
60
  credentials from the `GITHUB_TOKEN` environment variable for simple
61
61
  environment-driven configuration in workflows.
62
62
 
@@ -173,3 +173,5 @@ adapter for production, staging, or nightly build workflows.
173
173
  If you want to contribute to swarmauri-sdk, read up on our
174
174
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
175
175
  that will help you get started.
176
+
177
+
@@ -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=EYLLLvQopd1Nf25LLcgAm7wHeJdXd6-k4LF_ds_FgPs,6692
3
+ swarmauri_storage_github_release-0.11.0.dev1.dist-info/METADATA,sha256=lHd69Fj4hA47QI_Bz_uC1NtdkbYVZ8xptkfR2gEMCmU,6509
4
+ swarmauri_storage_github_release-0.11.0.dev1.dist-info/WHEEL,sha256=eY7nduwzv-ldUxpzbRlxwvC693Hg6PX8bWDjEHjZ_dk,88
5
+ swarmauri_storage_github_release-0.11.0.dev1.dist-info/entry_points.txt,sha256=6d91NDUup0HedFEyI0MOA6PJiSTZMJ5xA9IvE9p5w8k,280
6
+ swarmauri_storage_github_release-0.11.0.dev1.dist-info/licenses/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
7
+ swarmauri_storage_github_release-0.11.0.dev1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.3.1
2
+ Generator: poetry-core 2.4.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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=sd-JL0_XhNAeAbjSFgqILz2lN8wthnGYnROG7Fv9U_Y,6450
3
- swarmauri_storage_github_release-0.3.0.dev36.dist-info/METADATA,sha256=w18QgOnA1ycfTwz_cV4aqqfNjq0nHGr5pgdGY5VfRk4,6246
4
- swarmauri_storage_github_release-0.3.0.dev36.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
5
- swarmauri_storage_github_release-0.3.0.dev36.dist-info/entry_points.txt,sha256=6d91NDUup0HedFEyI0MOA6PJiSTZMJ5xA9IvE9p5w8k,280
6
- swarmauri_storage_github_release-0.3.0.dev36.dist-info/licenses/LICENSE,sha256=djUXOlCxLVszShEpZXshZ7v33G-2qIC_j9KXpWKZSzQ,11359
7
- swarmauri_storage_github_release-0.3.0.dev36.dist-info/RECORD,,