getlibs 0.1.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.
- getlibs/__init__.py +10 -0
- getlibs/cli.py +218 -0
- getlibs-0.1.1.dist-info/METADATA +49 -0
- getlibs-0.1.1.dist-info/RECORD +8 -0
- getlibs-0.1.1.dist-info/WHEEL +5 -0
- getlibs-0.1.1.dist-info/entry_points.txt +2 -0
- getlibs-0.1.1.dist-info/licenses/LICENSE +0 -0
- getlibs-0.1.1.dist-info/top_level.txt +1 -0
getlibs/__init__.py
ADDED
getlibs/cli.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import json
|
|
3
|
+
import os
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
6
|
+
import argparse
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def probe_target_environment(python_executable):
|
|
12
|
+
"""
|
|
13
|
+
Verilen Python executable üzerinde çalışan bir probe script ile:
|
|
14
|
+
- Built-in modülleri
|
|
15
|
+
- Kurulu pip paketlerini ve versiyonlarını
|
|
16
|
+
- Import adı -> Paket adı eşleşmelerini
|
|
17
|
+
toplar.
|
|
18
|
+
"""
|
|
19
|
+
print(f"[{python_executable}] ortamı taranıyor...")
|
|
20
|
+
|
|
21
|
+
probe_code = """
|
|
22
|
+
import sys
|
|
23
|
+
import json
|
|
24
|
+
import importlib.metadata
|
|
25
|
+
|
|
26
|
+
data = {
|
|
27
|
+
"builtins": [],
|
|
28
|
+
"installed": {},
|
|
29
|
+
"import_map": {}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Built-in modüller
|
|
33
|
+
try:
|
|
34
|
+
data["builtins"] = list(getattr(sys, 'stdlib_module_names', sys.builtin_module_names))
|
|
35
|
+
except:
|
|
36
|
+
data["builtins"] = list(sys.builtin_module_names)
|
|
37
|
+
|
|
38
|
+
# Kurulu paketler ve import eşleşmeleri
|
|
39
|
+
for dist in importlib.metadata.distributions():
|
|
40
|
+
try:
|
|
41
|
+
name = dist.metadata['Name']
|
|
42
|
+
version = dist.version
|
|
43
|
+
data["installed"][name.lower()] = version
|
|
44
|
+
|
|
45
|
+
toplevels = dist.read_text('top_level.txt')
|
|
46
|
+
if toplevels:
|
|
47
|
+
for imp in toplevels.split():
|
|
48
|
+
clean = imp.replace('/', '.').replace('\\\\', '.').split('.')[0]
|
|
49
|
+
if clean:
|
|
50
|
+
data["import_map"][clean] = name
|
|
51
|
+
except:
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
print(json.dumps(data))
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
try:
|
|
58
|
+
output = subprocess.check_output(
|
|
59
|
+
[python_executable, "-c", probe_code],
|
|
60
|
+
text=True,
|
|
61
|
+
stderr=subprocess.PIPE
|
|
62
|
+
)
|
|
63
|
+
return json.loads(output)
|
|
64
|
+
|
|
65
|
+
except subprocess.CalledProcessError as e:
|
|
66
|
+
print("KRİTİK HATA: Hedef Python çalıştırılamadı")
|
|
67
|
+
print(e.stderr)
|
|
68
|
+
sys.exit(1)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_local_modules(directory):
|
|
72
|
+
"""Projedeki yerel modül isimlerini çıkarır."""
|
|
73
|
+
modules = set()
|
|
74
|
+
|
|
75
|
+
for root, dirs, files in os.walk(directory):
|
|
76
|
+
for f in files:
|
|
77
|
+
if f.endswith(".py"):
|
|
78
|
+
modules.add(f[:-3])
|
|
79
|
+
|
|
80
|
+
for d in dirs:
|
|
81
|
+
if os.path.exists(os.path.join(root, d, "__init__.py")):
|
|
82
|
+
modules.add(d)
|
|
83
|
+
|
|
84
|
+
return modules
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def get_imports_from_file(file_path):
|
|
88
|
+
"""Bir Python dosyasındaki üst seviye import'ları AST ile çıkarır."""
|
|
89
|
+
imports = set()
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
tree = ast.parse(Path(file_path).read_text(encoding="utf-8"))
|
|
93
|
+
for node in ast.walk(tree):
|
|
94
|
+
if isinstance(node, ast.Import):
|
|
95
|
+
for alias in node.names:
|
|
96
|
+
imports.add(alias.name.split(".")[0])
|
|
97
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
98
|
+
imports.add(node.module.split(".")[0])
|
|
99
|
+
except Exception:
|
|
100
|
+
pass
|
|
101
|
+
|
|
102
|
+
return imports
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def analyze_project(project_dir, python_exec):
|
|
106
|
+
env = probe_target_environment(python_exec)
|
|
107
|
+
|
|
108
|
+
builtins = set(env.get("builtins", []))
|
|
109
|
+
installed = env.get("installed", {})
|
|
110
|
+
import_map = env.get("import_map", {})
|
|
111
|
+
|
|
112
|
+
local_modules = get_local_modules(project_dir)
|
|
113
|
+
|
|
114
|
+
used_packages = {}
|
|
115
|
+
report_lines = []
|
|
116
|
+
json_output = {
|
|
117
|
+
"project": str(project_dir),
|
|
118
|
+
"target_python": python_exec,
|
|
119
|
+
"files": {},
|
|
120
|
+
"summary": {}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
report_lines.append(f"ANALİZ RAPORU: {project_dir}")
|
|
124
|
+
report_lines.append(f"Target Python: {python_exec}")
|
|
125
|
+
report_lines.append("=" * 70)
|
|
126
|
+
|
|
127
|
+
for root, _, files in os.walk(project_dir):
|
|
128
|
+
for file in files:
|
|
129
|
+
if not file.endswith(".py"):
|
|
130
|
+
continue
|
|
131
|
+
|
|
132
|
+
file_path = os.path.join(root, file)
|
|
133
|
+
imports = get_imports_from_file(file_path)
|
|
134
|
+
if not imports:
|
|
135
|
+
continue
|
|
136
|
+
|
|
137
|
+
rel = os.path.relpath(file_path, project_dir)
|
|
138
|
+
report_lines.append(f"\nDosya: {rel}")
|
|
139
|
+
report_lines.append("-" * 40)
|
|
140
|
+
|
|
141
|
+
deps = []
|
|
142
|
+
|
|
143
|
+
for lib in sorted(imports):
|
|
144
|
+
# Yerel
|
|
145
|
+
if lib in local_modules:
|
|
146
|
+
report_lines.append(f"[Yerel] {lib}")
|
|
147
|
+
deps.append({"name": lib, "type": "local"})
|
|
148
|
+
|
|
149
|
+
# Built-in
|
|
150
|
+
elif lib in builtins:
|
|
151
|
+
report_lines.append(f"[Built-in] {lib}")
|
|
152
|
+
deps.append({"name": lib, "type": "builtin"})
|
|
153
|
+
|
|
154
|
+
# 3. parti
|
|
155
|
+
else:
|
|
156
|
+
pkg = import_map.get(lib, lib)
|
|
157
|
+
key = pkg.lower()
|
|
158
|
+
|
|
159
|
+
if key in installed:
|
|
160
|
+
ver = installed[key]
|
|
161
|
+
report_lines.append(f"[3. Parti] {lib} -> {pkg}=={ver}")
|
|
162
|
+
deps.append({
|
|
163
|
+
"name": lib,
|
|
164
|
+
"type": "3rd-party",
|
|
165
|
+
"package": pkg,
|
|
166
|
+
"version": ver
|
|
167
|
+
})
|
|
168
|
+
used_packages[pkg] = ver
|
|
169
|
+
else:
|
|
170
|
+
report_lines.append(f"[Bilinmiyor] {lib}")
|
|
171
|
+
deps.append({"name": lib, "type": "unknown"})
|
|
172
|
+
|
|
173
|
+
json_output["files"][rel] = deps
|
|
174
|
+
|
|
175
|
+
json_output["summary"] = used_packages
|
|
176
|
+
|
|
177
|
+
# ÇIKTILAR
|
|
178
|
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M")
|
|
179
|
+
out_dir = Path(f"RAPOR_getlibs_{timestamp}")
|
|
180
|
+
out_dir.mkdir(exist_ok=True)
|
|
181
|
+
|
|
182
|
+
(out_dir / "report_detailed.txt").write_text("\n".join(report_lines), encoding="utf-8")
|
|
183
|
+
(out_dir / "report_ci.json").write_text(json.dumps(json_output, indent=4), encoding="utf-8")
|
|
184
|
+
(out_dir / "requirements.txt").write_text(
|
|
185
|
+
"\n".join(f"{k}=={v}" for k, v in sorted(used_packages.items())),
|
|
186
|
+
encoding="utf-8"
|
|
187
|
+
)
|
|
188
|
+
(out_dir / "constraints.txt").write_text(
|
|
189
|
+
"\n".join(f"{k}=={v}" for k, v in sorted(installed.items())),
|
|
190
|
+
encoding="utf-8"
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
print("\nAnaliz tamamlandı ✔")
|
|
194
|
+
print(f"Rapor dizini: {out_dir}")
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def main():
|
|
198
|
+
parser = argparse.ArgumentParser(description="Python proje dependency analiz aracı")
|
|
199
|
+
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
"--project-dir",
|
|
202
|
+
help="Analiz edilecek proje dizini (varsayılan: script dizini)"
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
parser.add_argument(
|
|
206
|
+
"--python-exec",
|
|
207
|
+
help="Hedef Python executable (varsayılan: mevcut Python)",
|
|
208
|
+
default=sys.executable
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
args = parser.parse_args()
|
|
212
|
+
|
|
213
|
+
project_dir = Path(args.project_dir).resolve() if args.project_dir else Path(__file__).parent.resolve()
|
|
214
|
+
analyze_project(project_dir, args.python_exec)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == "__main__":
|
|
218
|
+
main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: getlibs
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Python projeleri için dependency ve import analiz aracı
|
|
5
|
+
Author-email: Muslu Yüksektepe <musluyuksektepe@gmail.com>, Ali Alın <alialinxz@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# getlibs
|
|
13
|
+
|
|
14
|
+
**getlibs**, bir Python projesindeki tüm `import` ifadelerini analiz ederek:
|
|
15
|
+
|
|
16
|
+
- Yerel modülleri
|
|
17
|
+
- Built-in (standart kütüphane) modülleri
|
|
18
|
+
- 3. parti (pip) paketleri
|
|
19
|
+
- Eksik / bilinmeyen import’ları
|
|
20
|
+
|
|
21
|
+
tespit eden bir **dependency analiz aracıdır**.
|
|
22
|
+
|
|
23
|
+
Özellikle:
|
|
24
|
+
- Mevcut bir projeden `requirements.txt` çıkarmak
|
|
25
|
+
- CI/CD süreçlerinde dependency denetimi yapmak
|
|
26
|
+
- Farklı Python ortamları için uyumluluk kontrolü yapmak
|
|
27
|
+
|
|
28
|
+
amacıyla tasarlanmıştır.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Özellikler
|
|
33
|
+
|
|
34
|
+
- 🔍 AST tabanlı gerçek import analizi (regex değil)
|
|
35
|
+
- 🧠 `top_level.txt` kullanarak **import adı → pip paket adı** eşlemesi
|
|
36
|
+
- 🐍 Hedef Python executable üzerinden analiz (env farkı sorunu yok)
|
|
37
|
+
- 📄 4 farklı çıktı üretir:
|
|
38
|
+
- Detaylı TXT rapor
|
|
39
|
+
- CI uyumlu JSON
|
|
40
|
+
- Sadece kullanılan paketlerden `requirements.txt`
|
|
41
|
+
- Tüm ortamı kapsayan `constraints.txt`
|
|
42
|
+
- 🧩 Yerel / built-in / 3. parti ayrımı net şekilde yapılır
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Kurulum
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install getlibs
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
getlibs/__init__.py,sha256=E5LjPn4R-sN8ohyKgjqG7Ix2hHiockCoP7TzgzlHyGk,204
|
|
2
|
+
getlibs/cli.py,sha256=rz1gCTRSqmnyZCZMDujhuMbPoOEdTJ-wsthZ0FAKrY8,6406
|
|
3
|
+
getlibs-0.1.1.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
getlibs-0.1.1.dist-info/METADATA,sha256=-l4XaeGiOC71CntNSEZHblpktKj6uErhyhd67dRZfxQ,1326
|
|
5
|
+
getlibs-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
getlibs-0.1.1.dist-info/entry_points.txt,sha256=1TacyJY8-00NFXHJ1AmhWNfqCNOApUivg6J1raMtFTk,45
|
|
7
|
+
getlibs-0.1.1.dist-info/top_level.txt,sha256=zhmdQ9pD1sRnh1u3KDmW1nsbNfcj0s2Pj4vzSwbttaw,8
|
|
8
|
+
getlibs-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
getlibs
|