xiaoshiai-hub 0.1.0__py3-none-any.whl → 0.1.2__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.
tests/test_download.py DELETED
@@ -1,142 +0,0 @@
1
- """
2
- Tests for download functionality
3
- """
4
-
5
- import os
6
- import tempfile
7
- import unittest
8
- from unittest.mock import Mock, patch, MagicMock
9
-
10
- from xiaoshiai_hub.download import (
11
- _match_pattern,
12
- _should_download_file,
13
- hf_hub_download,
14
- snapshot_download,
15
- )
16
-
17
-
18
- class TestPatternMatching(unittest.TestCase):
19
- """Test pattern matching functions."""
20
-
21
- def test_match_pattern_exact(self):
22
- """Test exact pattern matching."""
23
- self.assertTrue(_match_pattern("config.yaml", "config.yaml"))
24
- self.assertFalse(_match_pattern("config.yml", "config.yaml"))
25
-
26
- def test_match_pattern_wildcard(self):
27
- """Test wildcard pattern matching."""
28
- self.assertTrue(_match_pattern("config.yaml", "*.yaml"))
29
- self.assertTrue(_match_pattern("model.yml", "*.yml"))
30
- self.assertFalse(_match_pattern("config.txt", "*.yaml"))
31
-
32
- def test_match_pattern_prefix(self):
33
- """Test prefix pattern matching."""
34
- self.assertTrue(_match_pattern("config.yaml", "config*"))
35
- self.assertTrue(_match_pattern("config_v2.yaml", "config*"))
36
- self.assertFalse(_match_pattern("model.yaml", "config*"))
37
-
38
- def test_should_download_file_no_patterns(self):
39
- """Test file download decision with no patterns."""
40
- self.assertTrue(_should_download_file("config.yaml"))
41
- self.assertTrue(_should_download_file("model.bin"))
42
-
43
- def test_should_download_file_allow_patterns(self):
44
- """Test file download decision with allow patterns."""
45
- allow = ["*.yaml", "*.yml"]
46
- self.assertTrue(_should_download_file("config.yaml", allow_patterns=allow))
47
- self.assertTrue(_should_download_file("model.yml", allow_patterns=allow))
48
- self.assertFalse(_should_download_file("model.bin", allow_patterns=allow))
49
-
50
- def test_should_download_file_ignore_patterns(self):
51
- """Test file download decision with ignore patterns."""
52
- ignore = [".git*", "*.tmp"]
53
- self.assertFalse(_should_download_file(".gitignore", ignore_patterns=ignore))
54
- self.assertFalse(_should_download_file("temp.tmp", ignore_patterns=ignore))
55
- self.assertTrue(_should_download_file("config.yaml", ignore_patterns=ignore))
56
-
57
- def test_should_download_file_both_patterns(self):
58
- """Test file download decision with both allow and ignore patterns."""
59
- allow = ["*.yaml", "*.yml"]
60
- ignore = [".git*"]
61
-
62
- self.assertTrue(_should_download_file("config.yaml", allow, ignore))
63
- self.assertFalse(_should_download_file(".gitignore", allow, ignore))
64
- self.assertFalse(_should_download_file("model.bin", allow, ignore))
65
-
66
-
67
- class TestDownloadFunctions(unittest.TestCase):
68
- """Test download functions."""
69
-
70
- @patch('xiaoshiai_hub.download.HubClient')
71
- def test_hf_hub_download(self, mock_client_class):
72
- """Test hf_hub_download function."""
73
- # Setup mock
74
- mock_client = Mock()
75
- mock_client_class.return_value = mock_client
76
-
77
- mock_repo_info = Mock()
78
- mock_repo_info.default_branch = "main"
79
- mock_client.get_repository_info.return_value = mock_repo_info
80
-
81
- # Test download
82
- with tempfile.TemporaryDirectory() as tmpdir:
83
- result = hf_hub_download(
84
- repo_id="demo/demo",
85
- filename="config.yaml",
86
- local_dir=tmpdir,
87
- username="test",
88
- password="test",
89
- )
90
-
91
- # Verify client was created with correct params
92
- mock_client_class.assert_called_once()
93
-
94
- # Verify download was called
95
- mock_client.download_file.assert_called_once()
96
-
97
- # Verify result path
98
- self.assertIn("config.yaml", result)
99
-
100
- @patch('xiaoshiai_hub.download.HubClient')
101
- def test_snapshot_download(self, mock_client_class):
102
- """Test snapshot_download function."""
103
- # Setup mock
104
- mock_client = Mock()
105
- mock_client_class.return_value = mock_client
106
-
107
- mock_repo_info = Mock()
108
- mock_repo_info.default_branch = "main"
109
- mock_client.get_repository_info.return_value = mock_repo_info
110
-
111
- # Mock content structure
112
- mock_file = Mock()
113
- mock_file.type = "file"
114
- mock_file.path = "config.yaml"
115
-
116
- mock_content = Mock()
117
- mock_content.entries = [mock_file]
118
- mock_client.get_repository_content.return_value = mock_content
119
-
120
- # Test download
121
- with tempfile.TemporaryDirectory() as tmpdir:
122
- result = snapshot_download(
123
- repo_id="demo/demo",
124
- local_dir=tmpdir,
125
- username="test",
126
- password="test",
127
- verbose=False,
128
- )
129
-
130
- # Verify client was created
131
- mock_client_class.assert_called_once()
132
-
133
- # Verify download was called
134
- mock_client.download_file.assert_called()
135
-
136
- # Verify result path
137
- self.assertEqual(result, tmpdir)
138
-
139
-
140
- if __name__ == '__main__':
141
- unittest.main()
142
-
@@ -1,321 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: xiaoshiai-hub
3
- Version: 0.1.0
4
- Summary: Python SDK for XiaoShi AI Hub
5
- Home-page: https://github.com/poxiaoyun/XiaoShi-Moha
6
- Author: XiaoShi AI
7
- Author-email: XiaoShi AI <support@xiaoshiai.cn>
8
- License: Apache-2.0
9
- Project-URL: Homepage, https://github.com/poxiaoyun/XiaoShi-Moha
10
- Project-URL: Documentation, https://github.com/poxiaoyun/XiaoShi-Moha/tree/main/python-sdk
11
- Project-URL: Repository, https://github.com/poxiaoyun/XiaoShi-Moha
12
- Project-URL: Issues, https://github.com/poxiaoyun/XiaoShi-Moha/issues
13
- Classifier: Development Status :: 3 - Alpha
14
- Classifier: Intended Audience :: Developers
15
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
- Classifier: License :: OSI Approved :: Apache Software License
17
- Classifier: Programming Language :: Python :: 3
18
- Classifier: Programming Language :: Python :: 3.7
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Requires-Python: >=3.7
24
- Description-Content-Type: text/markdown
25
- License-File: LICENSE
26
- Requires-Dist: requests>=2.20.0
27
- Requires-Dist: tqdm>=4.62.0
28
- Provides-Extra: dev
29
- Requires-Dist: pytest>=6.0; extra == "dev"
30
- Requires-Dist: pytest-cov>=2.0; extra == "dev"
31
- Requires-Dist: black>=22.0; extra == "dev"
32
- Requires-Dist: flake8>=4.0; extra == "dev"
33
- Requires-Dist: mypy>=0.950; extra == "dev"
34
- Requires-Dist: build>=0.8.0; extra == "dev"
35
- Requires-Dist: twine>=4.0.0; extra == "dev"
36
- Dynamic: author
37
- Dynamic: home-page
38
- Dynamic: license-file
39
- Dynamic: requires-python
40
-
41
- # XiaoShi AI Hub Python SDK
42
-
43
- Python SDK for interacting with XiaoShi AI Hub repositories. This library provides a simple and intuitive interface for downloading models and datasets from XiaoShi AI Hub, similar to the Hugging Face Hub API.
44
-
45
- ## Installation
46
-
47
- ```bash
48
- pip install xiaoshiai-hub
49
- ```
50
-
51
- Or install from source:
52
-
53
- ```bash
54
- cd python-sdk
55
- pip install -e .
56
- ```
57
-
58
- ## Features
59
-
60
- - ✅ **Download single files or entire repositories**
61
- - ✅ **Progress bars** (like Hugging Face Hub) for download tracking
62
- - ✅ **Pattern-based filtering** with allow/ignore patterns
63
- - ✅ **Multiple authentication methods** (username/password, token)
64
- - ✅ **Environment variable configuration** for flexible Hub URL setup
65
- - ✅ **Caching support** for efficient reuse
66
- - ✅ **Type hints** for better IDE support
67
-
68
- ## Quick Start
69
-
70
- ### Download a Single File
71
-
72
- ```python
73
- from xiaoshiai_hub import hf_hub_download
74
-
75
- # Download a single file
76
- file_path = hf_hub_download(
77
- repo_id="demo/demo",
78
- filename="config.yaml",
79
- repo_type="models", # or "datasets"
80
- username="your-username",
81
- password="your-password",
82
- )
83
-
84
- print(f"File downloaded to: {file_path}")
85
- ```
86
-
87
- ### Download Entire Repository
88
-
89
- ```python
90
- from xiaoshiai_hub import snapshot_download
91
-
92
- # Download entire repository
93
- repo_path = snapshot_download(
94
- repo_id="demo/demo",
95
- repo_type="models",
96
- username="your-username",
97
- password="your-password",
98
- )
99
-
100
- print(f"Repository downloaded to: {repo_path}")
101
- ```
102
-
103
- ### Download with Filters
104
-
105
- ```python
106
- from xiaoshiai_hub import snapshot_download
107
-
108
- # Download only YAML files, ignoring .git files
109
- repo_path = snapshot_download(
110
- repo_id="demo/demo",
111
- repo_type="models",
112
- allow_patterns=["*.yaml", "*.yml"],
113
- ignore_patterns=[".git*"],
114
- username="your-username",
115
- password="your-password",
116
- )
117
- ```
118
-
119
- ## Advanced Usage
120
-
121
- ### Using the Client Directly
122
-
123
- ```python
124
- from xiaoshiai_hub import HubClient
125
-
126
- # Create a client
127
- client = HubClient(
128
- base_url="https://rune.develop.xiaoshiai.cn/api/moha",
129
- username="your-username",
130
- password="your-password",
131
- )
132
-
133
- # Get repository information
134
- repo_info = client.get_repository_info(
135
- organization="demo",
136
- repo_type="models",
137
- repo_name="demo",
138
- )
139
- print(f"Repository: {repo_info.name}")
140
- print(f"Default branch: {repo_info.default_branch}")
141
-
142
- # List branches and tags
143
- refs = client.get_repository_refs(
144
- organization="demo",
145
- repo_type="models",
146
- repo_name="demo",
147
- )
148
- for ref in refs:
149
- print(f"{ref.type}: {ref.name} ({ref.hash})")
150
-
151
- # Get repository content
152
- content = client.get_repository_content(
153
- organization="demo",
154
- repo_type="models",
155
- repo_name="demo",
156
- branch="main",
157
- path="", # root directory
158
- )
159
-
160
- # List files
161
- if content.entries:
162
- for entry in content.entries:
163
- print(f"{entry.type}: {entry.path} ({entry.size} bytes)")
164
-
165
- # Download a specific file
166
- client.download_file(
167
- organization="demo",
168
- repo_type="models",
169
- repo_name="demo",
170
- branch="main",
171
- file_path="config.yaml",
172
- local_path="./config.yaml",
173
- )
174
- ```
175
-
176
- ### Authentication
177
-
178
- The SDK supports multiple authentication methods:
179
-
180
- #### Username and Password
181
-
182
- ```python
183
- from xiaoshiai_hub import HubClient
184
-
185
- client = HubClient(
186
- username="your-username",
187
- password="your-password",
188
- )
189
- ```
190
-
191
- #### Token-based Authentication
192
-
193
- ```python
194
- from xiaoshiai_hub import HubClient
195
-
196
- client = HubClient(
197
- token="your-api-token",
198
- )
199
- ```
200
-
201
- ### Custom Base URL
202
-
203
- ```python
204
- from xiaoshiai_hub import snapshot_download
205
-
206
- repo_path = snapshot_download(
207
- repo_id="demo/demo",
208
- base_url="https://your-custom-hub.example.com/api/moha",
209
- username="your-username",
210
- password="your-password",
211
- )
212
- ```
213
-
214
- ### Specify Revision (Branch/Tag)
215
-
216
- ```python
217
- from xiaoshiai_hub import snapshot_download
218
-
219
- # Download from a specific branch
220
- repo_path = snapshot_download(
221
- repo_id="demo/demo",
222
- revision="develop",
223
- username="your-username",
224
- password="your-password",
225
- )
226
- ```
227
-
228
- ### Cache Directory
229
-
230
- ```python
231
- from xiaoshiai_hub import snapshot_download
232
-
233
- # Use a custom cache directory
234
- repo_path = snapshot_download(
235
- repo_id="demo/demo",
236
- cache_dir="~/.cache/xiaoshiai",
237
- username="your-username",
238
- password="your-password",
239
- )
240
- ```
241
-
242
- ## API Reference
243
-
244
- ### Functions
245
-
246
- #### `hf_hub_download()`
247
-
248
- Download a single file from a repository.
249
-
250
- **Parameters:**
251
- - `repo_id` (str): Repository ID in format "organization/repo_name"
252
- - `filename` (str): Path to the file in the repository
253
- - `repo_type` (str, optional): "models" or "datasets" (default: "models")
254
- - `revision` (str, optional): Branch/tag/commit to download from
255
- - `cache_dir` (str | Path, optional): Directory to cache files
256
- - `local_dir` (str | Path, optional): Directory to save the file
257
- - `base_url` (str, optional): Base URL of the Hub API
258
- - `username` (str, optional): Username for authentication
259
- - `password` (str, optional): Password for authentication
260
- - `token` (str, optional): Token for authentication
261
-
262
- **Returns:** Path to the downloaded file
263
-
264
- #### `snapshot_download()`
265
-
266
- Download an entire repository snapshot.
267
-
268
- **Parameters:**
269
- - `repo_id` (str): Repository ID in format "organization/repo_name"
270
- - `repo_type` (str, optional): "models" or "datasets" (default: "models")
271
- - `revision` (str, optional): Branch/tag/commit to download from
272
- - `cache_dir` (str | Path, optional): Directory to cache files
273
- - `local_dir` (str | Path, optional): Directory to save files
274
- - `allow_patterns` (str | List[str], optional): Patterns to allow (e.g., "*.yaml")
275
- - `ignore_patterns` (str | List[str], optional): Patterns to ignore (e.g., ".git*")
276
- - `base_url` (str, optional): Base URL of the Hub API
277
- - `username` (str, optional): Username for authentication
278
- - `password` (str, optional): Password for authentication
279
- - `token` (str, optional): Token for authentication
280
- - `verbose` (bool, optional): Print progress messages (default: True)
281
-
282
- **Returns:** Path to the downloaded repository
283
-
284
- ### Classes
285
-
286
- #### `HubClient`
287
-
288
- Main client for interacting with the Hub API.
289
-
290
- **Methods:**
291
- - `get_repository_info(organization, repo_type, repo_name)`: Get repository information
292
- - `get_repository_refs(organization, repo_type, repo_name)`: List branches and tags
293
- - `get_repository_content(organization, repo_type, repo_name, branch, path)`: Get content at path
294
- - `download_file(organization, repo_type, repo_name, branch, file_path, local_path)`: Download a file
295
-
296
- ## API Endpoints
297
-
298
- The SDK uses the following API endpoints:
299
-
300
- 1. **Repository Info**: `GET /organizations/{org}/{type}/{repo}`
301
- 2. **Repository Refs**: `GET /organizations/{org}/{type}/{repo}/refs`
302
- 3. **Repository Content**: `GET /organizations/{org}/{type}/{repo}/contents/{branch}/{path}`
303
- 4. **File Download**: `GET /organizations/{org}/{type}/{repo}/resolve/{branch}/{file}`
304
-
305
- ## Examples
306
-
307
- See the `examples/` directory for more examples:
308
-
309
- - `examples/download_single_file.py`: Download a single file
310
- - `examples/download_repository.py`: Download entire repository
311
- - `examples/download_with_filters.py`: Download with pattern filters
312
- - `examples/list_repository_content.py`: List repository contents
313
-
314
- ## License
315
-
316
- Apache License 2.0
317
-
318
- ## Contributing
319
-
320
- Contributions are welcome! Please feel free to submit a Pull Request.
321
-
@@ -1,12 +0,0 @@
1
- tests/__init__.py,sha256=ylJ7kigwI9UabE5kJJNJiBggcCucvp4nUtq4fy2xUwU,45
2
- tests/test_download.py,sha256=56Ce5URs8GsDvkd3PjXql9tNHkv8kyGELSVw-6b00Rk,5186
3
- xiaoshiai_hub/__init__.py,sha256=MKXxElvZhGVsogjHVRKE47KvQiATY3gMgvBo-9eIdEw,712
4
- xiaoshiai_hub/client.py,sha256=xyH9F2Dzllb1vtWDsmZuah0_PQnfgyBmfWOqJ0jlYkc,8224
5
- xiaoshiai_hub/download.py,sha256=CYm6BS2r9tv__kFmKmyIhCLseF4wNBrCzcVcKQ461yM,14297
6
- xiaoshiai_hub/exceptions.py,sha256=mwiQNrPWByIjXDcsj5Pdn-Bc82h0DLQZegjnFsNfIzo,668
7
- xiaoshiai_hub/types.py,sha256=Mwo6zdHs-v612yaZeKIWsaMF7FgxFauAPDuQrqyiREo,1777
8
- xiaoshiai_hub-0.1.0.dist-info/licenses/LICENSE,sha256=tS28u6VpvqNisRWGeufp-XYQc6p194vOGARl3OIjidA,9110
9
- xiaoshiai_hub-0.1.0.dist-info/METADATA,sha256=TJxVmxN9nVYrGbkNJ0HtBmjmlKVX_yreFIUfIcREEj8,8791
10
- xiaoshiai_hub-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- xiaoshiai_hub-0.1.0.dist-info/top_level.txt,sha256=yJG2aKJGzWHXUFUPu3mL35fQtuy2KZ-IHlmMVBRS6K4,20
12
- xiaoshiai_hub-0.1.0.dist-info/RECORD,,