deproc-python 0.4.0__tar.gz → 0.4.1__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.
Files changed (42) hide show
  1. deproc_python-0.4.1/PKG-INFO +128 -0
  2. deproc_python-0.4.1/README.md +104 -0
  3. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/utils/packages.py +29 -8
  4. deproc_python-0.4.1/deproc_python.egg-info/PKG-INFO +128 -0
  5. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc_python.egg-info/SOURCES.txt +1 -0
  6. {deproc_python-0.4.0 → deproc_python-0.4.1}/pyproject.toml +2 -1
  7. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_parser.py +1 -1
  8. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_shared_registry_precedence.py +94 -0
  9. deproc_python-0.4.0/PKG-INFO +0 -22
  10. deproc_python-0.4.0/deproc_python.egg-info/PKG-INFO +0 -22
  11. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/__init__.py +0 -0
  12. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/linker/__init__.py +0 -0
  13. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/linker/main.py +0 -0
  14. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/linker/models.py +0 -0
  15. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/__init__.py +0 -0
  16. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/main.py +0 -0
  17. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/models.py +0 -0
  18. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/utils/extraction.py +0 -0
  19. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/utils/misc.py +0 -0
  20. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/parser/utils/tree_sitter_python.py +0 -0
  21. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/resolver/__init__.py +0 -0
  22. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/resolver/main.py +0 -0
  23. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/resolver/models.py +0 -0
  24. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/symbol_cache/__init__.py +0 -0
  25. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/symbol_cache/main.py +0 -0
  26. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/symbol_cache/models.py +0 -0
  27. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/utils/exports.py +0 -0
  28. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/utils/imports.py +0 -0
  29. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/utils/mro.py +0 -0
  30. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc/plugins/python/utils/serialization.py +0 -0
  31. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc_python.egg-info/dependency_links.txt +0 -0
  32. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc_python.egg-info/requires.txt +0 -0
  33. {deproc_python-0.4.0 → deproc_python-0.4.1}/deproc_python.egg-info/top_level.txt +0 -0
  34. {deproc_python-0.4.0 → deproc_python-0.4.1}/setup.cfg +0 -0
  35. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_exports.py +0 -0
  36. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_imports.py +0 -0
  37. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_linker.py +0 -0
  38. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_mro.py +0 -0
  39. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_package_precedence.py +0 -0
  40. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_python_serialization.py +0 -0
  41. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_resolver.py +0 -0
  42. {deproc_python-0.4.0 → deproc_python-0.4.1}/tests/test_symbol_cache.py +0 -0
@@ -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)
@@ -0,0 +1,104 @@
1
+ # deproc-python
2
+
3
+ Python language plugin for [deproc](https://github.com/gurveervirk/deproc).
4
+
5
+ Parses `.py` and `.pyi` files with tree-sitter into the deproc entity model,
6
+ links them into a package hierarchy, and resolves names across modules.
7
+
8
+ ## Features
9
+
10
+ - Modules, classes, functions and methods, constants, type aliases, imports and
11
+ import aliases as deproc entities
12
+ - Regular packages (`__init__.py`) and implicit namespace packages, including a
13
+ namespace package contributed by several roots
14
+ - Python's regular-package precedence across roots: a regular package wins over
15
+ a same-named namespace portion from another root
16
+ - Name resolution through imports, relative imports and wildcard imports
17
+ - Class MRO (C3 linearization) and inherited members
18
+ - Entity serialization to flat records and back
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ python -m pip install deproc-python
24
+ ```
25
+
26
+ `deproc-python` supports Python 3.12 and newer and installs `deproc-core` with it.
27
+
28
+ ## Usage
29
+
30
+ ```python
31
+ from deproc.core.context import Context
32
+ from deproc.core.discovery import find_source_files
33
+ from deproc.plugins.python import (
34
+ PythonLinker,
35
+ PythonResolver,
36
+ PythonSourceParser,
37
+ PythonSymbolCache,
38
+ )
39
+
40
+ ctx = Context(base_path="/path/to/project")
41
+ ctx.set_language("python", [".py", ".pyi"], aliases=["py"])
42
+ ctx.set_parser("python", PythonSourceParser())
43
+ ctx.set_linker("python", PythonLinker())
44
+ ctx.set_resolver("python", PythonResolver())
45
+ ctx.set_symbol_cache(PythonSymbolCache())
46
+
47
+ files = find_source_files(ctx)
48
+ parser = ctx.get_parser("python")
49
+ modules = [parser.parse_file(path, ctx) for path in files]
50
+ ctx.get_linker("python").link_files(modules, ctx)
51
+
52
+ result = ctx.get_resolver("python").resolve("acme_billing.invoice", "TaxRate", ctx)
53
+ print(result.status) # resolved
54
+ for entity_id in result.resolved_ids:
55
+ print(ctx.entity_registry.get(entity_id).fqn) # acme_billing.tax.TaxRate
56
+ ```
57
+
58
+ `result.status` is a `ResolutionStatus` (`RESOLVED`, `UNRESOLVED`, `AMBIGUOUS`, or
59
+ `INACCESSIBLE`) from `deproc.core.interfaces.resolver`. The result also carries
60
+ `unresolved_ids`, `ambiguous_ids`, `inaccessible_ids`, `reason` and `candidates`.
61
+
62
+ `PythonResolver` also provides `resolve_class_mro(class_id, ctx)` and
63
+ `get_inherited_members(class_id, ctx)`.
64
+
65
+ ## Several roots
66
+
67
+ When several roots contribute the same package name, deproc follows Python's
68
+ import rule:
69
+
70
+ - A regular package (`__init__.py`) in one root wins over a same-named namespace
71
+ portion in another root, in any root order. The shadowed container is removed
72
+ and its modules stay indexed with no parent.
73
+ - Namespace portions with the same name in several roots become one namespace
74
+ package.
75
+ - Two regular packages with the same name in different roots are both kept, and a
76
+ warning names the roots, because Python would import whichever comes first on
77
+ its path.
78
+
79
+ `PythonLinker.link_files()` applies this rule automatically when roots share one
80
+ registry; `PythonLinker(apply_package_precedence=False)` turns it off.
81
+ `deproc.plugins.python.utils.packages` provides
82
+ `apply_regular_package_precedence()` for separate per-root registries,
83
+ `apply_regular_package_precedence_to_registry()` for one shared registry, and
84
+ `find_regular_package_conflicts()`. Pass `root_labels` to either precedence
85
+ function to name roots in the warning.
86
+
87
+ ## Package layout
88
+
89
+ ```
90
+ deproc-python/
91
+ ├── deproc/plugins/python/
92
+ │ ├── parser/ PythonSourceParser (tree-sitter AST → entities)
93
+ │ ├── linker/ PythonLinker (modules → package hierarchy)
94
+ │ ├── resolver/ PythonResolver (names, MRO, inherited members)
95
+ │ ├── symbol_cache/ PythonSymbolCache (per-module cache)
96
+ │ └── utils/ imports, exports, MRO, package precedence, serialization
97
+ └── tests/
98
+ ```
99
+
100
+ ## Dependencies
101
+
102
+ - `deproc-core` (entity model, Context, EntityRegistry)
103
+ - `deproc-utils-tree-sitter` (AST walking utilities)
104
+ - `tree-sitter` (`>=0.25.2,<0.26`) and `tree-sitter-python` (Python grammar)
@@ -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)
@@ -1,3 +1,4 @@
1
+ README.md
1
2
  pyproject.toml
2
3
  deproc/plugins/python/__init__.py
3
4
  deproc/plugins/python/linker/__init__.py
@@ -4,8 +4,9 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "deproc-python"
7
- version = "0.4.0"
7
+ version = "0.4.1"
8
8
  description = "Python language plugin for deproc."
9
+ readme = "README.md"
9
10
  authors = [
10
11
  { name = "Gurveer Singh Virk", email = "gurveervirk.15517@gmail.com" }
11
12
  ]
@@ -16,7 +16,7 @@ context = Context()
16
16
 
17
17
 
18
18
  def _create_temp_file(content: str) -> str:
19
- """Helper to create a temporary file with given content."""
19
+ """Create a temporary file with the given content."""
20
20
  import tempfile
21
21
 
22
22
  with tempfile.NamedTemporaryFile(delete=False, mode="w", suffix=".py") as tmp:
@@ -419,3 +419,97 @@ def test_two_same_named_regular_packages_are_kept_in_either_root_order(
419
419
  assert any(
420
420
  "defined in more than one root" in r.getMessage() for r in caplog.records
421
421
  )
422
+
423
+
424
+ def _conflict_messages(caplog) -> list[str]:
425
+ return [
426
+ r.getMessage()
427
+ for r in caplog.records
428
+ if r.name == PACKAGES_LOGGER
429
+ and "defined in more than one root" in r.getMessage()
430
+ ]
431
+
432
+
433
+ def _per_root_registries(
434
+ base: Path, layout: Layout, root_ids: dict[str, str | None]
435
+ ) -> list[EntityRegistry]:
436
+ registries = []
437
+ for name, files in layout.items():
438
+ registry = EntityRegistry()
439
+ _link_into(registry, base, name, files, root_ids[name])
440
+ registries.append(registry)
441
+ return registries
442
+
443
+
444
+ def test_conflict_warning_names_roots_by_their_labels(tmp_path, caplog):
445
+ registries = _per_root_registries(
446
+ tmp_path, TWO_REGULAR, {"first": None, "second": "shared"}
447
+ )
448
+
449
+ with caplog.at_level(logging.WARNING, logger=PACKAGES_LOGGER):
450
+ apply_regular_package_precedence(
451
+ registries,
452
+ root_labels={
453
+ None: "/work/app [project]",
454
+ "shared": "/work/shared [source]",
455
+ },
456
+ )
457
+
458
+ assert _conflict_messages(caplog) == [
459
+ "regular package 'acme' is defined in more than one root "
460
+ "(/work/app [project], /work/shared [source]); Python imports only the "
461
+ "first one on its path, and all of them stay indexed"
462
+ ]
463
+
464
+
465
+ def test_conflict_warning_falls_back_to_root_ids_for_unlabelled_roots(tmp_path, caplog):
466
+ layout = {**TWO_REGULAR, "third": TWO_REGULAR["first"]}
467
+ registries = _per_root_registries(
468
+ tmp_path, layout, {"first": None, "second": "shared", "third": "vendor"}
469
+ )
470
+
471
+ with caplog.at_level(logging.WARNING, logger=PACKAGES_LOGGER):
472
+ apply_regular_package_precedence(
473
+ registries, root_labels={"shared": "/work/shared [source]"}
474
+ )
475
+
476
+ (message,) = _conflict_messages(caplog)
477
+ assert "(<no root id>, /work/shared [source], vendor)" in message
478
+
479
+
480
+ def test_conflict_warning_without_labels_is_unchanged(tmp_path, caplog):
481
+ registries = _per_root_registries(
482
+ tmp_path, TWO_REGULAR, {"first": None, "second": "shared"}
483
+ )
484
+
485
+ with caplog.at_level(logging.WARNING, logger=PACKAGES_LOGGER):
486
+ apply_regular_package_precedence(registries)
487
+
488
+ assert _conflict_messages(caplog) == [
489
+ "regular package 'acme' is defined in more than one root "
490
+ "(<no root id>, shared); Python imports only the first one on its path, "
491
+ "and all of them stay indexed"
492
+ ]
493
+
494
+
495
+ def test_shared_registry_conflict_warning_names_roots_by_their_labels(tmp_path, caplog):
496
+ from deproc.plugins.python.utils.packages import (
497
+ apply_regular_package_precedence_to_registry,
498
+ )
499
+
500
+ registry = EntityRegistry()
501
+ linker = PythonLinker(apply_package_precedence=False)
502
+ for name in ("first", "second"):
503
+ _link_into(registry, tmp_path, name, TWO_REGULAR[name], name, linker)
504
+
505
+ with caplog.at_level(logging.WARNING, logger=PACKAGES_LOGGER):
506
+ apply_regular_package_precedence_to_registry(
507
+ registry,
508
+ root_labels={
509
+ "first": "/work/first [source]",
510
+ "second": "/work/second [source]",
511
+ },
512
+ )
513
+
514
+ (message,) = _conflict_messages(caplog)
515
+ assert "(/work/first [source], /work/second [source])" in message
@@ -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
@@ -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
File without changes