fix poetry package-mode configuration
Browse files- .gitignore +3 -1
- poetry.lock +15 -66
- pyproject.toml +5 -4
- src/know_lang_bot/__main__.py +8 -0
- parser/parse.py → src/know_lang_bot/code_parser/parser.py +29 -23
- {utils → src/know_lang_bot/utils}/fancy_log.py +0 -0
.gitignore
CHANGED
@@ -1 +1,3 @@
|
|
1 |
-
.venv
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
__pycache__
|
3 |
+
.pytest_cache
|
poetry.lock
CHANGED
@@ -1345,76 +1345,25 @@ docs = ["sphinx (>=8.1,<9.0)", "sphinx-book-theme"]
|
|
1345 |
tests = ["tree-sitter-html (>=0.23.2)", "tree-sitter-javascript (>=0.23.1)", "tree-sitter-json (>=0.24.8)", "tree-sitter-python (>=0.23.6)", "tree-sitter-rust (>=0.23.2)"]
|
1346 |
|
1347 |
[[package]]
|
1348 |
-
name = "tree-sitter-
|
1349 |
-
version = "
|
1350 |
-
description = "
|
1351 |
optional = false
|
1352 |
-
python-versions = "
|
1353 |
groups = ["main"]
|
1354 |
files = [
|
1355 |
-
{file = "
|
1356 |
-
{file = "
|
1357 |
-
{file = "
|
1358 |
-
{file = "
|
1359 |
-
{file = "
|
1360 |
-
{file = "
|
1361 |
-
{file = "
|
1362 |
-
{file = "
|
1363 |
-
{file = "tree_sitter_languages-1.10.2-cp310-cp310-win32.whl", hash = "sha256:c9731cf745f135d9770eeba9bb4e2ff4dabc107b5ae9b8211e919f6b9100ea6d"},
|
1364 |
-
{file = "tree_sitter_languages-1.10.2-cp310-cp310-win_amd64.whl", hash = "sha256:6dd75851c41d0c3c4987a9b7692d90fa8848706c23115669d8224ffd6571e357"},
|
1365 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7eb7d7542b2091c875fe52719209631fca36f8c10fa66970d2c576ae6a1b8289"},
|
1366 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:6b41bcb00974b1c8a1800c7f1bb476a1d15a0463e760ee24872f2d53b08ee424"},
|
1367 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6f370cd7845c6c81df05680d5bd96db8a99d32b56f4728c5d05978911130a853"},
|
1368 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1dc195c88ef4c72607e112a809a69190e096a2e5ebc6201548b3e05fdd169ad"},
|
1369 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ae34ac314a7170be24998a0f994c1ac80761d8d4bd126af27ee53a023d3b849"},
|
1370 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:01b5742d5f5bd675489486b582bd482215880b26dde042c067f8265a6e925d9c"},
|
1371 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:ab1cbc46244d34fd16f21edaa20231b2a57f09f092a06ee3d469f3117e6eb954"},
|
1372 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:0b1149e7467a4e92b8a70e6005fe762f880f493cf811fc003554b29f04f5e7c8"},
|
1373 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-win32.whl", hash = "sha256:049276343962f4696390ee555acc2c1a65873270c66a6cbe5cb0bca83bcdf3c6"},
|
1374 |
-
{file = "tree_sitter_languages-1.10.2-cp311-cp311-win_amd64.whl", hash = "sha256:7f3fdd468a577f04db3b63454d939e26e360229b53c80361920aa1ebf2cd7491"},
|
1375 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:c0f4c8b2734c45859edc7fcaaeaab97a074114111b5ba51ab4ec7ed52104763c"},
|
1376 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:eecd3c1244ac3425b7a82ba9125b4ddb45d953bbe61de114c0334fd89b7fe782"},
|
1377 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:15db3c8510bc39a80147ee7421bf4782c15c09581c1dc2237ea89cefbd95b846"},
|
1378 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:92c6487a6feea683154d3e06e6db68c30e0ae749a7ce4ce90b9e4e46b78c85c7"},
|
1379 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6d2f1cd1d1bdd65332f9c2b67d49dcf148cf1ded752851d159ac3e5ee4f4d260"},
|
1380 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:976c8039165b8e12f17a01ddee9f4e23ec6e352b165ad29b44d2bf04e2fbe77e"},
|
1381 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:dafbbdf16bf668a580902e1620f4baa1913e79438abcce721a50647564c687b9"},
|
1382 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:1aeabd3d60d6d276b73cd8f3739d595b1299d123cc079a317f1a5b3c5461e2ca"},
|
1383 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-win32.whl", hash = "sha256:fab8ee641914098e8933b87ea3d657bea4dd00723c1ee7038b847b12eeeef4f5"},
|
1384 |
-
{file = "tree_sitter_languages-1.10.2-cp312-cp312-win_amd64.whl", hash = "sha256:5e606430d736367e5787fa5a7a0c5a1ec9b85eded0b3596bbc0d83532a40810b"},
|
1385 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:838d5b48a7ed7a17658721952c77fda4570d2a069f933502653b17e15a9c39c9"},
|
1386 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:987b3c71b1d278c2889e018ee77b8ee05c384e2e3334dec798f8b611c4ab2d1e"},
|
1387 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:faa00abcb2c819027df58472da055d22fa7dfcb77c77413d8500c32ebe24d38b"},
|
1388 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0e102fbbf02322d9201a86a814e79a9734ac80679fdb9682144479044f401a73"},
|
1389 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:8f0b87cf1a7b03174ba18dfd81582be82bfed26803aebfe222bd20e444aba003"},
|
1390 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c0f1b9af9cb67f0b942b020da9fdd000aad5e92f2383ae0ba7a330b318d31912"},
|
1391 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:5a4076c921f7a4d31e643843de7dfe040b65b63a238a5aa8d31d93aabe6572aa"},
|
1392 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-win32.whl", hash = "sha256:fa6391a3a5d83d32db80815161237b67d70576f090ce5f38339206e917a6f8bd"},
|
1393 |
-
{file = "tree_sitter_languages-1.10.2-cp37-cp37m-win_amd64.whl", hash = "sha256:55649d3f254585a064121513627cf9788c1cfdadbc5f097f33d5ba750685a4c0"},
|
1394 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6f85d1edaa2d22d80d4ea5b6d12b95cf3644017b6c227d0d42854439e02e8893"},
|
1395 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:d78feed4a764ef3141cb54bf00fe94d514d8b6e26e09423e23b4c616fcb7938c"},
|
1396 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da1aca27531f9dd5308637d76643372856f0f65d0d28677d1bcf4211e8ed1ad0"},
|
1397 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1031ea440dafb72237437d754eff8940153a3b051e3d18932ac25e75ce060a15"},
|
1398 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:99d3249beaef2c9fe558ecc9a97853c260433a849dcc68266d9770d196c2e102"},
|
1399 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:59a4450f262a55148fb7e68681522f0c2a2f6b7d89666312a2b32708d8f416e1"},
|
1400 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:ce74eab0e430370d5e15a96b6c6205f93405c177a8b2e71e1526643b2fb9bab1"},
|
1401 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:9b4dd2b6b3d24c85dffe33d6c343448869eaf4f41c19ddba662eb5d65d8808f4"},
|
1402 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-win32.whl", hash = "sha256:92d734fb968fe3927a7596d9f0459f81a8fa7b07e16569476b28e27d0d753348"},
|
1403 |
-
{file = "tree_sitter_languages-1.10.2-cp38-cp38-win_amd64.whl", hash = "sha256:46a13f7d38f2eeb75f7cf127d1201346093748c270d686131f0cbc50e42870a1"},
|
1404 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f8c6a936ae99fdd8857e91f86c11c2f5e507ff30631d141d98132bb7ab2c8638"},
|
1405 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c283a61423f49cdfa7b5a5dfbb39221e3bd126fca33479cd80749d4d7a6b7349"},
|
1406 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:76e60be6bdcff923386a54a5edcb6ff33fc38ab0118636a762024fa2bc98de55"},
|
1407 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c00069f9575bd831eabcce2cdfab158dde1ed151e7e5614c2d985ff7d78a7de1"},
|
1408 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:475ff53203d8a43ccb19bb322fa2fb200d764001cc037793f1fadd714bb343da"},
|
1409 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:26fe7c9c412e4141dea87ea4b3592fd12e385465b5bdab106b0d5125754d4f60"},
|
1410 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:8fed27319957458340f24fe14daad467cd45021da034eef583519f83113a8c5e"},
|
1411 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:3657a491a7f96cc75a3568ddd062d25f3be82b6a942c68801a7b226ff7130181"},
|
1412 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-win32.whl", hash = "sha256:33f7d584d01a7a3c893072f34cfc64ec031f3cfe57eebc32da2f8ac046e101a7"},
|
1413 |
-
{file = "tree_sitter_languages-1.10.2-cp39-cp39-win_amd64.whl", hash = "sha256:1b944af3ee729fa70fc8ae82224a9ff597cdb63addea084e0ea2fa2b0ec39bb7"},
|
1414 |
]
|
1415 |
|
1416 |
-
[package.
|
1417 |
-
tree-sitter
|
1418 |
|
1419 |
[[package]]
|
1420 |
name = "types-requests"
|
@@ -1480,4 +1429,4 @@ zstd = ["zstandard (>=0.18.0)"]
|
|
1480 |
[metadata]
|
1481 |
lock-version = "2.1"
|
1482 |
python-versions = ">=3.10, <4.0"
|
1483 |
-
content-hash = "
|
|
|
1345 |
tests = ["tree-sitter-html (>=0.23.2)", "tree-sitter-javascript (>=0.23.1)", "tree-sitter-json (>=0.24.8)", "tree-sitter-python (>=0.23.6)", "tree-sitter-rust (>=0.23.2)"]
|
1346 |
|
1347 |
[[package]]
|
1348 |
+
name = "tree-sitter-python"
|
1349 |
+
version = "0.23.6"
|
1350 |
+
description = "Python grammar for tree-sitter"
|
1351 |
optional = false
|
1352 |
+
python-versions = ">=3.9"
|
1353 |
groups = ["main"]
|
1354 |
files = [
|
1355 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-macosx_10_9_x86_64.whl", hash = "sha256:28fbec8f74eeb2b30292d97715e60fac9ccf8a8091ce19b9d93e9b580ed280fb"},
|
1356 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:680b710051b144fedf61c95197db0094f2245e82551bf7f0c501356333571f7a"},
|
1357 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8a9dcef55507b6567207e8ee0a6b053d0688019b47ff7f26edc1764b7f4dc0a4"},
|
1358 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:29dacdc0cd2f64e55e61d96c6906533ebb2791972bec988450c46cce60092f5d"},
|
1359 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:7e048733c36f564b379831689006801feb267d8194f9e793fbb395ef1723335d"},
|
1360 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-win_amd64.whl", hash = "sha256:a24027248399fb41594b696f929f9956828ae7cc85596d9f775e6c239cd0c2be"},
|
1361 |
+
{file = "tree_sitter_python-0.23.6-cp39-abi3-win_arm64.whl", hash = "sha256:71334371bd73d5fe080aed39fbff49ed8efb9506edebe16795b0c7567ed6a272"},
|
1362 |
+
{file = "tree_sitter_python-0.23.6.tar.gz", hash = "sha256:354bfa0a2f9217431764a631516f85173e9711af2c13dbd796a8815acfe505d9"},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1363 |
]
|
1364 |
|
1365 |
+
[package.extras]
|
1366 |
+
core = ["tree-sitter (>=0.22,<1.0)"]
|
1367 |
|
1368 |
[[package]]
|
1369 |
name = "types-requests"
|
|
|
1429 |
[metadata]
|
1430 |
lock-version = "2.1"
|
1431 |
python-versions = ">=3.10, <4.0"
|
1432 |
+
content-hash = "3ddd3107cd44dfd9c8060b3aa58c21e738a687ef62aea13cfd9e1ef6dae22557"
|
pyproject.toml
CHANGED
@@ -3,7 +3,7 @@ addopts = [
|
|
3 |
"--import-mode=importlib",
|
4 |
]
|
5 |
[project]
|
6 |
-
name = "
|
7 |
version = "0.1.0"
|
8 |
description = ""
|
9 |
authors = [
|
@@ -13,13 +13,14 @@ readme = "README.md"
|
|
13 |
requires-python = ">=3.10, <4.0"
|
14 |
dependencies = [
|
15 |
"pydantic-ai (>=0.0.20,<0.0.21)",
|
16 |
-
"
|
17 |
-
"
|
|
|
18 |
]
|
19 |
|
20 |
[tool.poetry]
|
21 |
packages = [
|
22 |
-
{ include = "src" },
|
23 |
]
|
24 |
|
25 |
|
|
|
3 |
"--import-mode=importlib",
|
4 |
]
|
5 |
[project]
|
6 |
+
name = "know_lang_bot"
|
7 |
version = "0.1.0"
|
8 |
description = ""
|
9 |
authors = [
|
|
|
13 |
requires-python = ">=3.10, <4.0"
|
14 |
dependencies = [
|
15 |
"pydantic-ai (>=0.0.20,<0.0.21)",
|
16 |
+
"gitpython (>=3.1.44,<4.0.0)",
|
17 |
+
"tree-sitter (>=0.24.0,<0.25.0)",
|
18 |
+
"tree-sitter-python (>=0.23.6,<0.24.0)"
|
19 |
]
|
20 |
|
21 |
[tool.poetry]
|
22 |
packages = [
|
23 |
+
{ include = "know_lang_bot", from="src" },
|
24 |
]
|
25 |
|
26 |
|
src/know_lang_bot/__main__.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from know_lang_bot.code_parser.parser import CodeParser
|
2 |
+
|
3 |
+
# Usage example:
|
4 |
+
if __name__ == "__main__":
|
5 |
+
parser = CodeParser(".")
|
6 |
+
chunks = parser.parse_repository()
|
7 |
+
for chunk in chunks:
|
8 |
+
print(f"{chunk.type}: {chunk.name} ({chunk.start_line}-{chunk.end_line})")
|
parser/parse.py → src/know_lang_bot/code_parser/parser.py
RENAMED
@@ -1,11 +1,12 @@
|
|
|
|
1 |
from typing import List, Optional, Dict
|
2 |
from enum import Enum
|
3 |
from pathlib import Path
|
4 |
-
import
|
5 |
-
|
6 |
-
from pydantic import BaseModel
|
7 |
from git import Repo
|
8 |
-
from utils.fancy_log import FancyLogger
|
9 |
|
10 |
LOG = FancyLogger(__name__)
|
11 |
|
@@ -28,8 +29,8 @@ class CodeChunk(BaseModel):
|
|
28 |
docstring: Optional[str] = None
|
29 |
|
30 |
class CodeParser:
|
31 |
-
parser :
|
32 |
-
laguage:
|
33 |
|
34 |
def __init__(self, repo_path: str):
|
35 |
"""Initialize the parser with a repository path"""
|
@@ -40,10 +41,10 @@ class CodeParser:
|
|
40 |
"""Initialize tree-sitter with Python language support"""
|
41 |
# In real implementation, we'd need to handle language loading more robustly
|
42 |
# For MVP, we'll assume Python parser is available
|
43 |
-
self.
|
44 |
-
self.
|
45 |
|
46 |
-
def _extract_docstring(self, node:
|
47 |
"""Extract docstring from a class or function node"""
|
48 |
for child in node.children:
|
49 |
if child.type == "expression_statement":
|
@@ -87,7 +88,7 @@ class CodeParser:
|
|
87 |
LOG.error(f"Error parsing file {file_path}: {str(e)}")
|
88 |
return []
|
89 |
|
90 |
-
def _process_class(self, node:
|
91 |
"""Process a class node and return a CodeChunk"""
|
92 |
name = next(child.text.decode('utf-8')
|
93 |
for child in node.children
|
@@ -103,7 +104,7 @@ class CodeParser:
|
|
103 |
docstring=self._extract_docstring(node, source_code)
|
104 |
)
|
105 |
|
106 |
-
def _process_function(self, node:
|
107 |
"""Process a function node and return a CodeChunk"""
|
108 |
name = next(child.text.decode('utf-8')
|
109 |
for child in node.children
|
@@ -122,23 +123,28 @@ class CodeParser:
|
|
122 |
def parse_repository(self) -> List[CodeChunk]:
|
123 |
"""Parse all Python files in the repository"""
|
124 |
chunks: List[CodeChunk] = []
|
125 |
-
|
126 |
try:
|
127 |
repo = Repo(self.repo_path)
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
if file.endswith('.py'):
|
131 |
-
file_path = Path(root) / file
|
132 |
chunks.extend(self.parse_file(file_path))
|
133 |
except Exception as e:
|
134 |
LOG.error(f"Error processing repository: {str(e)}")
|
135 |
|
136 |
return chunks
|
137 |
-
|
138 |
-
|
139 |
-
# Usage example:
|
140 |
-
if __name__ == "__main__":
|
141 |
-
parser = CodeParser("path/to/repo")
|
142 |
-
chunks = parser.parse_repository()
|
143 |
-
for chunk in chunks:
|
144 |
-
print(f"{chunk.type}: {chunk.name} ({chunk.start_line}-{chunk.end_line})")
|
|
|
1 |
+
import os
|
2 |
from typing import List, Optional, Dict
|
3 |
from enum import Enum
|
4 |
from pathlib import Path
|
5 |
+
from tree_sitter import Language, Parser, Node
|
6 |
+
import tree_sitter_python
|
7 |
+
from pydantic import BaseModel
|
8 |
from git import Repo
|
9 |
+
from know_lang_bot.utils.fancy_log import FancyLogger
|
10 |
|
11 |
LOG = FancyLogger(__name__)
|
12 |
|
|
|
29 |
docstring: Optional[str] = None
|
30 |
|
31 |
class CodeParser:
|
32 |
+
parser : Parser = None
|
33 |
+
laguage: Language = None
|
34 |
|
35 |
def __init__(self, repo_path: str):
|
36 |
"""Initialize the parser with a repository path"""
|
|
|
41 |
"""Initialize tree-sitter with Python language support"""
|
42 |
# In real implementation, we'd need to handle language loading more robustly
|
43 |
# For MVP, we'll assume Python parser is available
|
44 |
+
self.language = Language(tree_sitter_python.language())
|
45 |
+
self.parser = Parser(self.language)
|
46 |
|
47 |
+
def _extract_docstring(self, node: Node, source_code: bytes) -> Optional[str]:
|
48 |
"""Extract docstring from a class or function node"""
|
49 |
for child in node.children:
|
50 |
if child.type == "expression_statement":
|
|
|
88 |
LOG.error(f"Error parsing file {file_path}: {str(e)}")
|
89 |
return []
|
90 |
|
91 |
+
def _process_class(self, node: Node, source_code: bytes, file_path: Path) -> CodeChunk:
|
92 |
"""Process a class node and return a CodeChunk"""
|
93 |
name = next(child.text.decode('utf-8')
|
94 |
for child in node.children
|
|
|
104 |
docstring=self._extract_docstring(node, source_code)
|
105 |
)
|
106 |
|
107 |
+
def _process_function(self, node: Node, source_code: bytes, file_path: Path) -> CodeChunk:
|
108 |
"""Process a function node and return a CodeChunk"""
|
109 |
name = next(child.text.decode('utf-8')
|
110 |
for child in node.children
|
|
|
123 |
def parse_repository(self) -> List[CodeChunk]:
|
124 |
"""Parse all Python files in the repository"""
|
125 |
chunks: List[CodeChunk] = []
|
126 |
+
|
127 |
try:
|
128 |
repo = Repo(self.repo_path)
|
129 |
+
|
130 |
+
if repo.bare:
|
131 |
+
raise ValueError(f"Repository {self.repo_path} is bare and has no working directory")
|
132 |
+
|
133 |
+
for dirpath, _, filenames in os.walk(repo.working_tree_dir):
|
134 |
+
if repo.ignored(dirpath):
|
135 |
+
LOG.debug(f"Skipping ignored directory: {dirpath}")
|
136 |
+
continue
|
137 |
+
|
138 |
+
for file in filenames:
|
139 |
+
file_path = Path(dirpath) / file
|
140 |
+
|
141 |
+
if repo.ignored(file_path):
|
142 |
+
LOG.debug(f"Skipping ignored file: {file_path}")
|
143 |
+
continue
|
144 |
+
|
145 |
if file.endswith('.py'):
|
|
|
146 |
chunks.extend(self.parse_file(file_path))
|
147 |
except Exception as e:
|
148 |
LOG.error(f"Error processing repository: {str(e)}")
|
149 |
|
150 |
return chunks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{utils → src/know_lang_bot/utils}/fancy_log.py
RENAMED
File without changes
|