widpath 0.1.0__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.
widpath-0.1.0/LICENSE ADDED
File without changes
widpath-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: widpath
3
+ Version: 0.1.0
4
+ Summary: A hierarchical file path resolver for WID-based storage
5
+ Author-email: "sheng.SMLH" <sheng@smlh.com>
6
+ Project-URL: Homepage, https://github.com/yourusername/widpath
7
+ Keywords: wid,file storage,hierarchical path
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Dynamic: license-file
12
+
13
+ # widpath
14
+
15
+ `widpath` 是一个基于 **WID 分层规则** 的文件路径解析器,可以把长字符串 WID 映射到分层文件系统路径,用于存储和查找大规模 JSON 文件。
16
+
17
+ 它的目标是方便地将数据切分为层次化的目录结构,避免单目录下文件过多,同时支持二分查找已有文件。
18
+
19
+ ---
20
+
21
+ ## ✨ 特性
22
+
23
+ - 支持将 WID 按固定大小分块,生成分层路径
24
+ - 支持查找 **最合适的存储文件路径**(使用二分查找)
25
+ - 默认从最深层开始回溯,效率接近 `O(logN)`
26
+ - 可配置分块大小(默认为 `2`)和分隔符(默认为 `/`)
27
+ - 简单易用,几行代码即可集成
28
+
29
+
30
+ ---
31
+ ## 与现有方案对比
32
+
33
+ 目前在 PyPI 上常见的一些路径操作工具包括:
34
+
35
+ | 包名 / 类型 | 功能亮点 | 与 `widpath` 的区别 |
36
+ | ------------------ | ----------------------- | ---------------------- |
37
+ | **widpath** (本包) | 根据 WID 切片 + 分层路径 + 二分查找 | 专为 WID 管理设计,支持快速定位存储路径 |
38
+ | `wildpath` | 通配符访问数据结构 | 与文件系统路径分层无关 |
39
+ | `path` / `path.py` | 更友好的路径操作接口 | 注重路径 API,不支持 WID 分层策略 |
40
+ | 标准库 `pathlib` | 面向对象的路径处理,跨平台兼容 | 基础操作,不支持分层和二分查找 |
41
+
42
+ 结论:
43
+ widpath 提供了一种专门针对 WID 的分层文件管理与查找机制,是对现有通用路径库的有益补充。
44
+
45
+ ---
46
+
47
+ ## 📦 安装
48
+
49
+ ### 从 PyPI 安装
50
+ ```bash
51
+ pip install widpath
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 支持作者
57
+
58
+ 如果你觉得这个项目对你有帮助,可以考虑捐赠支持开发:
59
+
60
+ ### 现金支持
61
+
62
+ - PayPal:
63
+
64
+ ### 数字货币支持
65
+
66
+ - Bitcoin (BTC): bc1qa5g4aeg6rp8m46c4lwxfapesmwkns0rhjmm65g
67
+ - Ethereum (ETH): 0xA466f5E4D0eaAc20f38154D7D4F0a2b75076e0a0
68
+
69
+ 非常感谢你的支持 🙏
@@ -0,0 +1,57 @@
1
+ # widpath
2
+
3
+ `widpath` 是一个基于 **WID 分层规则** 的文件路径解析器,可以把长字符串 WID 映射到分层文件系统路径,用于存储和查找大规模 JSON 文件。
4
+
5
+ 它的目标是方便地将数据切分为层次化的目录结构,避免单目录下文件过多,同时支持二分查找已有文件。
6
+
7
+ ---
8
+
9
+ ## ✨ 特性
10
+
11
+ - 支持将 WID 按固定大小分块,生成分层路径
12
+ - 支持查找 **最合适的存储文件路径**(使用二分查找)
13
+ - 默认从最深层开始回溯,效率接近 `O(logN)`
14
+ - 可配置分块大小(默认为 `2`)和分隔符(默认为 `/`)
15
+ - 简单易用,几行代码即可集成
16
+
17
+
18
+ ---
19
+ ## 与现有方案对比
20
+
21
+ 目前在 PyPI 上常见的一些路径操作工具包括:
22
+
23
+ | 包名 / 类型 | 功能亮点 | 与 `widpath` 的区别 |
24
+ | ------------------ | ----------------------- | ---------------------- |
25
+ | **widpath** (本包) | 根据 WID 切片 + 分层路径 + 二分查找 | 专为 WID 管理设计,支持快速定位存储路径 |
26
+ | `wildpath` | 通配符访问数据结构 | 与文件系统路径分层无关 |
27
+ | `path` / `path.py` | 更友好的路径操作接口 | 注重路径 API,不支持 WID 分层策略 |
28
+ | 标准库 `pathlib` | 面向对象的路径处理,跨平台兼容 | 基础操作,不支持分层和二分查找 |
29
+
30
+ 结论:
31
+ widpath 提供了一种专门针对 WID 的分层文件管理与查找机制,是对现有通用路径库的有益补充。
32
+
33
+ ---
34
+
35
+ ## 📦 安装
36
+
37
+ ### 从 PyPI 安装
38
+ ```bash
39
+ pip install widpath
40
+ ```
41
+
42
+ ---
43
+
44
+ ## 支持作者
45
+
46
+ 如果你觉得这个项目对你有帮助,可以考虑捐赠支持开发:
47
+
48
+ ### 现金支持
49
+
50
+ - PayPal:
51
+
52
+ ### 数字货币支持
53
+
54
+ - Bitcoin (BTC): bc1qa5g4aeg6rp8m46c4lwxfapesmwkns0rhjmm65g
55
+ - Ethereum (ETH): 0xA466f5E4D0eaAc20f38154D7D4F0a2b75076e0a0
56
+
57
+ 非常感谢你的支持 🙏
@@ -0,0 +1,18 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "widpath"
7
+ version = "0.1.0"
8
+ description = "A hierarchical file path resolver for WID-based storage"
9
+ authors = [
10
+ { name = "sheng.SMLH", email = "sheng@smlh.com" }
11
+ ]
12
+ readme = "README.md"
13
+ license = { file = "LICENSE" }
14
+ requires-python = ">=3.8"
15
+ keywords = ["wid", "file storage", "hierarchical path"]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/yourusername/widpath"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .resolver import WidPathResolver
2
+
3
+ __all__ = ["WidPathResolver"]
@@ -0,0 +1,43 @@
1
+ from pathlib import Path
2
+
3
+ class WidPathResolver:
4
+ def __init__(self, size: int = 2, separator: str = "/"):
5
+ self.size = size
6
+ self.separator = separator
7
+
8
+ def _split_wid(self, wid: str):
9
+ return [wid[i:i + self.size] for i in range(0, len(wid), self.size)]
10
+
11
+ def get_max_level(self, wid: str) -> int:
12
+ return len(wid) // self.size - 1
13
+
14
+ def get_hierarchical_json(self, wid: str, level: int) -> Path:
15
+ parts = self._split_wid(wid)
16
+ max_level = self.get_max_level(wid)
17
+ level = min(max(level, 0), max_level)
18
+ if level >= max_level:
19
+ return Path(self.separator.join(parts[:max_level+1]) + ".json")
20
+ else:
21
+ return Path(self.separator.join(parts[:level+1]) + ".json")
22
+
23
+ def get_file_path(self, wid: str) -> Path:
24
+ min_level = 0
25
+ max_level = self.get_max_level(wid)
26
+ level = max_level
27
+
28
+ while True:
29
+ cur_file = self.get_hierarchical_json(wid, level)
30
+ if cur_file.exists():
31
+ return cur_file
32
+ if not cur_file.parent.exists():
33
+ if level == min_level:
34
+ return cur_file
35
+ max_level = level
36
+ level = (level + min_level) // 2
37
+ else:
38
+ next_file = self.get_hierarchical_json(wid, level+1)
39
+ if next_file != cur_file and next_file.parent.exists():
40
+ min_level = level
41
+ level = (level + max_level) // 2
42
+ else:
43
+ return cur_file
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: widpath
3
+ Version: 0.1.0
4
+ Summary: A hierarchical file path resolver for WID-based storage
5
+ Author-email: "sheng.SMLH" <sheng@smlh.com>
6
+ Project-URL: Homepage, https://github.com/yourusername/widpath
7
+ Keywords: wid,file storage,hierarchical path
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Dynamic: license-file
12
+
13
+ # widpath
14
+
15
+ `widpath` 是一个基于 **WID 分层规则** 的文件路径解析器,可以把长字符串 WID 映射到分层文件系统路径,用于存储和查找大规模 JSON 文件。
16
+
17
+ 它的目标是方便地将数据切分为层次化的目录结构,避免单目录下文件过多,同时支持二分查找已有文件。
18
+
19
+ ---
20
+
21
+ ## ✨ 特性
22
+
23
+ - 支持将 WID 按固定大小分块,生成分层路径
24
+ - 支持查找 **最合适的存储文件路径**(使用二分查找)
25
+ - 默认从最深层开始回溯,效率接近 `O(logN)`
26
+ - 可配置分块大小(默认为 `2`)和分隔符(默认为 `/`)
27
+ - 简单易用,几行代码即可集成
28
+
29
+
30
+ ---
31
+ ## 与现有方案对比
32
+
33
+ 目前在 PyPI 上常见的一些路径操作工具包括:
34
+
35
+ | 包名 / 类型 | 功能亮点 | 与 `widpath` 的区别 |
36
+ | ------------------ | ----------------------- | ---------------------- |
37
+ | **widpath** (本包) | 根据 WID 切片 + 分层路径 + 二分查找 | 专为 WID 管理设计,支持快速定位存储路径 |
38
+ | `wildpath` | 通配符访问数据结构 | 与文件系统路径分层无关 |
39
+ | `path` / `path.py` | 更友好的路径操作接口 | 注重路径 API,不支持 WID 分层策略 |
40
+ | 标准库 `pathlib` | 面向对象的路径处理,跨平台兼容 | 基础操作,不支持分层和二分查找 |
41
+
42
+ 结论:
43
+ widpath 提供了一种专门针对 WID 的分层文件管理与查找机制,是对现有通用路径库的有益补充。
44
+
45
+ ---
46
+
47
+ ## 📦 安装
48
+
49
+ ### 从 PyPI 安装
50
+ ```bash
51
+ pip install widpath
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 支持作者
57
+
58
+ 如果你觉得这个项目对你有帮助,可以考虑捐赠支持开发:
59
+
60
+ ### 现金支持
61
+
62
+ - PayPal:
63
+
64
+ ### 数字货币支持
65
+
66
+ - Bitcoin (BTC): bc1qa5g4aeg6rp8m46c4lwxfapesmwkns0rhjmm65g
67
+ - Ethereum (ETH): 0xA466f5E4D0eaAc20f38154D7D4F0a2b75076e0a0
68
+
69
+ 非常感谢你的支持 🙏
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/widpath/__init__.py
5
+ src/widpath/resolver.py
6
+ src/widpath.egg-info/PKG-INFO
7
+ src/widpath.egg-info/SOURCES.txt
8
+ src/widpath.egg-info/dependency_links.txt
9
+ src/widpath.egg-info/top_level.txt
10
+ tests/test_resolver.py
@@ -0,0 +1 @@
1
+ widpath
@@ -0,0 +1,53 @@
1
+ import pytest
2
+ from pathlib import Path
3
+ from widpath import WidPathResolver
4
+
5
+ @pytest.fixture
6
+ def resolver():
7
+ return WidPathResolver(size=2)
8
+
9
+ @pytest.fixture
10
+ def sample_wid():
11
+ return "dc10ce02019b8ed9787869d0103e9c4b" # 32 chars
12
+
13
+ def test_max_level(resolver, sample_wid):
14
+ max_level = resolver.get_max_level(sample_wid)
15
+ assert max_level == len(sample_wid)//2 - 1
16
+ assert max_level == 15 # 32/2 = 16 parts, max_level = 15
17
+
18
+ def test_hierarchical_json_levels(resolver, sample_wid):
19
+ # Level 0: dc.json
20
+ p0 = resolver.get_hierarchical_json(sample_wid, 0)
21
+ assert str(p0) == "dc.json"
22
+
23
+ # Level 1: dc/10.json
24
+ p1 = resolver.get_hierarchical_json(sample_wid, 1)
25
+ assert str(p1) == "dc/10.json"
26
+
27
+ # Level 2: dc/10/ce.json
28
+ p2 = resolver.get_hierarchical_json(sample_wid, 2)
29
+ assert str(p2) == "dc/10/ce.json"
30
+
31
+ # Max level: full split + .json
32
+ pmax = resolver.get_hierarchical_json(sample_wid, 100) # 超过 max_level 会被限制
33
+ assert str(pmax).endswith("4b.json")
34
+ assert str(pmax).count("/") == resolver.get_max_level(sample_wid)
35
+
36
+ def test_file_path_returns_path(resolver, sample_wid, tmp_path):
37
+ # 创建一个模拟的文件结构
38
+ target = tmp_path / "dc" / "10" / "ce.json"
39
+ target.parent.mkdir(parents=True, exist_ok=True)
40
+ target.write_text("{}")
41
+
42
+ # 切换到临时目录运行测试
43
+ cwd = Path.cwd()
44
+ try:
45
+ # 临时目录作为工作目录
46
+ import os
47
+ os.chdir(tmp_path)
48
+
49
+ result = resolver.get_file_path(sample_wid)
50
+ assert result.exists()
51
+ assert result == Path("dc/10/ce.json")
52
+ finally:
53
+ os.chdir(cwd)