deproc-python 0.4.0__py3-none-any.whl → 0.4.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.
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import logging
4
- from collections.abc import Sequence
4
+ from collections.abc import Mapping, Sequence
5
5
  from dataclasses import dataclass
6
6
 
7
7
  from deproc.core.interfaces.parser.models import SymbolID
@@ -33,7 +33,11 @@ def _shadows(regular_fqns: set[str], fqn: str) -> bool:
33
33
  )
34
34
 
35
35
 
36
- def _root_label(root_id: str | None) -> str:
36
+ def _root_label(
37
+ root_id: str | None, root_labels: Mapping[str | None, str] | None
38
+ ) -> str:
39
+ if root_labels is not None and root_id in root_labels:
40
+ return root_labels[root_id]
37
41
  return root_id if root_id is not None else "<no root id>"
38
42
 
39
43
 
@@ -70,30 +74,45 @@ def find_regular_package_conflicts(
70
74
  ]
71
75
 
72
76
 
73
- def _log_conflicts(conflicts: Sequence[RegularPackageConflict]) -> None:
77
+ def _log_conflicts(
78
+ conflicts: Sequence[RegularPackageConflict],
79
+ root_labels: Mapping[str | None, str] | None,
80
+ ) -> None:
74
81
  for conflict in conflicts:
75
82
  logger.warning(
76
83
  "regular package '%s' is defined in more than one root (%s); Python "
77
84
  "imports only the first one on its path, and all of them stay indexed",
78
85
  conflict.fqn,
79
- ", ".join(_root_label(root_id) for root_id in conflict.source_root_ids),
86
+ ", ".join(
87
+ _root_label(root_id, root_labels)
88
+ for root_id in conflict.source_root_ids
89
+ ),
80
90
  )
81
91
 
82
92
 
83
93
  def apply_regular_package_precedence(
84
94
  registries: Sequence[EntityRegistry],
95
+ *,
96
+ root_labels: Mapping[str | None, str] | None = None,
85
97
  ) -> list[ShadowedNamespacePortion]:
86
98
  """Apply Python's rule that a regular package wins over a namespace portion.
87
99
 
88
- ``registries`` are the per-root link results, before they are merged. A
89
- namespace portion in one registry is shadowed when a different registry
100
+ A namespace portion in one registry is shadowed when a different registry
90
101
  holds a regular package (one with ``__init__.py``) of the same name, or of
91
102
  an ancestor name. Python then never imports that portion, so its container
92
103
  is removed and the modules it held stay in the registry without a parent.
93
104
  A warning is logged for each regular package name that more than one
94
105
  registry defines; all of them are kept.
106
+
107
+ Args:
108
+ registries: The per-root link results, before they are merged.
109
+ root_labels: Names for roots in the warning, by source root id.
110
+ Unlabelled roots show their id.
111
+
112
+ Returns:
113
+ The shadowed portions, with the module IDs each one detached.
95
114
  """
96
- _log_conflicts(find_regular_package_conflicts(registries))
115
+ _log_conflicts(find_regular_package_conflicts(registries), root_labels)
97
116
  regular_by_registry = [
98
117
  {
99
118
  entity.fqn
@@ -138,12 +157,14 @@ def apply_regular_package_precedence(
138
157
 
139
158
  def apply_regular_package_precedence_to_registry(
140
159
  registry: EntityRegistry,
160
+ *,
161
+ root_labels: Mapping[str | None, str] | None = None,
141
162
  ) -> list[ShadowedNamespacePortion]:
142
163
  regular: dict[str, list[PythonPackage]] = {}
143
164
  for entity in registry.values():
144
165
  if isinstance(entity, PythonPackage):
145
166
  regular.setdefault(entity.fqn, []).append(entity)
146
- _log_conflicts(find_regular_package_conflicts([registry]))
167
+ _log_conflicts(find_regular_package_conflicts([registry]), root_labels)
147
168
  if not regular:
148
169
  return []
149
170
 
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: deproc-python
3
+ Version: 0.4.1
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.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Requires-Python: >=3.12
19
+ Description-Content-Type: text/markdown
20
+ Requires-Dist: deproc-core>=0.4.0
21
+ Requires-Dist: deproc-utils-tree-sitter>=0.1.3
22
+ Requires-Dist: tree-sitter<0.26,>=0.25.2
23
+ Requires-Dist: tree-sitter-python>=0.25.0
24
+
25
+ # deproc-python
26
+
27
+ Python language plugin for [deproc](https://github.com/gurveervirk/deproc).
28
+
29
+ Parses `.py` and `.pyi` files with tree-sitter into the deproc entity model,
30
+ links them into a package hierarchy, and resolves names across modules.
31
+
32
+ ## Features
33
+
34
+ - Modules, classes, functions and methods, constants, type aliases, imports and
35
+ import aliases as deproc entities
36
+ - Regular packages (`__init__.py`) and implicit namespace packages, including a
37
+ namespace package contributed by several roots
38
+ - Python's regular-package precedence across roots: a regular package wins over
39
+ a same-named namespace portion from another root
40
+ - Name resolution through imports, relative imports and wildcard imports
41
+ - Class MRO (C3 linearization) and inherited members
42
+ - Entity serialization to flat records and back
43
+
44
+ ## Install
45
+
46
+ ```bash
47
+ python -m pip install deproc-python
48
+ ```
49
+
50
+ `deproc-python` supports Python 3.12 and newer and installs `deproc-core` with it.
51
+
52
+ ## Usage
53
+
54
+ ```python
55
+ from deproc.core.context import Context
56
+ from deproc.core.discovery import find_source_files
57
+ from deproc.plugins.python import (
58
+ PythonLinker,
59
+ PythonResolver,
60
+ PythonSourceParser,
61
+ PythonSymbolCache,
62
+ )
63
+
64
+ ctx = Context(base_path="/path/to/project")
65
+ ctx.set_language("python", [".py", ".pyi"], aliases=["py"])
66
+ ctx.set_parser("python", PythonSourceParser())
67
+ ctx.set_linker("python", PythonLinker())
68
+ ctx.set_resolver("python", PythonResolver())
69
+ ctx.set_symbol_cache(PythonSymbolCache())
70
+
71
+ files = find_source_files(ctx)
72
+ parser = ctx.get_parser("python")
73
+ modules = [parser.parse_file(path, ctx) for path in files]
74
+ ctx.get_linker("python").link_files(modules, ctx)
75
+
76
+ result = ctx.get_resolver("python").resolve("acme_billing.invoice", "TaxRate", ctx)
77
+ print(result.status) # resolved
78
+ for entity_id in result.resolved_ids:
79
+ print(ctx.entity_registry.get(entity_id).fqn) # acme_billing.tax.TaxRate
80
+ ```
81
+
82
+ `result.status` is a `ResolutionStatus` (`RESOLVED`, `UNRESOLVED`, `AMBIGUOUS`, or
83
+ `INACCESSIBLE`) from `deproc.core.interfaces.resolver`. The result also carries
84
+ `unresolved_ids`, `ambiguous_ids`, `inaccessible_ids`, `reason` and `candidates`.
85
+
86
+ `PythonResolver` also provides `resolve_class_mro(class_id, ctx)` and
87
+ `get_inherited_members(class_id, ctx)`.
88
+
89
+ ## Several roots
90
+
91
+ When several roots contribute the same package name, deproc follows Python's
92
+ import rule:
93
+
94
+ - A regular package (`__init__.py`) in one root wins over a same-named namespace
95
+ portion in another root, in any root order. The shadowed container is removed
96
+ and its modules stay indexed with no parent.
97
+ - Namespace portions with the same name in several roots become one namespace
98
+ package.
99
+ - Two regular packages with the same name in different roots are both kept, and a
100
+ warning names the roots, because Python would import whichever comes first on
101
+ its path.
102
+
103
+ `PythonLinker.link_files()` applies this rule automatically when roots share one
104
+ registry; `PythonLinker(apply_package_precedence=False)` turns it off.
105
+ `deproc.plugins.python.utils.packages` provides
106
+ `apply_regular_package_precedence()` for separate per-root registries,
107
+ `apply_regular_package_precedence_to_registry()` for one shared registry, and
108
+ `find_regular_package_conflicts()`. Pass `root_labels` to either precedence
109
+ function to name roots in the warning.
110
+
111
+ ## Package layout
112
+
113
+ ```
114
+ deproc-python/
115
+ ├── deproc/plugins/python/
116
+ │ ├── parser/ PythonSourceParser (tree-sitter AST → entities)
117
+ │ ├── linker/ PythonLinker (modules → package hierarchy)
118
+ │ ├── resolver/ PythonResolver (names, MRO, inherited members)
119
+ │ ├── symbol_cache/ PythonSymbolCache (per-module cache)
120
+ │ └── utils/ imports, exports, MRO, package precedence, serialization
121
+ └── tests/
122
+ ```
123
+
124
+ ## Dependencies
125
+
126
+ - `deproc-core` (entity model, Context, EntityRegistry)
127
+ - `deproc-utils-tree-sitter` (AST walking utilities)
128
+ - `tree-sitter` (`>=0.25.2,<0.26`) and `tree-sitter-python` (Python grammar)
@@ -17,9 +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/packages.py,sha256=Tdedjc8c7_R9rK9KWtZAOjNuqu55uM3ZRPwId1rsEU4,8857
20
+ deproc/plugins/python/utils/packages.py,sha256=VOOibo76bJwti6BrLlTq3ihW23MQfBALOFEAQ_W2tms,9491
21
21
  deproc/plugins/python/utils/serialization.py,sha256=oiuezQ5XslWBPnQyCidEPHxqOSkBfFS0xFQ6PVsQ-ic,16903
22
- deproc_python-0.4.0.dist-info/METADATA,sha256=xda6brcG4Bsbj-bnHPx2mudvR98YDvObK6DjF-Rxokg,955
23
- deproc_python-0.4.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
24
- deproc_python-0.4.0.dist-info/top_level.txt,sha256=qyPIAnJVTLaewuAbLpShmn-777EtCI7b1b5sGgkzO10,7
25
- deproc_python-0.4.0.dist-info/RECORD,,
22
+ deproc_python-0.4.1.dist-info/METADATA,sha256=RD3Uk4xPJ5SqfCj47gUBZMkjRd0sODQLVv-BITzvK7Q,4973
23
+ deproc_python-0.4.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
24
+ deproc_python-0.4.1.dist-info/top_level.txt,sha256=qyPIAnJVTLaewuAbLpShmn-777EtCI7b1b5sGgkzO10,7
25
+ deproc_python-0.4.1.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: deproc-python
3
- Version: 0.4.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.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Topic :: Software Development :: Libraries
18
- Requires-Python: >=3.12
19
- Requires-Dist: deproc-core>=0.4.0
20
- Requires-Dist: deproc-utils-tree-sitter>=0.1.3
21
- Requires-Dist: tree-sitter<0.26,>=0.25.2
22
- Requires-Dist: tree-sitter-python>=0.25.0