graphlore-engine 0.5.79__cp310-abi3-win_amd64.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.
- graphlore_engine/__init__.py +21 -0
- graphlore_engine/__main__.py +80 -0
- graphlore_engine/_native.pyd +4 -0
- graphlore_engine/_native.pyi +19 -0
- graphlore_engine/py.typed +0 -0
- graphlore_engine-0.5.79.dist-info/METADATA +70 -0
- graphlore_engine-0.5.79.dist-info/RECORD +11 -0
- graphlore_engine-0.5.79.dist-info/WHEEL +4 -0
- graphlore_engine-0.5.79.dist-info/entry_points.txt +2 -0
- graphlore_engine-0.5.79.dist-info/licenses/LICENSE +21 -0
- graphlore_engine-0.5.79.dist-info/sboms/graphlore-engine.cyclonedx.json +2454 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""graphlore's native code-graph extractor.
|
|
2
|
+
|
|
3
|
+
``build`` walks a project and writes a graphify-compatible ``graph.json``;
|
|
4
|
+
``cluster`` detects its communities again;
|
|
5
|
+
``file_spans`` / ``file_facts`` read one file. The tree-sitter grammars are
|
|
6
|
+
compiled in: nothing is downloaded, nothing reaches the network.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from ._native import (
|
|
10
|
+
SCHEMA_VERSION,
|
|
11
|
+
__version__,
|
|
12
|
+
build,
|
|
13
|
+
cluster,
|
|
14
|
+
file_facts,
|
|
15
|
+
file_spans,
|
|
16
|
+
languages,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"SCHEMA_VERSION", "__version__", "build", "cluster", "file_facts", "file_spans", "languages",
|
|
21
|
+
]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""``python -m graphlore_engine``: the engine's command line.
|
|
2
|
+
|
|
3
|
+
build ROOT [--out PATH] [--commit SHA] [--no-docs] [--out-dir-name NAME] [--incremental]
|
|
4
|
+
[--unresolved PATH]
|
|
5
|
+
cluster GRAPH
|
|
6
|
+
spans FILE [--as PATH]
|
|
7
|
+
languages
|
|
8
|
+
|
|
9
|
+
``build`` and ``cluster`` print their report as JSON on stdout; a failure prints ``ERROR: ...``
|
|
10
|
+
on stderr and exits 1. graphlore's server runs builds this way, in a child
|
|
11
|
+
process, so a crash in a grammar cannot take the server down.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import argparse
|
|
17
|
+
import json
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main(argv: list[str] | None = None) -> int:
|
|
23
|
+
from . import __version__, build, cluster, file_spans, languages
|
|
24
|
+
|
|
25
|
+
p = argparse.ArgumentParser(prog="graphlore-engine")
|
|
26
|
+
p.add_argument("--version", action="version", version=__version__)
|
|
27
|
+
sub = p.add_subparsers(dest="cmd", required=True)
|
|
28
|
+
b = sub.add_parser("build", help="build graph.json for a project")
|
|
29
|
+
b.add_argument("root")
|
|
30
|
+
b.add_argument("--out", help="graph.json to write (default: ROOT/OUT_DIR_NAME/graph.json)")
|
|
31
|
+
b.add_argument("--commit", help="value for built_at_commit")
|
|
32
|
+
b.add_argument("--no-docs", action="store_true", help="skip Markdown / RST headings")
|
|
33
|
+
b.add_argument("--out-dir-name", default="graphify-out")
|
|
34
|
+
b.add_argument("--max-file-bytes", type=int, default=2 * 1024 * 1024)
|
|
35
|
+
b.add_argument("--threads", type=int)
|
|
36
|
+
b.add_argument("--incremental", action="store_true",
|
|
37
|
+
help="reuse the facts of files unchanged since the last build")
|
|
38
|
+
b.add_argument("--unresolved", metavar="PATH",
|
|
39
|
+
help="also write the calls left without an edge whose name is one "
|
|
40
|
+
"definition of the project, each with the reason (JSON)")
|
|
41
|
+
c = sub.add_parser("cluster", help="detect a graph.json's communities again")
|
|
42
|
+
c.add_argument("graph")
|
|
43
|
+
s = sub.add_parser("spans", help="print the definition spans of one file")
|
|
44
|
+
s.add_argument("file")
|
|
45
|
+
s.add_argument("--as", dest="rel", help="path to detect the language from")
|
|
46
|
+
sub.add_parser("languages", help="list the languages and extensions read")
|
|
47
|
+
args = p.parse_args(argv)
|
|
48
|
+
|
|
49
|
+
if args.cmd == "languages":
|
|
50
|
+
for name, exts in languages():
|
|
51
|
+
print(f"{name}: {' '.join('.' + e for e in exts)}")
|
|
52
|
+
return 0
|
|
53
|
+
if args.cmd == "spans":
|
|
54
|
+
src = Path(args.file).read_bytes()
|
|
55
|
+
for row in file_spans(src, args.rel or args.file):
|
|
56
|
+
print("\t".join(map(str, row)))
|
|
57
|
+
return 0
|
|
58
|
+
if args.cmd == "cluster":
|
|
59
|
+
try:
|
|
60
|
+
print(json.dumps(json.loads(cluster(args.graph))))
|
|
61
|
+
except RuntimeError as e:
|
|
62
|
+
print(f"ERROR: {e}", file=sys.stderr)
|
|
63
|
+
return 1
|
|
64
|
+
return 0
|
|
65
|
+
out = args.out or str(Path(args.root) / args.out_dir_name / "graph.json")
|
|
66
|
+
try:
|
|
67
|
+
report = build(
|
|
68
|
+
args.root, out=out, commit=args.commit, documents=not args.no_docs,
|
|
69
|
+
out_dir_name=args.out_dir_name, max_file_bytes=args.max_file_bytes,
|
|
70
|
+
threads=args.threads, incremental=args.incremental, unresolved=args.unresolved,
|
|
71
|
+
)
|
|
72
|
+
except RuntimeError as e:
|
|
73
|
+
print(f"ERROR: {e}", file=sys.stderr)
|
|
74
|
+
return 1
|
|
75
|
+
print(json.dumps(json.loads(report)))
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
if __name__ == "__main__":
|
|
80
|
+
sys.exit(main())
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
SCHEMA_VERSION: int
|
|
2
|
+
__version__: str
|
|
3
|
+
|
|
4
|
+
def build(
|
|
5
|
+
root: str,
|
|
6
|
+
out: str | None = None,
|
|
7
|
+
commit: str | None = None,
|
|
8
|
+
documents: bool = True,
|
|
9
|
+
out_dir_name: str = "graphify-out",
|
|
10
|
+
max_file_bytes: int = ...,
|
|
11
|
+
parse_timeout_ms: int = 10000,
|
|
12
|
+
threads: int | None = None,
|
|
13
|
+
incremental: bool = False,
|
|
14
|
+
unresolved: str | None = None,
|
|
15
|
+
) -> str: ...
|
|
16
|
+
def cluster(graph: str) -> str: ...
|
|
17
|
+
def file_spans(src: bytes, rel: str) -> list[tuple[int, int, int, str]]: ...
|
|
18
|
+
def file_facts(src: bytes, rel: str) -> str: ...
|
|
19
|
+
def languages() -> list[tuple[str, list[str]]]: ...
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: graphlore-engine
|
|
3
|
+
Version: 0.5.79
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Rust
|
|
9
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Summary: graphlore's native code-graph extractor: definitions, spans and containment in 14 languages, with tree-sitter grammars compiled in.
|
|
12
|
+
Keywords: graphlore,tree-sitter,code-graph,knowledge-graph,static-analysis
|
|
13
|
+
Author: yasinyaman
|
|
14
|
+
License: MIT
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
17
|
+
Project-URL: Changelog, https://github.com/yasinyaman/graphlore/blob/master/CHANGELOG.md
|
|
18
|
+
Project-URL: Documentation, https://github.com/yasinyaman/graphlore/blob/master/docs/native-engine.md
|
|
19
|
+
Project-URL: Homepage, https://github.com/yasinyaman/graphlore
|
|
20
|
+
|
|
21
|
+
# graphlore-engine
|
|
22
|
+
|
|
23
|
+
The native code-graph extractor behind [graphlore](https://github.com/yasinyaman/graphlore).
|
|
24
|
+
It walks a project, parses every source file with a tree-sitter grammar compiled
|
|
25
|
+
into the wheel, and writes a graphify-compatible `graph.json`: a node per file,
|
|
26
|
+
per definition (with its real `start..end` span), property, constant and
|
|
27
|
+
document heading, the containment edges between them, the imports, calls,
|
|
28
|
+
bases and type references it resolves from the source, the methods written
|
|
29
|
+
for a base's method (`dispatches_to`), shared state (the
|
|
30
|
+
variables, fields, constants, environment variables, files, tables and events
|
|
31
|
+
definitions read and write), web routes with their full paths and the
|
|
32
|
+
requests the code makes to them (`handles` / `http_calls`), and communities
|
|
33
|
+
(Leiden on edges weighted by
|
|
34
|
+
kind, confidence and directory, stable across rebuilds).
|
|
35
|
+
|
|
36
|
+
Languages: Python, JavaScript, TypeScript, TSX, Go, Java, Kotlin, Scala, C#,
|
|
37
|
+
Rust, Swift, C, C++, Ruby and PHP; plus Markdown and reStructuredText headings.
|
|
38
|
+
Nothing is downloaded at run time and nothing reaches the network.
|
|
39
|
+
|
|
40
|
+
It is experimental: graphlore uses it only when `GRAPHLORE_ENGINE=native` (or
|
|
41
|
+
`auto`) is set.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install graphlore-engine # prebuilt abi3 wheels: Linux (glibc, musl), macOS, Windows; Python 3.10+
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python -m graphlore_engine build /path/to/repo # writes graphify-out/graph.json
|
|
49
|
+
python -m graphlore_engine build /path/to/repo --incremental # parse only what changed
|
|
50
|
+
python -m graphlore_engine build /path/to/repo --unresolved left.json # the calls left without an edge, with the reason
|
|
51
|
+
python -m graphlore_engine cluster graphify-out/graph.json # detect its communities again
|
|
52
|
+
python -m graphlore_engine spans src/app.ts # one file's definitions
|
|
53
|
+
python -m graphlore_engine languages
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Developing
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install maturin
|
|
60
|
+
maturin develop -m engine/Cargo.toml --release # from the repository root
|
|
61
|
+
cargo test --manifest-path engine/Cargo.toml
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Adding a language: add its grammar crate to `Cargo.toml`, a `Lang` variant and a
|
|
65
|
+
row in `SPECS` (`src/lang/mod.rs`), and a module in `src/lang/` that overrides
|
|
66
|
+
only what its grammar does differently from the generic walk (`src/generic.rs`).
|
|
67
|
+
Then add golden snippets to `tests/spans_golden.rs`, a small project to
|
|
68
|
+
`tests/edges_golden.rs`, and the language's module paths to
|
|
69
|
+
`src/resolve/modules.rs`.
|
|
70
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
graphlore_engine/__init__.py,sha256=l-NwIx45KhsNPbjs-Rtvz6nR8VVjdoi7YN8fZgHcYLg,576
|
|
2
|
+
graphlore_engine/__main__.py,sha256=ijNKQgh9LXbjf7VlyHAtJRIEhs6cR9rZohEuwcKg6rw,3405
|
|
3
|
+
graphlore_engine/_native.pyd,sha256=imn0u4yw4rj_lo88A1ibptPHjK_lQEALG-kD9jgRmZo,39666176
|
|
4
|
+
graphlore_engine/_native.pyi,sha256=jo3NU_v6GgjPCNQVwd2kyhAVhVAdT6p-5CYL_nbGCUQ,602
|
|
5
|
+
graphlore_engine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
graphlore_engine-0.5.79.dist-info/METADATA,sha256=ePUJ0fL5r76cz0CQG4a_DE9abZA285KsrfGSN7Ds5ug,3404
|
|
7
|
+
graphlore_engine-0.5.79.dist-info/WHEEL,sha256=TzjyIyBUptJHnlQyOymQYLWjtXe7MGI0m3QvmcG7PpI,96
|
|
8
|
+
graphlore_engine-0.5.79.dist-info/entry_points.txt,sha256=c9YNe4o3Phgw1I3_QAwz7xvqH3v-mQeCAMoWzNgDU8o,66
|
|
9
|
+
graphlore_engine-0.5.79.dist-info/licenses/LICENSE,sha256=T-3cwANUe6z3wwGZzJEAmM-kpdTnZ3L56Yj5wCzTebA,1088
|
|
10
|
+
graphlore_engine-0.5.79.dist-info/sboms/graphlore-engine.cyclonedx.json,sha256=gQSnlUUV-wTV8jsKplBhVn3po0awp_kJdOY43aPcdoU,77774
|
|
11
|
+
graphlore_engine-0.5.79.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 yasinyaman
|
|
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.
|