flashmemory 0.0.1__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.
@@ -0,0 +1,8 @@
1
+ """
2
+ FlashMemory - Cross-language code analysis and semantic search system.
3
+
4
+ Supports Go, Python, JavaScript, Java, C++ code indexing with
5
+ LLM-powered analysis and Faiss-based semantic search.
6
+ """
7
+
8
+ __version__ = "0.0.1"
flashmemory/cli.py ADDED
@@ -0,0 +1,208 @@
1
+ """
2
+ FlashMemory CLI 入口
3
+ 首次运行时自动下载对应平台的 Go 二进制文件
4
+ """
5
+ import os
6
+ import sys
7
+ import platform
8
+ import stat
9
+ import shutil
10
+ import tarfile
11
+ import zipfile
12
+ import tempfile
13
+ import logging
14
+
15
+ logger = logging.getLogger("flashmemory")
16
+
17
+ REPO = "ZetaZeroHub/FlashMemory"
18
+ INSTALL_DIR = os.path.join(os.path.expanduser("~"), ".flashmemory", "bin")
19
+
20
+ # 平台映射
21
+ PLATFORM_MAP = {
22
+ "Darwin": "darwin",
23
+ "Linux": "linux",
24
+ "Windows": "windows",
25
+ }
26
+
27
+ ARCH_MAP = {
28
+ "x86_64": "amd64",
29
+ "AMD64": "amd64",
30
+ "arm64": "arm64",
31
+ "aarch64": "arm64",
32
+ }
33
+
34
+
35
+ def get_platform_info():
36
+ """检测当前平台和架构"""
37
+ system = platform.system()
38
+ machine = platform.machine()
39
+
40
+ os_name = PLATFORM_MAP.get(system)
41
+ arch = ARCH_MAP.get(machine)
42
+
43
+ if not os_name:
44
+ print(f"❌ 不支持的操作系统: {system}", file=sys.stderr)
45
+ sys.exit(1)
46
+ if not arch:
47
+ print(f"❌ 不支持的 CPU 架构: {machine}", file=sys.stderr)
48
+ sys.exit(1)
49
+
50
+ return os_name, arch
51
+
52
+
53
+ def get_latest_version():
54
+ """从 GitHub 获取最新 Release 版本号"""
55
+ import requests
56
+
57
+ try:
58
+ resp = requests.get(
59
+ f"https://api.github.com/repos/{REPO}/releases/latest",
60
+ headers={"User-Agent": "flashmemory-pip"},
61
+ timeout=15,
62
+ )
63
+ resp.raise_for_status()
64
+ tag = resp.json().get("tag_name", "")
65
+ return tag.lstrip("v")
66
+ except Exception as e:
67
+ logger.error(f"获取最新版本失败: {e}")
68
+ return None
69
+
70
+
71
+ def download_file(url, dest):
72
+ """下载文件(支持重定向)"""
73
+ import requests
74
+
75
+ resp = requests.get(
76
+ url,
77
+ headers={"User-Agent": "flashmemory-pip"},
78
+ stream=True,
79
+ timeout=120,
80
+ allow_redirects=True,
81
+ )
82
+ resp.raise_for_status()
83
+
84
+ total = int(resp.headers.get("content-length", 0))
85
+ downloaded = 0
86
+
87
+ with open(dest, "wb") as f:
88
+ for chunk in resp.iter_content(chunk_size=8192):
89
+ f.write(chunk)
90
+ downloaded += len(chunk)
91
+ if total > 0:
92
+ pct = int(downloaded / total * 100)
93
+ bar = "=" * (pct // 2) + ">" + " " * (50 - pct // 2)
94
+ print(f"\r [{bar}] {pct}%", end="", flush=True)
95
+
96
+ if total > 0:
97
+ print() # newline after progress bar
98
+
99
+
100
+ def ensure_binary(binary_name):
101
+ """确保二进制文件存在,不存在则下载"""
102
+ ext = ".exe" if platform.system() == "Windows" else ""
103
+ bin_path = os.path.join(INSTALL_DIR, f"{binary_name}{ext}")
104
+
105
+ if os.path.isfile(bin_path):
106
+ return bin_path
107
+
108
+ # 需要下载
109
+ print(f"\n📦 FlashMemory 首次运行,正在下载二进制文件...")
110
+
111
+ os_name, arch = get_platform_info()
112
+ print(f" 平台: {os_name}/{arch}")
113
+
114
+ version = get_latest_version()
115
+ if not version:
116
+ print("❌ 无法获取版本信息,请检查网络", file=sys.stderr)
117
+ sys.exit(1)
118
+
119
+ print(f" 版本: v{version}")
120
+
121
+ archive_ext = "zip" if os_name == "windows" else "tar.gz"
122
+ archive_name = f"flashmemory_{version}_{os_name}_{arch}"
123
+ url = f"https://github.com/{REPO}/releases/download/v{version}/{archive_name}.{archive_ext}"
124
+
125
+ print(f" 下载: {url}")
126
+
127
+ # 创建安装目录
128
+ os.makedirs(INSTALL_DIR, exist_ok=True)
129
+
130
+ # 下载到临时目录
131
+ with tempfile.TemporaryDirectory() as tmp_dir:
132
+ archive_path = os.path.join(tmp_dir, f"flashmemory.{archive_ext}")
133
+ download_file(url, archive_path)
134
+ print(" ✅ 下载完成")
135
+
136
+ # 解压
137
+ if archive_ext == "zip":
138
+ with zipfile.ZipFile(archive_path, "r") as zf:
139
+ zf.extractall(tmp_dir)
140
+ else:
141
+ with tarfile.open(archive_path, "r:gz") as tf:
142
+ tf.extractall(tmp_dir)
143
+ print(" ✅ 解压完成")
144
+
145
+ # 复制文件到安装目录
146
+ extracted_dir = os.path.join(tmp_dir, archive_name)
147
+ if not os.path.isdir(extracted_dir):
148
+ # 查找解压后的目录
149
+ for d in os.listdir(tmp_dir):
150
+ full = os.path.join(tmp_dir, d)
151
+ if os.path.isdir(full) and d.startswith("flashmemory_"):
152
+ extracted_dir = full
153
+ break
154
+
155
+ for item in os.listdir(extracted_dir):
156
+ src = os.path.join(extracted_dir, item)
157
+ dst = os.path.join(INSTALL_DIR, item)
158
+ if os.path.isdir(src):
159
+ if os.path.exists(dst):
160
+ shutil.rmtree(dst)
161
+ shutil.copytree(src, dst)
162
+ else:
163
+ shutil.copy2(src, dst)
164
+
165
+ # 设置执行权限 (非 Windows)
166
+ if os_name != "windows":
167
+ for name in ["fm", "fm_http"]:
168
+ p = os.path.join(INSTALL_DIR, name)
169
+ if os.path.isfile(p):
170
+ st = os.stat(p)
171
+ os.chmod(p, st.st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
172
+
173
+ print(f" ✅ 安装完成: {INSTALL_DIR}\n")
174
+ return bin_path
175
+
176
+
177
+ def run_binary(binary_name):
178
+ """运行指定的二进制文件"""
179
+ bin_path = ensure_binary(binary_name)
180
+
181
+ # 设置 FAISS_SERVICE_PATH 环境变量
182
+ faiss_dir = os.path.join(INSTALL_DIR, "FAISSService")
183
+ if os.path.isdir(faiss_dir):
184
+ os.environ["FAISS_SERVICE_PATH"] = faiss_dir
185
+
186
+ # 执行二进制,透传所有参数
187
+ args = [bin_path] + sys.argv[1:]
188
+
189
+ if platform.system() == "Windows":
190
+ import subprocess
191
+ result = subprocess.run(args)
192
+ sys.exit(result.returncode)
193
+ else:
194
+ os.execv(bin_path, args)
195
+
196
+
197
+ def main_fm():
198
+ """fm 命令入口"""
199
+ run_binary("fm")
200
+
201
+
202
+ def main_fm_http():
203
+ """fm_http 命令入口"""
204
+ run_binary("fm_http")
205
+
206
+
207
+ if __name__ == "__main__":
208
+ main_fm()
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: flashmemory
3
+ Version: 0.0.1
4
+ Summary: FlashMemory - Cross-language code analysis and semantic search system
5
+ Author-email: ZetaZeroHub <contact@zzh.app>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ZetaZeroHub/FlashMemory
8
+ Project-URL: Repository, https://github.com/ZetaZeroHub/FlashMemory
9
+ Project-URL: Issues, https://github.com/ZetaZeroHub/FlashMemory/issues
10
+ Keywords: code-analysis,semantic-search,llm,faiss,code-indexing
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Code Generators
14
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Operating System :: MacOS
23
+ Classifier: Operating System :: POSIX :: Linux
24
+ Classifier: Operating System :: Microsoft :: Windows
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown
27
+ Requires-Dist: requests>=2.25.0
28
+
29
+ # FlashMemory
30
+
31
+ 跨语言代码分析与语义搜索系统。
32
+
33
+ ## 功能特性
34
+
35
+ - **多语言支持**:解析 Go / Python / JavaScript / Java / C++ 代码
36
+ - **智能分析**:使用 LLM 生成函数描述和语义理解
37
+ - **增量索引**:基于 Git 变更记录的高效更新机制
38
+ - **混合搜索**:支持语义搜索、关键词搜索和混合模式
39
+ - **知识图谱**:构建函数级别的代码依赖关系图
40
+
41
+ ## 安装
42
+
43
+ ```bash
44
+ pip install flashmemory
45
+ ```
46
+
47
+ ## 使用
48
+
49
+ ```bash
50
+ # CLI 工具
51
+ fm -dir /path/to/project -query "文件上传处理"
52
+
53
+ # HTTP 服务
54
+ fm_http
55
+ ```
56
+
57
+ ## 更多信息
58
+
59
+ - [GitHub](https://github.com/ZetaZeroHub/FlashMemory)
60
+ - [API 文档](https://github.com/ZetaZeroHub/FlashMemory/blob/main/cmd/app/README.md)
@@ -0,0 +1,7 @@
1
+ flashmemory/__init__.py,sha256=nor2MKP5Y2o_DNR50n7lKxWLMXO0HUjVoHw2at6WBK8,219
2
+ flashmemory/cli.py,sha256=nlt7J8nqDyYUE-RvI1ZQfoO3goKCBUFLHXxSCnfccg4,5784
3
+ flashmemory-0.0.1.dist-info/METADATA,sha256=kuezB8vSnUzJqP3fxaOdPdHmJjzn5BOUxNyBk-VAId4,2012
4
+ flashmemory-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
5
+ flashmemory-0.0.1.dist-info/entry_points.txt,sha256=e7U9uP9fQ3jy7cQiCO8bttl40pOLz6DX8a7-KY54IRk,86
6
+ flashmemory-0.0.1.dist-info/top_level.txt,sha256=t7mb8D3NHZyPb_WoBMaDmiEP9WMhefPDVg3Bp2BB9FY,12
7
+ flashmemory-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ fm = flashmemory.cli:main_fm
3
+ fm_http = flashmemory.cli:main_fm_http
@@ -0,0 +1 @@
1
+ flashmemory