treegetter 2.0.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.
- treegetter-2.0.0/LICENSE +21 -0
- treegetter-2.0.0/MANIFEST.in +3 -0
- treegetter-2.0.0/PKG-INFO +64 -0
- treegetter-2.0.0/README.md +36 -0
- treegetter-2.0.0/pyproject.toml +67 -0
- treegetter-2.0.0/setup.cfg +4 -0
- treegetter-2.0.0/tests/test_api.py +44 -0
- treegetter-2.0.0/tests/test_repository.py +109 -0
- treegetter-2.0.0/treegetter/__init__.py +64 -0
- treegetter-2.0.0/treegetter/__main__.py +9 -0
- treegetter-2.0.0/treegetter/api.py +146 -0
- treegetter-2.0.0/treegetter/architecture.py +93 -0
- treegetter-2.0.0/treegetter/cache.py +61 -0
- treegetter-2.0.0/treegetter/config.py +158 -0
- treegetter-2.0.0/treegetter/context.py +123 -0
- treegetter-2.0.0/treegetter/dependency.py +280 -0
- treegetter-2.0.0/treegetter/detector.py +41 -0
- treegetter-2.0.0/treegetter/entrypoints.py +105 -0
- treegetter-2.0.0/treegetter/exceptions.py +44 -0
- treegetter-2.0.0/treegetter/exporters.py +169 -0
- treegetter-2.0.0/treegetter/filters.py +139 -0
- treegetter-2.0.0/treegetter/formatter.py +151 -0
- treegetter-2.0.0/treegetter/language.py +62 -0
- treegetter-2.0.0/treegetter/models.py +306 -0
- treegetter-2.0.0/treegetter/plugins/__init__.py +55 -0
- treegetter-2.0.0/treegetter/plugins/base.py +58 -0
- treegetter-2.0.0/treegetter/plugins/csharp.py +31 -0
- treegetter-2.0.0/treegetter/plugins/django.py +35 -0
- treegetter-2.0.0/treegetter/plugins/fastapi.py +37 -0
- treegetter-2.0.0/treegetter/plugins/flask.py +37 -0
- treegetter-2.0.0/treegetter/plugins/flutter.py +35 -0
- treegetter-2.0.0/treegetter/plugins/go.py +28 -0
- treegetter-2.0.0/treegetter/plugins/java.py +33 -0
- treegetter-2.0.0/treegetter/plugins/javascript.py +38 -0
- treegetter-2.0.0/treegetter/plugins/nextjs.py +48 -0
- treegetter-2.0.0/treegetter/plugins/php.py +28 -0
- treegetter-2.0.0/treegetter/plugins/python.py +42 -0
- treegetter-2.0.0/treegetter/plugins/react.py +47 -0
- treegetter-2.0.0/treegetter/plugins/rust.py +28 -0
- treegetter-2.0.0/treegetter/repository.py +258 -0
- treegetter-2.0.0/treegetter/scanner.py +238 -0
- treegetter-2.0.0/treegetter/search.py +121 -0
- treegetter-2.0.0/treegetter/statistics.py +125 -0
- treegetter-2.0.0/treegetter/summary.py +73 -0
- treegetter-2.0.0/treegetter/tokenizer.py +43 -0
- treegetter-2.0.0/treegetter/utils.py +136 -0
- treegetter-2.0.0/treegetter.egg-info/PKG-INFO +64 -0
- treegetter-2.0.0/treegetter.egg-info/SOURCES.txt +49 -0
- treegetter-2.0.0/treegetter.egg-info/dependency_links.txt +1 -0
- treegetter-2.0.0/treegetter.egg-info/entry_points.txt +2 -0
- treegetter-2.0.0/treegetter.egg-info/top_level.txt +1 -0
treegetter-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rupam Manna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: treegetter
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: AI-Ready Repository Intelligence Engine for Agents
|
|
5
|
+
Author-email: Rupam Manna <rupammanna8@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/RupamManna8/TreeGetter
|
|
8
|
+
Project-URL: Documentation, https://rupammanna8.github.io/TreeGetter/
|
|
9
|
+
Project-URL: Repository, https://github.com/RupamManna8/TreeGetter.git
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/RupamManna8/TreeGetter/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/RupamManna8/TreeGetter/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: repository,directory-tree,ai-agent,codebase-intelligence,llm-context,token-optimizer,repo-parser,ast-analyzer,dependency-parser,architecture-detector
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# TreeGetter Python Package
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/treegetter/)
|
|
32
|
+
[](https://pypi.org/project/treegetter/)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
|
|
35
|
+
**TreeGetter** is an AI-Ready Repository Intelligence Engine for Python. It transforms raw directory trees into compact, structured, token-optimized context payloads for AI coding agents.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install treegetter
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from treegetter import Repository, get_tree
|
|
47
|
+
|
|
48
|
+
# Backward compatible legacy API
|
|
49
|
+
print(get_tree("./"))
|
|
50
|
+
|
|
51
|
+
# High-Level AI Repository Intelligence Engine
|
|
52
|
+
repo = Repository("./")
|
|
53
|
+
|
|
54
|
+
# Repository Overview Summary
|
|
55
|
+
print(repo.summary())
|
|
56
|
+
|
|
57
|
+
# Token-optimized context for LLM agents
|
|
58
|
+
print(repo.export_llm(max_tokens=4000))
|
|
59
|
+
|
|
60
|
+
# Indexed O(1) Search
|
|
61
|
+
results = repo.search("AuthController")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
For full documentation, visit [https://rupammanna8.github.io/TreeGetter/](https://rupammanna8.github.io/TreeGetter/).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# TreeGetter Python Package
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/treegetter/)
|
|
4
|
+
[](https://pypi.org/project/treegetter/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**TreeGetter** is an AI-Ready Repository Intelligence Engine for Python. It transforms raw directory trees into compact, structured, token-optimized context payloads for AI coding agents.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install treegetter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from treegetter import Repository, get_tree
|
|
19
|
+
|
|
20
|
+
# Backward compatible legacy API
|
|
21
|
+
print(get_tree("./"))
|
|
22
|
+
|
|
23
|
+
# High-Level AI Repository Intelligence Engine
|
|
24
|
+
repo = Repository("./")
|
|
25
|
+
|
|
26
|
+
# Repository Overview Summary
|
|
27
|
+
print(repo.summary())
|
|
28
|
+
|
|
29
|
+
# Token-optimized context for LLM agents
|
|
30
|
+
print(repo.export_llm(max_tokens=4000))
|
|
31
|
+
|
|
32
|
+
# Indexed O(1) Search
|
|
33
|
+
results = repo.search("AuthController")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
For full documentation, visit [https://rupammanna8.github.io/TreeGetter/](https://rupammanna8.github.io/TreeGetter/).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "treegetter"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "AI-Ready Repository Intelligence Engine for Agents"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Rupam Manna", email = "rupammanna8@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = { text = "MIT" }
|
|
14
|
+
keywords = [
|
|
15
|
+
"repository",
|
|
16
|
+
"directory-tree",
|
|
17
|
+
"ai-agent",
|
|
18
|
+
"codebase-intelligence",
|
|
19
|
+
"llm-context",
|
|
20
|
+
"token-optimizer",
|
|
21
|
+
"repo-parser",
|
|
22
|
+
"ast-analyzer",
|
|
23
|
+
"dependency-parser",
|
|
24
|
+
"architecture-detector"
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 5 - Production/Stable",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
36
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
37
|
+
"Topic :: Utilities"
|
|
38
|
+
]
|
|
39
|
+
requires-python = ">=3.10"
|
|
40
|
+
dependencies = []
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/RupamManna8/TreeGetter"
|
|
44
|
+
Documentation = "https://rupammanna8.github.io/TreeGetter/"
|
|
45
|
+
Repository = "https://github.com/RupamManna8/TreeGetter.git"
|
|
46
|
+
"Bug Tracker" = "https://github.com/RupamManna8/TreeGetter/issues"
|
|
47
|
+
Changelog = "https://github.com/RupamManna8/TreeGetter/blob/main/CHANGELOG.md"
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
treegetter = "treegetter.api:main"
|
|
51
|
+
|
|
52
|
+
[tool.setuptools.packages.find]
|
|
53
|
+
where = ["."]
|
|
54
|
+
include = ["treegetter*"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff]
|
|
57
|
+
line-length = 100
|
|
58
|
+
target-version = "py310"
|
|
59
|
+
|
|
60
|
+
[tool.mypy]
|
|
61
|
+
python_version = "3.10"
|
|
62
|
+
warn_return_any = true
|
|
63
|
+
warn_unused_configs = true
|
|
64
|
+
disallow_untyped_defs = true
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Unit tests for backward compatible treegetter public API functions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from treegetter import generate_tree, get_tree
|
|
11
|
+
from treegetter.exceptions import InvalidPathError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestApi(unittest.TestCase):
|
|
15
|
+
def setUp(self) -> None:
|
|
16
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
17
|
+
self.root = Path(self.tmp.name)
|
|
18
|
+
(self.root / "src").mkdir()
|
|
19
|
+
(self.root / "src" / "main.py").write_text("print('hello')")
|
|
20
|
+
(self.root / "README.md").write_text("# Test Repo")
|
|
21
|
+
|
|
22
|
+
def tearDown(self) -> None:
|
|
23
|
+
self.tmp.cleanup()
|
|
24
|
+
|
|
25
|
+
def test_get_tree_basic(self) -> None:
|
|
26
|
+
output = get_tree(self.root)
|
|
27
|
+
self.assertIn("src", output)
|
|
28
|
+
self.assertIn("main.py", output)
|
|
29
|
+
self.assertIn("README.md", output)
|
|
30
|
+
|
|
31
|
+
def test_generate_tree_json_format(self) -> None:
|
|
32
|
+
output = generate_tree(self.root, output_format="json", show_stats=True)
|
|
33
|
+
data = json.loads(output)
|
|
34
|
+
self.assertIn("tree", data)
|
|
35
|
+
self.assertIn("statistics", data)
|
|
36
|
+
self.assertEqual(data["tree"]["name"], self.root.name)
|
|
37
|
+
|
|
38
|
+
def test_invalid_path(self) -> None:
|
|
39
|
+
with self.assertRaises(InvalidPathError):
|
|
40
|
+
get_tree("/non/existent/path/for/test")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
unittest.main()
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Unit tests for Repository intelligence class."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from treegetter import Repository
|
|
10
|
+
from treegetter.models import (
|
|
11
|
+
AIContext,
|
|
12
|
+
ArchitectureInfo,
|
|
13
|
+
DependencyInfo,
|
|
14
|
+
FrameworkInfo,
|
|
15
|
+
RepositorySummary,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TestRepository(unittest.TestCase):
|
|
20
|
+
def setUp(self) -> None:
|
|
21
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
22
|
+
self.root = Path(self.tmp.name)
|
|
23
|
+
|
|
24
|
+
(self.root / "src" / "controllers").mkdir(parents=True)
|
|
25
|
+
(self.root / "src" / "services").mkdir(parents=True)
|
|
26
|
+
(self.root / "tests").mkdir(parents=True)
|
|
27
|
+
|
|
28
|
+
(self.root / "src" / "controllers" / "user_controller.py").write_text("# user controller\n" * 5)
|
|
29
|
+
(self.root / "src" / "services" / "user_service.py").write_text("# user service\n" * 10)
|
|
30
|
+
(self.root / "tests" / "test_user.py").write_text("# unit tests\n" * 3)
|
|
31
|
+
|
|
32
|
+
(self.root / "pyproject.toml").write_text('[tool.poetry.dependencies]\nfastapi = "^0.95.0"\n')
|
|
33
|
+
(self.root / "main.py").write_text("import fastapi\napp = fastapi.FastAPI()\n")
|
|
34
|
+
(self.root / "README.md").write_text("# Project Documentation\n")
|
|
35
|
+
|
|
36
|
+
self.repo = Repository(self.root)
|
|
37
|
+
|
|
38
|
+
def tearDown(self) -> None:
|
|
39
|
+
self.tmp.cleanup()
|
|
40
|
+
|
|
41
|
+
def test_tree(self) -> None:
|
|
42
|
+
tree_out = self.repo.tree()
|
|
43
|
+
self.assertIn("src", tree_out)
|
|
44
|
+
self.assertIn("main.py", tree_out)
|
|
45
|
+
|
|
46
|
+
def test_files_and_directories(self) -> None:
|
|
47
|
+
files = self.repo.files()
|
|
48
|
+
self.assertGreaterEqual(len(files), 4)
|
|
49
|
+
|
|
50
|
+
dirs = self.repo.directories()
|
|
51
|
+
self.assertIn("src", dirs)
|
|
52
|
+
|
|
53
|
+
def test_framework_and_detect(self) -> None:
|
|
54
|
+
fw = self.repo.framework()
|
|
55
|
+
self.assertIsInstance(fw, FrameworkInfo)
|
|
56
|
+
|
|
57
|
+
all_detected = self.repo.detect()
|
|
58
|
+
self.assertGreater(len(all_detected), 0)
|
|
59
|
+
|
|
60
|
+
def test_language(self) -> None:
|
|
61
|
+
langs = self.repo.language()
|
|
62
|
+
self.assertIn("Python", langs)
|
|
63
|
+
|
|
64
|
+
def test_dependencies(self) -> None:
|
|
65
|
+
deps = self.repo.dependencies()
|
|
66
|
+
self.assertIsInstance(deps, DependencyInfo)
|
|
67
|
+
self.assertIn("fastapi", deps.dependencies)
|
|
68
|
+
|
|
69
|
+
def test_architecture(self) -> None:
|
|
70
|
+
arch = self.repo.architecture()
|
|
71
|
+
self.assertIsInstance(arch, ArchitectureInfo)
|
|
72
|
+
|
|
73
|
+
def test_entrypoints(self) -> None:
|
|
74
|
+
eps = self.repo.entrypoints()
|
|
75
|
+
self.assertTrue(any(ep.path == "main.py" for ep in eps))
|
|
76
|
+
|
|
77
|
+
def test_statistics(self) -> None:
|
|
78
|
+
stats = self.repo.statistics()
|
|
79
|
+
self.assertEqual(stats["file_count"], len(self.repo.files()))
|
|
80
|
+
|
|
81
|
+
def test_summary(self) -> None:
|
|
82
|
+
summ = self.repo.summary()
|
|
83
|
+
self.assertIsInstance(summ, RepositorySummary)
|
|
84
|
+
self.assertEqual(summ.name, self.root.name)
|
|
85
|
+
|
|
86
|
+
def test_project_map(self) -> None:
|
|
87
|
+
pmap = self.repo.project_map()
|
|
88
|
+
self.assertIn("Controllers", pmap)
|
|
89
|
+
|
|
90
|
+
def test_search(self) -> None:
|
|
91
|
+
res = self.repo.search("user")
|
|
92
|
+
self.assertGreater(len(res), 0)
|
|
93
|
+
|
|
94
|
+
def test_context(self) -> None:
|
|
95
|
+
ctx = self.repo.context()
|
|
96
|
+
self.assertIsInstance(ctx, AIContext)
|
|
97
|
+
|
|
98
|
+
def test_readme(self) -> None:
|
|
99
|
+
rm = self.repo.readme()
|
|
100
|
+
self.assertIsNotNone(rm)
|
|
101
|
+
|
|
102
|
+
def test_exporters(self) -> None:
|
|
103
|
+
self.assertIn("{", self.repo.export_json())
|
|
104
|
+
self.assertIn("#", self.repo.export_markdown())
|
|
105
|
+
self.assertIn("REPOSITORY", self.repo.export_llm())
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
if __name__ == "__main__":
|
|
109
|
+
unittest.main()
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""TreeGetter – AI-Ready Repository Intelligence Engine."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .api import generate_tree, get_tree, main
|
|
6
|
+
from .cache import CacheManager
|
|
7
|
+
from .exceptions import (
|
|
8
|
+
AnalysisError,
|
|
9
|
+
CacheError,
|
|
10
|
+
CircularSymlinkError,
|
|
11
|
+
DirectoryTreeError,
|
|
12
|
+
InvalidPathError,
|
|
13
|
+
PermissionDeniedError,
|
|
14
|
+
PluginError,
|
|
15
|
+
ScannerError,
|
|
16
|
+
SearchError,
|
|
17
|
+
)
|
|
18
|
+
from .models import (
|
|
19
|
+
AIContext,
|
|
20
|
+
ArchitectureInfo,
|
|
21
|
+
DependencyInfo,
|
|
22
|
+
EntryPoint,
|
|
23
|
+
FileMetadata,
|
|
24
|
+
FrameworkInfo,
|
|
25
|
+
LanguageStat,
|
|
26
|
+
Node,
|
|
27
|
+
RepositorySummary,
|
|
28
|
+
SearchResult,
|
|
29
|
+
TreeConfig,
|
|
30
|
+
TreeStatistics,
|
|
31
|
+
)
|
|
32
|
+
from .plugins import BasePlugin, PluginRegistry
|
|
33
|
+
from .repository import Repository
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"get_tree",
|
|
37
|
+
"generate_tree",
|
|
38
|
+
"main",
|
|
39
|
+
"Repository",
|
|
40
|
+
"Node",
|
|
41
|
+
"TreeConfig",
|
|
42
|
+
"TreeStatistics",
|
|
43
|
+
"FileMetadata",
|
|
44
|
+
"FrameworkInfo",
|
|
45
|
+
"DependencyInfo",
|
|
46
|
+
"EntryPoint",
|
|
47
|
+
"ArchitectureInfo",
|
|
48
|
+
"LanguageStat",
|
|
49
|
+
"RepositorySummary",
|
|
50
|
+
"SearchResult",
|
|
51
|
+
"AIContext",
|
|
52
|
+
"BasePlugin",
|
|
53
|
+
"PluginRegistry",
|
|
54
|
+
"CacheManager",
|
|
55
|
+
"DirectoryTreeError",
|
|
56
|
+
"InvalidPathError",
|
|
57
|
+
"PermissionDeniedError",
|
|
58
|
+
"CircularSymlinkError",
|
|
59
|
+
"PluginError",
|
|
60
|
+
"CacheError",
|
|
61
|
+
"ScannerError",
|
|
62
|
+
"SearchError",
|
|
63
|
+
"AnalysisError",
|
|
64
|
+
]
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Public high-level API functions for treegetter backward compatibility and CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .config import DEFAULT_IGNORE_DIRS, DEFAULT_IGNORE_PATTERNS, SUPPORTED_FORMATS
|
|
11
|
+
from .exceptions import DirectoryTreeError
|
|
12
|
+
from .filters import PathFilter
|
|
13
|
+
from .formatter import FormatterFactory
|
|
14
|
+
from .models import TreeConfig, TreeStatistics
|
|
15
|
+
from .scanner import DirectoryScanner
|
|
16
|
+
from .statistics import StatisticsEngine
|
|
17
|
+
from .utils import validate_path
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def generate_tree(
|
|
21
|
+
path: str | Path,
|
|
22
|
+
*,
|
|
23
|
+
max_depth: int | None = None,
|
|
24
|
+
include_hidden: bool = False,
|
|
25
|
+
follow_symlinks: bool = False,
|
|
26
|
+
show_size: bool = False,
|
|
27
|
+
dirs_first: bool = True,
|
|
28
|
+
output_format: str = "unicode",
|
|
29
|
+
ignore_dirs: frozenset[str] | None = None,
|
|
30
|
+
ignore_patterns: tuple[str, ...] | None = None,
|
|
31
|
+
use_gitignore: bool = False,
|
|
32
|
+
show_stats: bool = False,
|
|
33
|
+
) -> str:
|
|
34
|
+
"""Generate a formatted directory tree string."""
|
|
35
|
+
root = validate_path(path)
|
|
36
|
+
|
|
37
|
+
config = TreeConfig(
|
|
38
|
+
root=root,
|
|
39
|
+
max_depth=max_depth,
|
|
40
|
+
include_hidden=include_hidden,
|
|
41
|
+
follow_symlinks=follow_symlinks,
|
|
42
|
+
show_size=show_size,
|
|
43
|
+
dirs_first=dirs_first,
|
|
44
|
+
output_format=output_format,
|
|
45
|
+
ignore_dirs=frozenset(ignore_dirs) if ignore_dirs is not None else DEFAULT_IGNORE_DIRS,
|
|
46
|
+
ignore_patterns=(
|
|
47
|
+
tuple(ignore_patterns) if ignore_patterns is not None else DEFAULT_IGNORE_PATTERNS
|
|
48
|
+
),
|
|
49
|
+
use_gitignore=use_gitignore,
|
|
50
|
+
show_stats=show_stats,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
path_filter = PathFilter(config)
|
|
54
|
+
scanner = DirectoryScanner(config, path_filter)
|
|
55
|
+
tree = scanner.scan(root)
|
|
56
|
+
|
|
57
|
+
statistics: TreeStatistics | None = None
|
|
58
|
+
if config.show_stats:
|
|
59
|
+
statistics = StatisticsEngine().compute(tree)
|
|
60
|
+
|
|
61
|
+
formatter = FormatterFactory.create(config.output_format, show_size=config.show_size)
|
|
62
|
+
return formatter.format(tree, stats=statistics)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def get_tree(path: str | Path, **kwargs: Any) -> str:
|
|
66
|
+
"""Backward-compatible alias for generate_tree."""
|
|
67
|
+
return generate_tree(path, **kwargs)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _build_arg_parser() -> argparse.ArgumentParser:
|
|
71
|
+
parser = argparse.ArgumentParser(
|
|
72
|
+
prog="treegetter",
|
|
73
|
+
description="Generate a directory tree in unicode, ascii, markdown or json format.",
|
|
74
|
+
)
|
|
75
|
+
parser.add_argument(
|
|
76
|
+
"path", nargs="?", default=".", help="Directory to scan (default: current directory)"
|
|
77
|
+
)
|
|
78
|
+
parser.add_argument("-d", "--max-depth", type=int, default=None, help="Maximum depth to traverse")
|
|
79
|
+
parser.add_argument("-a", "--all", action="store_true", help="Include hidden files and directories")
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"-L", "--follow-symlinks", action="store_true", help="Descend into symlinked directories"
|
|
82
|
+
)
|
|
83
|
+
parser.add_argument("-s", "--size", action="store_true", help="Show file sizes")
|
|
84
|
+
parser.add_argument(
|
|
85
|
+
"--no-dirs-first", action="store_true", help="Do not list directories before files"
|
|
86
|
+
)
|
|
87
|
+
parser.add_argument(
|
|
88
|
+
"-f", "--format", choices=SUPPORTED_FORMATS, default="unicode", help="Output format"
|
|
89
|
+
)
|
|
90
|
+
parser.add_argument(
|
|
91
|
+
"-i", "--ignore", action="append", default=[], metavar="GLOB",
|
|
92
|
+
help="Additional glob pattern to ignore (repeatable)",
|
|
93
|
+
)
|
|
94
|
+
parser.add_argument(
|
|
95
|
+
"--ignore-dir", action="append", default=[], metavar="NAME",
|
|
96
|
+
help="Additional directory name to ignore (repeatable)",
|
|
97
|
+
)
|
|
98
|
+
parser.add_argument(
|
|
99
|
+
"--gitignore", action="store_true", help="Respect a .gitignore file in the root directory"
|
|
100
|
+
)
|
|
101
|
+
parser.add_argument("--stats", action="store_true", help="Show summary statistics")
|
|
102
|
+
parser.add_argument(
|
|
103
|
+
"-o", "--output", type=Path, default=None, help="Write output to a file instead of stdout"
|
|
104
|
+
)
|
|
105
|
+
return parser
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def main(argv: list[str] | None = None) -> int:
|
|
109
|
+
parser = _build_arg_parser()
|
|
110
|
+
args = parser.parse_args(argv)
|
|
111
|
+
|
|
112
|
+
ignore_dirs = DEFAULT_IGNORE_DIRS | frozenset(args.ignore_dir)
|
|
113
|
+
ignore_patterns = DEFAULT_IGNORE_PATTERNS + tuple(args.ignore)
|
|
114
|
+
|
|
115
|
+
try:
|
|
116
|
+
rendered = generate_tree(
|
|
117
|
+
args.path,
|
|
118
|
+
max_depth=args.max_depth,
|
|
119
|
+
include_hidden=args.all,
|
|
120
|
+
follow_symlinks=args.follow_symlinks,
|
|
121
|
+
show_size=args.size,
|
|
122
|
+
dirs_first=not args.no_dirs_first,
|
|
123
|
+
output_format=args.format,
|
|
124
|
+
ignore_dirs=ignore_dirs,
|
|
125
|
+
ignore_patterns=ignore_patterns,
|
|
126
|
+
use_gitignore=args.gitignore,
|
|
127
|
+
show_stats=args.stats,
|
|
128
|
+
)
|
|
129
|
+
except DirectoryTreeError as exc:
|
|
130
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
131
|
+
return 1
|
|
132
|
+
except ValueError as exc:
|
|
133
|
+
print(f"Error: {exc}", file=sys.stderr)
|
|
134
|
+
return 2
|
|
135
|
+
|
|
136
|
+
if args.output is not None:
|
|
137
|
+
args.output.write_text(rendered, encoding="utf-8")
|
|
138
|
+
print(f"Written to {args.output}")
|
|
139
|
+
else:
|
|
140
|
+
print(rendered)
|
|
141
|
+
|
|
142
|
+
return 0
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Architecture pattern analyzer using folder structure heuristics and configuration files."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Sequence
|
|
7
|
+
|
|
8
|
+
from .models import ArchitectureInfo, FileMetadata
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ArchitectureAnalyzer:
|
|
12
|
+
"""Analyzes directory structure and file paths to identify architecture style."""
|
|
13
|
+
|
|
14
|
+
def analyze(self, root: Path, files: Sequence[FileMetadata] | None = None) -> ArchitectureInfo:
|
|
15
|
+
"""Detect architecture pattern and calculate confidence score."""
|
|
16
|
+
dir_names = set()
|
|
17
|
+
for p in root.glob("*"):
|
|
18
|
+
if p.is_dir():
|
|
19
|
+
dir_names.add(p.name.lower())
|
|
20
|
+
|
|
21
|
+
if files:
|
|
22
|
+
for f in files:
|
|
23
|
+
for part in f.path.parts:
|
|
24
|
+
dir_names.add(part.lower())
|
|
25
|
+
|
|
26
|
+
if (root / "packages").is_dir() or (root / "apps").is_dir() or (root / "lerna.json").is_file() or (root / "pnpm-workspace.yaml").is_file():
|
|
27
|
+
return ArchitectureInfo(
|
|
28
|
+
pattern="Monorepo",
|
|
29
|
+
confidence=0.95,
|
|
30
|
+
details={"indicator": "packages/apps workspace structure or configuration"},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
clean_keywords = {"domain", "usecases", "adapters", "entities", "interfaces", "infrastructure"}
|
|
34
|
+
if len(clean_keywords.intersection(dir_names)) >= 3:
|
|
35
|
+
return ArchitectureInfo(
|
|
36
|
+
pattern="Clean Architecture",
|
|
37
|
+
confidence=0.90,
|
|
38
|
+
details={"matching_layers": list(clean_keywords.intersection(dir_names))},
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
hex_keywords = {"ports", "adapters", "domain", "application"}
|
|
42
|
+
if len(hex_keywords.intersection(dir_names)) >= 3:
|
|
43
|
+
return ArchitectureInfo(
|
|
44
|
+
pattern="Hexagonal Architecture",
|
|
45
|
+
confidence=0.90,
|
|
46
|
+
details={"matching_layers": list(hex_keywords.intersection(dir_names))},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
ddd_keywords = {"domain", "aggregates", "bounded_contexts", "value_objects", "repositories"}
|
|
50
|
+
if len(ddd_keywords.intersection(dir_names)) >= 3:
|
|
51
|
+
return ArchitectureInfo(
|
|
52
|
+
pattern="Domain Driven Design",
|
|
53
|
+
confidence=0.85,
|
|
54
|
+
details={"matching_elements": list(ddd_keywords.intersection(dir_names))},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
mvc_keywords = {"models", "views", "controllers"}
|
|
58
|
+
if mvc_keywords.issubset(dir_names) or {"model", "view", "controller"}.issubset(dir_names):
|
|
59
|
+
return ArchitectureInfo(
|
|
60
|
+
pattern="MVC",
|
|
61
|
+
confidence=0.95,
|
|
62
|
+
details={"matching_folders": ["models", "views", "controllers"]},
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
layered_keywords = {"controllers", "services", "repositories", "routes"}
|
|
66
|
+
matches = layered_keywords.intersection(dir_names)
|
|
67
|
+
if len(matches) >= 2:
|
|
68
|
+
return ArchitectureInfo(
|
|
69
|
+
pattern="Layered Architecture",
|
|
70
|
+
confidence=0.85,
|
|
71
|
+
details={"layers": list(matches)},
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
feature_keywords = {"features", "modules", "components"}
|
|
75
|
+
if len(feature_keywords.intersection(dir_names)) >= 1:
|
|
76
|
+
return ArchitectureInfo(
|
|
77
|
+
pattern="Feature-based",
|
|
78
|
+
confidence=0.75,
|
|
79
|
+
details={"matching_folders": list(feature_keywords.intersection(dir_names))},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if len([d for d in dir_names if "service" in d]) >= 2:
|
|
83
|
+
return ArchitectureInfo(
|
|
84
|
+
pattern="Microservices",
|
|
85
|
+
confidence=0.80,
|
|
86
|
+
details={"indicator": "multiple service directories"},
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return ArchitectureInfo(
|
|
90
|
+
pattern="Modular / Standard Layout",
|
|
91
|
+
confidence=0.60,
|
|
92
|
+
details={"indicator": "standard package directory layout"},
|
|
93
|
+
)
|