swarmauri_storage_file 0.3.0.dev51__tar.gz → 0.11.0.dev1__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.
@@ -1,43 +1,43 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swarmauri_storage_file
3
- Version: 0.3.0.dev51
3
+ Version: 0.11.0.dev1
4
4
  Summary: Filesystem storage adapter for Peagen
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Keywords: swarmauri,sdk,standards,storage,file
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: swarmauri_base
20
22
  Requires-Dist: swarmauri_core
21
23
  Requires-Dist: swarmauri_standard
22
24
  Description-Content-Type: text/markdown
23
25
 
24
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
26
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
25
27
 
26
28
  <p align="center">
27
- <a href="https://pypi.org/project/swarmauri_storage_file/">
28
- <img src="https://img.shields.io/pypi/dm/swarmauri_storage_file" alt="PyPI - Downloads"/></a>
29
+ <a href="https://pepy.tech/project/swarmauri_storage_file/">
30
+ <img src="https://static.pepy.tech/badge/swarmauri_storage_file/month" alt="PyPI - Downloads"/></a>
29
31
  <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_file/">
30
32
  <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_file.svg"/></a>
31
33
  <a href="https://pypi.org/project/swarmauri_storage_file/">
32
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_storage_file" alt="PyPI - Python Version"/></a>
34
+ <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>
33
35
  <a href="https://pypi.org/project/swarmauri_storage_file/">
34
36
  <img src="https://img.shields.io/pypi/l/swarmauri_storage_file" alt="PyPI - License"/></a>
35
37
  <a href="https://pypi.org/project/swarmauri_storage_file/">
36
38
  <img src="https://img.shields.io/pypi/v/swarmauri_storage_file?label=swarmauri_storage_file&color=green" alt="PyPI - swarmauri_storage_file"/></a>
37
-
38
- </p>
39
-
40
- ---
39
+ <a href="https://discord.gg/N4UpBuQv8T">
40
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
41
41
 
42
42
  # Swarmauri File Storage Adapter
43
43
 
@@ -121,3 +121,5 @@ tools that understand ``file://`` locations.
121
121
  If you want to contribute to swarmauri-sdk, read up on our
122
122
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
123
123
  that will help you get started.
124
+
125
+
@@ -1,20 +1,18 @@
1
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
2
 
3
3
  <p align="center">
4
- <a href="https://pypi.org/project/swarmauri_storage_file/">
5
- <img src="https://img.shields.io/pypi/dm/swarmauri_storage_file" alt="PyPI - Downloads"/></a>
4
+ <a href="https://pepy.tech/project/swarmauri_storage_file/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_storage_file/month" alt="PyPI - Downloads"/></a>
6
6
  <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_file/">
7
7
  <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_storage_file.svg"/></a>
8
8
  <a href="https://pypi.org/project/swarmauri_storage_file/">
9
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_storage_file" alt="PyPI - Python Version"/></a>
9
+ <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>
10
10
  <a href="https://pypi.org/project/swarmauri_storage_file/">
11
11
  <img src="https://img.shields.io/pypi/l/swarmauri_storage_file" alt="PyPI - License"/></a>
12
12
  <a href="https://pypi.org/project/swarmauri_storage_file/">
13
13
  <img src="https://img.shields.io/pypi/v/swarmauri_storage_file?label=swarmauri_storage_file&color=green" alt="PyPI - swarmauri_storage_file"/></a>
14
-
15
- </p>
16
-
17
- ---
14
+ <a href="https://discord.gg/N4UpBuQv8T">
15
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
18
16
 
19
17
  # Swarmauri File Storage Adapter
20
18
 
@@ -97,4 +95,5 @@ tools that understand ``file://`` locations.
97
95
 
98
96
  If you want to contribute to swarmauri-sdk, read up on our
99
97
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
100
- that will help you get started.
98
+ that will help you get started.
99
+
@@ -1,23 +1,23 @@
1
1
  [project]
2
2
  name = "swarmauri_storage_file"
3
- version = "0.3.0.dev51"
4
- authors = [
5
- { name = "Jacob Stewart", email = "jacob@swarmauri.com" }
6
- ]
3
+ version = "0.11.0.dev1"
4
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
7
5
  description = "Filesystem storage adapter for Peagen"
8
6
  readme = "README.md"
9
7
  license = "Apache-2.0"
10
8
  repository = "http://github.com/swarmauri/swarmauri-sdk"
11
- requires-python = ">=3.10,<3.13"
9
+ requires-python = ">=3.10,<3.15"
12
10
  classifiers = [
13
11
  "License :: OSI Approved :: Apache Software License",
12
+ "Operating System :: OS Independent",
13
+ "Programming Language :: Python",
14
14
  "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3 :: Only",
15
16
  "Programming Language :: Python :: 3.10",
16
17
  "Programming Language :: Python :: 3.11",
17
18
  "Programming Language :: Python :: 3.12",
18
- "Operating System :: OS Independent",
19
- "Programming Language :: Python",
20
- "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
21
  ]
22
22
  dependencies = [
23
23
  "swarmauri_core",
@@ -76,7 +76,7 @@ dev = [
76
76
  "pytest-xdist>=3.6.1",
77
77
  "pytest-json-report>=1.5.0",
78
78
  "python-dotenv",
79
- "requests>=2.32.3",
79
+ "httpx>=0.27",
80
80
  "flake8>=7.0",
81
81
  "pytest-timeout>=2.3.1",
82
82
  "ruff>=0.9.9",
@@ -20,17 +20,19 @@ from swarmauri_base.storage import StorageAdapterBase
20
20
  class FileStorageAdapter(StorageAdapterBase):
21
21
  """Write and read artefacts on the local disk."""
22
22
 
23
- def __init__(self, output_dir: str | os.PathLike, *, prefix: str = "", **kwargs):
23
+ def __init__(
24
+ self, output_dir: str | os.PathLike, *, prefix: str = "", **kwargs
25
+ ):
24
26
  super().__init__(**kwargs)
25
27
  self._root = Path(output_dir).expanduser().resolve()
26
28
  self._root.mkdir(parents=True, exist_ok=True)
27
- self._prefix = prefix.lstrip("/")
29
+ self._prefix = self.normalize_prefix(prefix)
28
30
 
29
- def _full_key(self, key: str) -> Path:
30
- key = key.lstrip("/")
31
- if self._prefix:
32
- return self._root / self._prefix / key
33
- return self._root / key
31
+ def _full_key(self, key: str, *, allow_empty: bool = True) -> Path:
32
+ full_key = self.compose_key(self._prefix, key, allow_empty=allow_empty)
33
+ return self.storage_path_for_key(
34
+ self._root, full_key, allow_empty=allow_empty
35
+ )
34
36
 
35
37
  @property
36
38
  def root_uri(self) -> str:
@@ -40,8 +42,10 @@ class FileStorageAdapter(StorageAdapterBase):
40
42
 
41
43
  # ---------------------------------------------------------------- upload
42
44
  def upload(self, key: str, data: BinaryIO) -> str:
43
- """Copy *data* to ``${root_dir}/${key}`` atomically and return the artifact URI."""
44
- dest = self._full_key(key)
45
+ """Copy *data* to ``${root_dir}/${key}`` atomically and return the
46
+ artifact URI."""
47
+ normalized_key = self.normalize_key(key)
48
+ dest = self._full_key(key, allow_empty=False)
45
49
  dest.parent.mkdir(parents=True, exist_ok=True)
46
50
 
47
51
  tmp = dest.with_suffix(dest.suffix + ".tmp")
@@ -50,12 +54,13 @@ class FileStorageAdapter(StorageAdapterBase):
50
54
 
51
55
  tmp.replace(dest)
52
56
 
53
- return f"{self.root_uri}{key.lstrip('/')}"
57
+ return f"{self.root_uri}{normalized_key}"
54
58
 
55
59
  # ---------------------------------------------------------------- download
56
60
  def download(self, key: str) -> BinaryIO:
57
- """Return a :class:`BytesIO` with the contents of ``${root_dir}/${key}``."""
58
- path = self._full_key(key)
61
+ """Return a :class:`BytesIO` with the contents of
62
+ ``${root_dir}/${key}``."""
63
+ path = self._full_key(key, allow_empty=False)
59
64
  if not path.exists():
60
65
  raise FileNotFoundError(path)
61
66
 
@@ -63,18 +68,20 @@ class FileStorageAdapter(StorageAdapterBase):
63
68
  buffer.seek(0)
64
69
  return buffer
65
70
 
66
- # ---------------------------------------------------------------- upload_dir
71
+ # ----------------------------------------------------------------
72
+ # upload_dir
67
73
  def upload_dir(self, src: str | os.PathLike, *, prefix: str = "") -> None:
68
74
  """Recursively upload files from *src* under ``prefix``."""
69
75
  base = Path(src)
70
76
  for path in base.rglob("*"):
71
77
  if path.is_file():
72
78
  rel = path.relative_to(base)
73
- key = os.path.join(prefix, rel.as_posix())
79
+ key = self.compose_key(prefix, rel.as_posix())
74
80
  with path.open("rb") as fh:
75
81
  self.upload(key, fh)
76
82
 
77
- # ---------------------------------------------------------------- iter_prefix
83
+ # ----------------------------------------------------------------
84
+ # iter_prefix
78
85
  def iter_prefix(self, prefix: str):
79
86
  """Yield stored keys beginning with ``prefix``."""
80
87
  base = self._full_key(prefix)
@@ -83,9 +90,10 @@ class FileStorageAdapter(StorageAdapterBase):
83
90
  for path in base.rglob("*"):
84
91
  if path.is_file():
85
92
  rel = path.relative_to(self._root)
86
- yield str(rel)
93
+ yield rel.as_posix()
87
94
 
88
- # ---------------------------------------------------------------- download_dir
95
+ # ----------------------------------------------------------------
96
+ # download_dir
89
97
  def download_dir(self, prefix: str, dest_dir: str | os.PathLike) -> None:
90
98
  """Copy all files under ``prefix`` into ``dest_dir``."""
91
99
  src_root = self._full_key(prefix)
@@ -95,7 +103,7 @@ class FileStorageAdapter(StorageAdapterBase):
95
103
  for path in src_root.rglob("*"):
96
104
  if path.is_file():
97
105
  rel = path.relative_to(src_root)
98
- target = dest / rel
106
+ target = self.download_target_for_key(dest, rel.as_posix())
99
107
  target.parent.mkdir(parents=True, exist_ok=True)
100
108
  shutil.copy2(path, target)
101
109