modwire 1.0.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.
- modwire/__init__.py +15 -0
- modwire/_version.py +24 -0
- modwire/architecture/__init__.py +10 -0
- modwire/architecture/analyzers.py +140 -0
- modwire/architecture/matching.py +58 -0
- modwire/architecture/policy.py +63 -0
- modwire/architecture/render.py +98 -0
- modwire/architecture/violations.py +24 -0
- modwire/definitions.py +101 -0
- modwire/extraction.py +73 -0
- modwire/extractors/__init__.py +5 -0
- modwire/extractors/base.py +177 -0
- modwire/extractors/loader.py +31 -0
- modwire/extractors/php.py +170 -0
- modwire/extractors/python.py +113 -0
- modwire/extractors/scripts/php_extractor.php +816 -0
- modwire/extractors/scripts/python_extractor.py +398 -0
- modwire/extractors/scripts/typescript_extractor.js +1030 -0
- modwire/extractors/typescript.py +48 -0
- modwire/graph.py +56 -0
- modwire-1.0.0.dist-info/METADATA +111 -0
- modwire-1.0.0.dist-info/RECORD +25 -0
- modwire-1.0.0.dist-info/WHEEL +5 -0
- modwire-1.0.0.dist-info/licenses/LICENSE +21 -0
- modwire-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from posixpath import normpath
|
|
5
|
+
from pathlib import PurePosixPath
|
|
6
|
+
|
|
7
|
+
from ..definitions import SourceImport
|
|
8
|
+
from .base import SourceExtractor
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class TypeScriptExtractor(SourceExtractor):
|
|
13
|
+
language = "typescript"
|
|
14
|
+
file_extensions = (".ts", ".tsx", ".js", ".jsx")
|
|
15
|
+
command = "node"
|
|
16
|
+
extractor_file = "typescript_extractor.js"
|
|
17
|
+
|
|
18
|
+
def normalize_import(
|
|
19
|
+
self,
|
|
20
|
+
source_id: str,
|
|
21
|
+
source_import: SourceImport,
|
|
22
|
+
known_source_ids: set[str],
|
|
23
|
+
) -> SourceImport:
|
|
24
|
+
normalized_path = source_import.normalized_path
|
|
25
|
+
if source_import.is_relative:
|
|
26
|
+
normalized_path = normpath(
|
|
27
|
+
PurePosixPath(source_id).parent.joinpath(source_import.path).as_posix()
|
|
28
|
+
)
|
|
29
|
+
normalized_path = self.normalize_source_id(normalized_path)
|
|
30
|
+
|
|
31
|
+
return SourceImport(
|
|
32
|
+
path=source_import.path,
|
|
33
|
+
is_relative=source_import.is_relative,
|
|
34
|
+
normalized_path=normalized_path,
|
|
35
|
+
imported_name=source_import.imported_name,
|
|
36
|
+
is_aliased=source_import.is_aliased,
|
|
37
|
+
crossing_type=source_import.crossing_type,
|
|
38
|
+
file_barrier_crossed=(
|
|
39
|
+
source_import.file_barrier_crossed
|
|
40
|
+
and normalized_path in known_source_ids
|
|
41
|
+
),
|
|
42
|
+
statement_id=source_import.statement_id,
|
|
43
|
+
join_key=normalized_path if source_import.join_key else "",
|
|
44
|
+
uses_joined_import=source_import.uses_joined_import,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
__all__ = ["TypeScriptExtractor"]
|
modwire/graph.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
|
|
5
|
+
from .definitions import SourceFile
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class Node:
|
|
10
|
+
id: str
|
|
11
|
+
kind: str = "file"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True)
|
|
15
|
+
class Edge:
|
|
16
|
+
from_id: str
|
|
17
|
+
to_id: str
|
|
18
|
+
kind: str = "import"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass
|
|
22
|
+
class DependencyGraph:
|
|
23
|
+
nodes: dict[str, Node] = field(default_factory=dict)
|
|
24
|
+
edges: list[Edge] = field(default_factory=list)
|
|
25
|
+
_outgoing_by_node: dict[str, list[Edge]] = field(default_factory=dict)
|
|
26
|
+
|
|
27
|
+
def add_node(self, node_id: str, *, kind: str = "file") -> None:
|
|
28
|
+
self.nodes.setdefault(node_id, Node(id=node_id, kind=kind))
|
|
29
|
+
self._outgoing_by_node.setdefault(node_id, [])
|
|
30
|
+
|
|
31
|
+
def add_edge(self, from_id: str, to_id: str, *, kind: str = "import") -> None:
|
|
32
|
+
self.add_node(from_id)
|
|
33
|
+
self.add_node(to_id)
|
|
34
|
+
edge = Edge(from_id=from_id, to_id=to_id, kind=kind)
|
|
35
|
+
self.edges.append(edge)
|
|
36
|
+
self._outgoing_by_node[from_id].append(edge)
|
|
37
|
+
|
|
38
|
+
def outgoing(self, node_id: str) -> tuple[Edge, ...]:
|
|
39
|
+
return tuple(self._outgoing_by_node.get(node_id, ()))
|
|
40
|
+
|
|
41
|
+
def node_ids(self) -> tuple[str, ...]:
|
|
42
|
+
return tuple(self.nodes.keys())
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def build_dependency_graph(extracted_files: dict[str, SourceFile]) -> DependencyGraph:
|
|
46
|
+
graph = DependencyGraph()
|
|
47
|
+
|
|
48
|
+
for file_path, extracted_file in extracted_files.items():
|
|
49
|
+
graph.add_node(file_path)
|
|
50
|
+
for imported_reference in extracted_file.imports:
|
|
51
|
+
graph.add_edge(file_path, imported_reference.normalized_path)
|
|
52
|
+
|
|
53
|
+
return graph
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
__all__ = ["DependencyGraph", "build_dependency_graph"]
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: modwire
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Extract source-code dependencies and build dependency graphs.
|
|
5
|
+
Author: Tomasz Szpak
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/9orky/codemap
|
|
8
|
+
Project-URL: Repository, https://github.com/9orky/codemap
|
|
9
|
+
Project-URL: Issues, https://github.com/9orky/codemap/issues
|
|
10
|
+
Keywords: architecture,code-analysis,dependency-graph,static-analysis
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Software Development
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: pydantic>=2.8
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.8; extra == "dev"
|
|
31
|
+
Requires-Dist: twine>=5.1; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# modwire
|
|
35
|
+
|
|
36
|
+
`modwire` extracts source-code structure and import dependencies from Python,
|
|
37
|
+
TypeScript/JavaScript, and PHP projects. It returns typed Python objects that
|
|
38
|
+
you can use to build dependency graphs, inspect symbols, and evaluate
|
|
39
|
+
architecture rules.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
python -m pip install modwire
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The Python extractor works with Python alone. TypeScript/JavaScript extraction
|
|
48
|
+
requires Node.js at runtime, and PHP extraction requires PHP at runtime.
|
|
49
|
+
|
|
50
|
+
## Quick Start
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from pathlib import Path
|
|
54
|
+
|
|
55
|
+
from modwire import extract_code
|
|
56
|
+
|
|
57
|
+
result = extract_code(
|
|
58
|
+
"python",
|
|
59
|
+
Path("src"),
|
|
60
|
+
exclusions=("**/__pycache__/**",),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
print(result.extraction_result.summary.files_checked)
|
|
64
|
+
print(result.graph.node_ids())
|
|
65
|
+
print([(edge.from_id, edge.to_id) for edge in result.graph.edges])
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Graph nodes use canonical extensionless source IDs, so equivalent Python,
|
|
69
|
+
TypeScript, and PHP projects can be compared through the same graph shape.
|
|
70
|
+
|
|
71
|
+
## Supported Languages
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from modwire import supported_languages
|
|
75
|
+
|
|
76
|
+
print(supported_languages())
|
|
77
|
+
# ("python", "typescript", "php")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Language-specific source IDs can be normalized without running a full
|
|
81
|
+
extraction:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from modwire import normalize_source_id
|
|
85
|
+
|
|
86
|
+
print(normalize_source_id("typescript", "src/view.tsx"))
|
|
87
|
+
# "src/view"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Architecture Policy API
|
|
91
|
+
|
|
92
|
+
`modwire.architecture` exposes policy evaluation helpers for checking import
|
|
93
|
+
boundaries and common dependency-flow rules.
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from modwire.architecture import ArchitecturePolicyEvaluator, supported_analyzers
|
|
97
|
+
|
|
98
|
+
print(supported_analyzers())
|
|
99
|
+
# ("backward-flow", "no-reentry", "no-cycles")
|
|
100
|
+
|
|
101
|
+
evaluator = ArchitecturePolicyEvaluator()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Development
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv run ruff check
|
|
108
|
+
uv run pytest
|
|
109
|
+
uv run python -m build --outdir dist
|
|
110
|
+
uv run twine check dist/*
|
|
111
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
modwire/__init__.py,sha256=_oDaQwkrK3-oMb6h51B4gur_xP36HgA5NqTQI_cKBnY,371
|
|
2
|
+
modwire/_version.py,sha256=JAAyU3al4wmBf3BF-Umm1J_GrCIT-yS_yWEGHqKRVHc,520
|
|
3
|
+
modwire/definitions.py,sha256=4YXHhEbL2szHPfeH6ps_Iy0o7yLe28gjAjBeu-kxH-o,2486
|
|
4
|
+
modwire/extraction.py,sha256=pfNxJshpE7Qzfryg5vI7-5b5J8MwEzBBiFwyPbwJ4ak,2154
|
|
5
|
+
modwire/graph.py,sha256=qRTAqd5yPyKIzqQinr0dMAxHdwj2guIJ3iaD76NuDbQ,1614
|
|
6
|
+
modwire/architecture/__init__.py,sha256=qGcakDv6b-CLQe6DGTD_cKlpASom0Gh3cF1A5Ddp-ts,271
|
|
7
|
+
modwire/architecture/analyzers.py,sha256=_3vj7PFwLBgEfLD_XlkvV0X7NbYIoRSlRff3pY7pXoE,4432
|
|
8
|
+
modwire/architecture/matching.py,sha256=ZP-L21kON7WpMlSenP_m5NgFj3GC1fHLYjGphsuj8pI,1951
|
|
9
|
+
modwire/architecture/policy.py,sha256=ut7_UvKfCG-oqGfO2U1tbYXzHEfPgyQiidMzKA-Ewzg,2273
|
|
10
|
+
modwire/architecture/render.py,sha256=Yk7OxBLgNjsc6ZqfhrwlTV293ABQqR0HZbODReM15I8,3145
|
|
11
|
+
modwire/architecture/violations.py,sha256=LQBxvKr4jx4U_6G3J8NpM1-eRJs23IWCzEyHNuayPkM,415
|
|
12
|
+
modwire/extractors/__init__.py,sha256=xI7e031XWEcMVx2e3gQdAQNI7VQa2iBc_GXV6fQ3sZI,118
|
|
13
|
+
modwire/extractors/base.py,sha256=Sp7Hr5QshAr8ByOnaP2juiG4sfNIB-B-car5GmBEU-g,5230
|
|
14
|
+
modwire/extractors/loader.py,sha256=Ag21zdjGWRSiaADDi59GQzlDZ33dhDcvGo-b6h-AwWU,830
|
|
15
|
+
modwire/extractors/php.py,sha256=b1I7qQDPzgSQUZkJUtGfOW_S6aHR9_Jvhs2umLPf6Oc,5650
|
|
16
|
+
modwire/extractors/python.py,sha256=pubG6JlFi7OKueGTw9fLZN89pYF1sJ3dqBlD-FwNP8M,3914
|
|
17
|
+
modwire/extractors/typescript.py,sha256=M6tkD_CbBQfNxk-UJQ8mHlenT5hzYN1xBOLO9v9_rQc,1612
|
|
18
|
+
modwire/extractors/scripts/php_extractor.php,sha256=xwqECd0weYIU5vQpLxFpW6g0jzr64N1FU9vFdffhR6w,28525
|
|
19
|
+
modwire/extractors/scripts/python_extractor.py,sha256=EeI-bqA9DTYH78w-lUpILHuT8bJ2o81TvwwwPRAvvTM,13571
|
|
20
|
+
modwire/extractors/scripts/typescript_extractor.js,sha256=xGxr8U9pdCtqsC0XRugd-6iV6o8KbWIYy7derBcPI4I,34074
|
|
21
|
+
modwire-1.0.0.dist-info/licenses/LICENSE,sha256=DxXQa2s8pS_YG13iuO5CsomZ7N2BQc8BA41Il8nu5F4,1069
|
|
22
|
+
modwire-1.0.0.dist-info/METADATA,sha256=wPH6-9KSWz5UeQ7OasDQfPFqcnyedS4N-Dfz7fK4JI0,3154
|
|
23
|
+
modwire-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
24
|
+
modwire-1.0.0.dist-info/top_level.txt,sha256=zqGajV2p9ic1QbDHG2XjTUsqg0h3YB3bHNyVkBykTHg,8
|
|
25
|
+
modwire-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tomasz Szpak
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
modwire
|