deproc-python 0.2.1__py3-none-any.whl → 0.3.0__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.
- deproc/plugins/python/linker/main.py +12 -5
- deproc/plugins/python/linker/models.py +22 -2
- deproc/plugins/python/parser/main.py +1 -0
- deproc/plugins/python/utils/packages.py +115 -0
- deproc/plugins/python/utils/serialization.py +5 -0
- {deproc_python-0.2.1.dist-info → deproc_python-0.3.0.dist-info}/METADATA +2 -2
- {deproc_python-0.2.1.dist-info → deproc_python-0.3.0.dist-info}/RECORD +9 -8
- {deproc_python-0.2.1.dist-info → deproc_python-0.3.0.dist-info}/WHEEL +1 -1
- {deproc_python-0.2.1.dist-info → deproc_python-0.3.0.dist-info}/top_level.txt +0 -0
|
@@ -3,16 +3,19 @@ from pathlib import Path
|
|
|
3
3
|
|
|
4
4
|
from deproc.core.context import Context
|
|
5
5
|
from deproc.core.interfaces import Linker
|
|
6
|
+
from deproc.core.interfaces.parser.models import SemanticContainer
|
|
6
7
|
|
|
7
8
|
from ..parser.models import PythonModule
|
|
8
9
|
from .models import Node, PythonNamespacePackage, PythonPackage
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
class PythonLinker(Linker[PythonModule, Node]):
|
|
12
|
+
class PythonLinker(Linker[PythonModule, Node | SemanticContainer]):
|
|
12
13
|
def _check_skip_patterns(self, path: str, skip_patterns: set[str]) -> bool:
|
|
13
14
|
return any(fnmatch.fnmatch(path, pattern) for pattern in skip_patterns)
|
|
14
15
|
|
|
15
|
-
def link_files(
|
|
16
|
+
def link_files(
|
|
17
|
+
self, nodes: list[PythonModule], context: Context
|
|
18
|
+
) -> list[Node | SemanticContainer]:
|
|
16
19
|
base_path = Path(context.base_path)
|
|
17
20
|
|
|
18
21
|
path_to_module: dict[str, PythonModule] = {}
|
|
@@ -29,7 +32,7 @@ class PythonLinker(Linker[PythonModule, Node]):
|
|
|
29
32
|
path_to_module[relative_path] = node
|
|
30
33
|
|
|
31
34
|
skip_patterns = context.skip_paths
|
|
32
|
-
top_level: list[Node] = []
|
|
35
|
+
top_level: list[Node | SemanticContainer] = []
|
|
33
36
|
for sub_path in base_path.iterdir():
|
|
34
37
|
if sub_path.name == "__pycache__":
|
|
35
38
|
continue
|
|
@@ -61,7 +64,7 @@ class PythonLinker(Linker[PythonModule, Node]):
|
|
|
61
64
|
path_to_module: dict[str, PythonModule],
|
|
62
65
|
has_init: dict[str, PythonModule],
|
|
63
66
|
context: Context,
|
|
64
|
-
) -> Node | None:
|
|
67
|
+
) -> Node | SemanticContainer | None:
|
|
65
68
|
if not self.validate_path(str(current_path)):
|
|
66
69
|
return None
|
|
67
70
|
|
|
@@ -94,5 +97,9 @@ class PythonLinker(Linker[PythonModule, Node]):
|
|
|
94
97
|
sub_node.parent_id = package.id
|
|
95
98
|
package.submodule_ids.append(sub_node.id)
|
|
96
99
|
|
|
97
|
-
|
|
100
|
+
if isinstance(package, SemanticContainer):
|
|
101
|
+
package.submodule_ids = sorted(set(package.submodule_ids))
|
|
102
|
+
package = context.entity_registry.merge_semantic_container(package)
|
|
103
|
+
else:
|
|
104
|
+
context.entity_registry.add(package)
|
|
98
105
|
return package
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
|
|
3
|
-
from deproc.core.interfaces.parser.models import Node
|
|
3
|
+
from deproc.core.interfaces.parser.models import Node, SemanticContainer
|
|
4
4
|
|
|
5
5
|
from ..parser.models import (
|
|
6
6
|
PythonModule,
|
|
@@ -9,10 +9,30 @@ from ..parser.models import (
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
@dataclass
|
|
12
|
-
class PythonNamespacePackage(
|
|
12
|
+
class PythonNamespacePackage(SemanticContainer):
|
|
13
|
+
path: str
|
|
13
14
|
fqn: str
|
|
14
15
|
submodule_ids: list[SymbolID] = field(default_factory=list)
|
|
15
16
|
|
|
17
|
+
@property
|
|
18
|
+
def semantic_type(self) -> str:
|
|
19
|
+
return "python.namespace-package"
|
|
20
|
+
|
|
21
|
+
def __post_init__(self) -> None:
|
|
22
|
+
super().__post_init__()
|
|
23
|
+
self.submodule_ids = sorted(set(self.submodule_ids))
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def contribution_ids(self) -> list[SymbolID]:
|
|
27
|
+
return self.submodule_ids
|
|
28
|
+
|
|
29
|
+
def _merge_contributions(self, other: SemanticContainer) -> None:
|
|
30
|
+
if not isinstance(other, PythonNamespacePackage):
|
|
31
|
+
raise ValueError(
|
|
32
|
+
"Namespace packages can only merge with namespace packages"
|
|
33
|
+
)
|
|
34
|
+
self.submodule_ids = sorted(set(self.submodule_ids) | set(other.submodule_ids))
|
|
35
|
+
|
|
16
36
|
|
|
17
37
|
@dataclass(kw_only=True)
|
|
18
38
|
class PythonPackage(PythonModule):
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from deproc.core.interfaces.parser.models import SymbolID
|
|
8
|
+
from deproc.core.runtime import EntityRegistry
|
|
9
|
+
|
|
10
|
+
from ..linker.models import PythonNamespacePackage, PythonPackage
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class ShadowedNamespacePortion:
|
|
17
|
+
fqn: str
|
|
18
|
+
path: str
|
|
19
|
+
registry_index: int
|
|
20
|
+
detached_ids: tuple[SymbolID, ...]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _shadows(regular_fqns: set[str], fqn: str) -> bool:
|
|
24
|
+
return any(
|
|
25
|
+
fqn == regular or fqn.startswith(f"{regular}.") for regular in regular_fqns
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def apply_regular_package_precedence(
|
|
30
|
+
registries: Sequence[EntityRegistry],
|
|
31
|
+
) -> list[ShadowedNamespacePortion]:
|
|
32
|
+
"""Apply Python's rule that a regular package wins over a namespace portion.
|
|
33
|
+
|
|
34
|
+
``registries`` are the per-root link results, before they are merged. A
|
|
35
|
+
namespace portion in one registry is shadowed when a different registry
|
|
36
|
+
holds a regular package (one with ``__init__.py``) of the same name, or of
|
|
37
|
+
an ancestor name. Python then never imports that portion, so its container
|
|
38
|
+
is removed and the modules it held stay in the registry without a parent.
|
|
39
|
+
"""
|
|
40
|
+
regular_by_registry = [
|
|
41
|
+
{
|
|
42
|
+
entity.fqn
|
|
43
|
+
for entity in registry.values()
|
|
44
|
+
if isinstance(entity, PythonPackage)
|
|
45
|
+
}
|
|
46
|
+
for registry in registries
|
|
47
|
+
]
|
|
48
|
+
shadowed: list[ShadowedNamespacePortion] = []
|
|
49
|
+
for index, registry in enumerate(registries):
|
|
50
|
+
foreign_regular = {
|
|
51
|
+
fqn
|
|
52
|
+
for other, fqns in enumerate(regular_by_registry)
|
|
53
|
+
if other != index
|
|
54
|
+
for fqn in fqns
|
|
55
|
+
}
|
|
56
|
+
if not foreign_regular:
|
|
57
|
+
continue
|
|
58
|
+
candidates = sorted(
|
|
59
|
+
(
|
|
60
|
+
entity
|
|
61
|
+
for entity in registry.values()
|
|
62
|
+
if isinstance(entity, PythonNamespacePackage)
|
|
63
|
+
and _shadows(foreign_regular, entity.fqn)
|
|
64
|
+
),
|
|
65
|
+
key=lambda entity: (entity.fqn, entity.path),
|
|
66
|
+
)
|
|
67
|
+
for container in candidates:
|
|
68
|
+
if container.id not in registry:
|
|
69
|
+
continue
|
|
70
|
+
detached = _drop_portion(registry, container)
|
|
71
|
+
portion = ShadowedNamespacePortion(
|
|
72
|
+
fqn=container.fqn,
|
|
73
|
+
path=container.path,
|
|
74
|
+
registry_index=index,
|
|
75
|
+
detached_ids=tuple(detached),
|
|
76
|
+
)
|
|
77
|
+
shadowed.append(portion)
|
|
78
|
+
logger.warning(
|
|
79
|
+
"namespace portion '%s' is shadowed by a regular package of the "
|
|
80
|
+
"same name in another root; its %d module(s) stay indexed "
|
|
81
|
+
"without a parent package",
|
|
82
|
+
container.fqn,
|
|
83
|
+
len(detached),
|
|
84
|
+
)
|
|
85
|
+
return shadowed
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _drop_portion(
|
|
89
|
+
registry: EntityRegistry, container: PythonNamespacePackage
|
|
90
|
+
) -> list[SymbolID]:
|
|
91
|
+
detached: list[SymbolID] = []
|
|
92
|
+
pending = [container]
|
|
93
|
+
while pending:
|
|
94
|
+
current = pending.pop()
|
|
95
|
+
parent = registry.get(current.parent_id) if current.parent_id else None
|
|
96
|
+
if isinstance(parent, (PythonNamespacePackage, PythonPackage)):
|
|
97
|
+
parent.submodule_ids = [
|
|
98
|
+
entity_id
|
|
99
|
+
for entity_id in parent.submodule_ids
|
|
100
|
+
if entity_id != current.id
|
|
101
|
+
]
|
|
102
|
+
registry.remove(current.id)
|
|
103
|
+
for child_id in current.submodule_ids:
|
|
104
|
+
child = registry.get(child_id)
|
|
105
|
+
if child is None:
|
|
106
|
+
continue
|
|
107
|
+
if isinstance(child, PythonNamespacePackage):
|
|
108
|
+
pending.append(child)
|
|
109
|
+
else:
|
|
110
|
+
child.parent_id = None
|
|
111
|
+
detached.append(child.id)
|
|
112
|
+
return sorted(detached)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
__all__ = ["ShadowedNamespacePortion", "apply_regular_package_precedence"]
|
|
@@ -190,6 +190,9 @@ def entity_to_record(
|
|
|
190
190
|
path = getattr(entity, "path", None)
|
|
191
191
|
if path is not None:
|
|
192
192
|
metadata["path"] = path
|
|
193
|
+
source_root_id = getattr(entity, "source_root_id", None)
|
|
194
|
+
if source_root_id:
|
|
195
|
+
metadata["source_root_id"] = source_root_id
|
|
193
196
|
if isinstance(entity, PythonModule) and entity.all_exports is not None:
|
|
194
197
|
metadata["all_exports"] = entity.all_exports
|
|
195
198
|
if isinstance(entity, PythonModule) and entity.exports_dynamic:
|
|
@@ -344,6 +347,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
344
347
|
all_exports=meta.get("all_exports"),
|
|
345
348
|
exports_dynamic=meta.get("exports_dynamic", False),
|
|
346
349
|
path=meta.get("path", ""),
|
|
350
|
+
source_root_id=meta.get("source_root_id"),
|
|
347
351
|
source="",
|
|
348
352
|
docstring_range=None,
|
|
349
353
|
import_stmt_ids=meta.get("import_stmt_ids", []),
|
|
@@ -360,6 +364,7 @@ def record_to_entity(record: dict) -> Entity | None:
|
|
|
360
364
|
all_exports=meta.get("all_exports"),
|
|
361
365
|
exports_dynamic=meta.get("exports_dynamic", False),
|
|
362
366
|
path=meta.get("path", ""),
|
|
367
|
+
source_root_id=meta.get("source_root_id"),
|
|
363
368
|
source="",
|
|
364
369
|
docstring_range=None,
|
|
365
370
|
import_stmt_ids=meta.get("import_stmt_ids", []),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: deproc-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python language plugin for deproc.
|
|
5
5
|
Author-email: Gurveer Singh Virk <gurveervirk.15517@gmail.com>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -16,7 +16,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
17
|
Classifier: Topic :: Software Development :: Libraries
|
|
18
18
|
Requires-Python: >=3.12
|
|
19
|
-
Requires-Dist: deproc-core>=0.
|
|
19
|
+
Requires-Dist: deproc-core>=0.4.0
|
|
20
20
|
Requires-Dist: deproc-utils-tree-sitter>=0.1.2
|
|
21
21
|
Requires-Dist: tree-sitter>=0.25.2
|
|
22
22
|
Requires-Dist: tree-sitter-python>=0.25.0
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
deproc/plugins/python/__init__.py,sha256=JuMffHnYtF82voXTOP4m1hQ-zTGA5OeroWhHuz9v8nk,504
|
|
2
2
|
deproc/plugins/python/linker/__init__.py,sha256=gQ64CQcNEDHfvyAuYAz81PZ6r2V0ZdnsVOR2YZZvvfU,59
|
|
3
|
-
deproc/plugins/python/linker/main.py,sha256=
|
|
4
|
-
deproc/plugins/python/linker/models.py,sha256=
|
|
3
|
+
deproc/plugins/python/linker/main.py,sha256=As8K2k1PtxdO7GnFC4cRQXRDzVJOFWqKPLx5O_xj2V4,3641
|
|
4
|
+
deproc/plugins/python/linker/models.py,sha256=aXigj6ATiTmM_wQVjSQP_Te8An6wm_XhR3InauqRaMc,1198
|
|
5
5
|
deproc/plugins/python/parser/__init__.py,sha256=dcfU6uyIOBUOvnz9xM4hX6gc0ldTGavHZCSIv6lbWWk,71
|
|
6
|
-
deproc/plugins/python/parser/main.py,sha256=
|
|
6
|
+
deproc/plugins/python/parser/main.py,sha256=hXODQpsCTOnTmi4xlTbGhl95SyusU5RmYMFZm5obtCI,31197
|
|
7
7
|
deproc/plugins/python/parser/models.py,sha256=_Fr239_t-v6ET5EA1uUVTUiFHztqbJ03Q7WfdktrQnc,1700
|
|
8
8
|
deproc/plugins/python/parser/utils/extraction.py,sha256=UE5u6SA_KrrGX6hTbuW1RrlFRvNqrlA-jMpGepHX0z0,7221
|
|
9
9
|
deproc/plugins/python/parser/utils/misc.py,sha256=vdxTcrNdWndIvaZtC8zGlKYI6XZnZHZ7I7YskuvXdnQ,219
|
|
@@ -17,8 +17,9 @@ deproc/plugins/python/symbol_cache/models.py,sha256=1SgqUyhNnwZcITRCL8a-21T26niQ
|
|
|
17
17
|
deproc/plugins/python/utils/exports.py,sha256=45dvBfClVEo_ZRN6vCPEx0VH3-eRQiKahv1Qgg074Lo,5218
|
|
18
18
|
deproc/plugins/python/utils/imports.py,sha256=DWvcN2SdYmhQgRl9RYAc5nxbbijSEtAJ11X_Xrf3x_U,547
|
|
19
19
|
deproc/plugins/python/utils/mro.py,sha256=6tTC5lHFK2PZWX-454dGKNmiVhFDrMRQhI0bgDJZlrk,1565
|
|
20
|
-
deproc/plugins/python/utils/
|
|
21
|
-
|
|
22
|
-
deproc_python-0.
|
|
23
|
-
deproc_python-0.
|
|
24
|
-
deproc_python-0.
|
|
20
|
+
deproc/plugins/python/utils/packages.py,sha256=d6gUP1_KE8_r3StPpdRpH5TyWJnaMlpXVqzBOFEm1HI,3861
|
|
21
|
+
deproc/plugins/python/utils/serialization.py,sha256=oiuezQ5XslWBPnQyCidEPHxqOSkBfFS0xFQ6PVsQ-ic,16903
|
|
22
|
+
deproc_python-0.3.0.dist-info/METADATA,sha256=UVBExd7lUnv4FpWAe2MuGPP9BdIfdEAG8ERmorq5JjQ,949
|
|
23
|
+
deproc_python-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
24
|
+
deproc_python-0.3.0.dist-info/top_level.txt,sha256=qyPIAnJVTLaewuAbLpShmn-777EtCI7b1b5sGgkzO10,7
|
|
25
|
+
deproc_python-0.3.0.dist-info/RECORD,,
|
|
File without changes
|