deproc-python 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.
- deproc_python-0.1.0/PKG-INFO +22 -0
- deproc_python-0.1.0/deproc/plugins/python/__init__.py +11 -0
- deproc_python-0.1.0/deproc/plugins/python/linker/__init__.py +3 -0
- deproc_python-0.1.0/deproc/plugins/python/linker/main.py +93 -0
- deproc_python-0.1.0/deproc/plugins/python/linker/models.py +21 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/__init__.py +3 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/main.py +552 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/models.py +70 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/utils/extraction.py +189 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/utils/misc.py +8 -0
- deproc_python-0.1.0/deproc/plugins/python/parser/utils/tree_sitter_python.py +29 -0
- deproc_python-0.1.0/deproc/plugins/python/resolver/__init__.py +3 -0
- deproc_python-0.1.0/deproc/plugins/python/resolver/main.py +235 -0
- deproc_python-0.1.0/deproc/plugins/python/resolver/models.py +10 -0
- deproc_python-0.1.0/deproc/plugins/python/symbol_cache/__init__.py +3 -0
- deproc_python-0.1.0/deproc/plugins/python/symbol_cache/main.py +64 -0
- deproc_python-0.1.0/deproc/plugins/python/symbol_cache/models.py +10 -0
- deproc_python-0.1.0/deproc_python.egg-info/PKG-INFO +22 -0
- deproc_python-0.1.0/deproc_python.egg-info/SOURCES.txt +26 -0
- deproc_python-0.1.0/deproc_python.egg-info/dependency_links.txt +1 -0
- deproc_python-0.1.0/deproc_python.egg-info/requires.txt +3 -0
- deproc_python-0.1.0/deproc_python.egg-info/top_level.txt +1 -0
- deproc_python-0.1.0/pyproject.toml +41 -0
- deproc_python-0.1.0/setup.cfg +4 -0
- deproc_python-0.1.0/tests/test_linker.py +185 -0
- deproc_python-0.1.0/tests/test_parser.py +341 -0
- deproc_python-0.1.0/tests/test_resolver.py +482 -0
- deproc_python-0.1.0/tests/test_symbol_cache.py +83 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deproc-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python language plugin for deproc.
|
|
5
|
+
Author-email: Gurveer Singh Virk <gurveervirk.15517@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/gurveervirk/deproc
|
|
8
|
+
Project-URL: Repository, https://github.com/gurveervirk/deproc
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: deproc-core==0.1.0
|
|
21
|
+
Requires-Dist: tree-sitter==0.25.2
|
|
22
|
+
Requires-Dist: tree-sitter-python==0.25.0
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .linker import PythonLinker
|
|
2
|
+
from .parser import PythonSourceParser
|
|
3
|
+
from .resolver import PythonResolver
|
|
4
|
+
from .symbol_cache import PythonSymbolCache
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"PythonLinker",
|
|
8
|
+
"PythonResolver",
|
|
9
|
+
"PythonSourceParser",
|
|
10
|
+
"PythonSymbolCache",
|
|
11
|
+
]
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import fnmatch
|
|
2
|
+
from deproc.core.interfaces import Linker
|
|
3
|
+
from deproc.core.context import Context
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from ..parser.models import PythonModule
|
|
6
|
+
from .models import (
|
|
7
|
+
Node,
|
|
8
|
+
PythonNamespacePackage,
|
|
9
|
+
PythonPackage,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
class PythonLinker(Linker[list[PythonModule], list[Node]]):
|
|
13
|
+
def _check_skip_patterns(self, path: str, skip_patterns: list[str]) -> bool:
|
|
14
|
+
return any(fnmatch.fnmatch(path, pattern) for pattern in skip_patterns)
|
|
15
|
+
|
|
16
|
+
def link_files(self, nodes: list[PythonModule], context: Context) -> list[Node]:
|
|
17
|
+
base_path = Path(context.base_path)
|
|
18
|
+
|
|
19
|
+
path_to_module: dict[str, PythonModule] = {}
|
|
20
|
+
has_init: dict[str, PythonModule] = {}
|
|
21
|
+
|
|
22
|
+
for node in nodes:
|
|
23
|
+
relative_path = node.path
|
|
24
|
+
dir_path = str(Path(relative_path).parent)
|
|
25
|
+
|
|
26
|
+
if node.path.endswith("__init__.py"):
|
|
27
|
+
has_init[dir_path] = node
|
|
28
|
+
continue
|
|
29
|
+
|
|
30
|
+
path_to_module[relative_path] = node
|
|
31
|
+
|
|
32
|
+
skip_patterns = context.skip_paths
|
|
33
|
+
top_level: list[Node] = []
|
|
34
|
+
for sub_path in base_path.iterdir():
|
|
35
|
+
if sub_path.name == "__pycache__":
|
|
36
|
+
continue
|
|
37
|
+
if self._check_skip_patterns(sub_path.name, skip_patterns):
|
|
38
|
+
continue
|
|
39
|
+
if not self.validate_path(str(sub_path)):
|
|
40
|
+
continue
|
|
41
|
+
sub_node = self.traverse_path(base_path, sub_path, path_to_module, has_init, context)
|
|
42
|
+
if sub_node:
|
|
43
|
+
sub_node.parent_id = None
|
|
44
|
+
top_level.append(sub_node)
|
|
45
|
+
|
|
46
|
+
return top_level
|
|
47
|
+
|
|
48
|
+
def validate_path(self, path: str) -> bool:
|
|
49
|
+
return path.endswith(".py") or path.endswith(".pyi") or path.endswith("__init__.py") or Path(path).is_dir()
|
|
50
|
+
|
|
51
|
+
def traverse_path(
|
|
52
|
+
self,
|
|
53
|
+
base_path: Path,
|
|
54
|
+
current_path: Path,
|
|
55
|
+
path_to_module: dict[str, PythonModule],
|
|
56
|
+
has_init: dict[str, PythonModule],
|
|
57
|
+
context: Context
|
|
58
|
+
) -> Node | None:
|
|
59
|
+
if not self.validate_path(str(current_path)):
|
|
60
|
+
return None
|
|
61
|
+
|
|
62
|
+
relative_path = str(current_path.relative_to(base_path)).replace("\\", "/")
|
|
63
|
+
|
|
64
|
+
if relative_path.endswith(".py") or relative_path.endswith(".pyi"):
|
|
65
|
+
return path_to_module.get(relative_path)
|
|
66
|
+
|
|
67
|
+
package = None
|
|
68
|
+
fqn = relative_path.replace("/", ".")
|
|
69
|
+
|
|
70
|
+
if relative_path in has_init:
|
|
71
|
+
package = PythonPackage(
|
|
72
|
+
submodule_ids=[],
|
|
73
|
+
**vars(has_init[relative_path])
|
|
74
|
+
)
|
|
75
|
+
else:
|
|
76
|
+
package = PythonNamespacePackage(
|
|
77
|
+
path=relative_path,
|
|
78
|
+
fqn=fqn,
|
|
79
|
+
submodule_ids=[],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
for sub_path in current_path.iterdir():
|
|
83
|
+
if sub_path.name == "__pycache__":
|
|
84
|
+
continue
|
|
85
|
+
if self._check_skip_patterns(sub_path.name, context.skip_paths):
|
|
86
|
+
continue
|
|
87
|
+
sub_node = self.traverse_path(base_path, sub_path, path_to_module, has_init, context)
|
|
88
|
+
if sub_node:
|
|
89
|
+
sub_node.parent_id = package.id
|
|
90
|
+
package.submodule_ids.append(sub_node.id)
|
|
91
|
+
|
|
92
|
+
context.entity_registry.add(package)
|
|
93
|
+
return package
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from deproc.core.interfaces.parser.models import Node
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from ..parser.models import (
|
|
4
|
+
PythonModule,
|
|
5
|
+
SymbolID,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
@dataclass
|
|
9
|
+
class PythonNamespacePackage(Node):
|
|
10
|
+
fqn: str
|
|
11
|
+
submodule_ids: list[SymbolID] = field(default_factory=list)
|
|
12
|
+
|
|
13
|
+
@dataclass(kw_only=True)
|
|
14
|
+
class PythonPackage(PythonModule):
|
|
15
|
+
submodule_ids: list[SymbolID] = field(default_factory=list)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Node",
|
|
19
|
+
"PythonNamespacePackage",
|
|
20
|
+
"PythonPackage",
|
|
21
|
+
]
|