graphe-code 0.1.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.
graphe/root.py ADDED
@@ -0,0 +1,82 @@
1
+ """The host project's root (T-0003) and its files (T-0004).
2
+
3
+ The root: GRAPHE_ROOT, else the git repository of the current directory,
4
+ else that directory. GRAPHE_ROOT serves a host's reference test (its frozen
5
+ tree), and the tool's tests.
6
+
7
+ The files: those git tracks, plus untracked files that are not ignored,
8
+ minus those that `exclude` (graphe.toml, at the root, optional) designates.
9
+ Each goes to the reader of its extension; a file no reader takes is ignored.
10
+
11
+ An external program a reader runs (T-0005): the `executable` key of the
12
+ reader's section (`[godot]`), relative to the root; else the PATH; else
13
+ nothing, with a warning that names the key.
14
+
15
+ The other keys of graphe.toml (T-0009): `displayed_text`, the pattern of the
16
+ call that displays a text, and `[documents]`, `patterns` and `identifier`
17
+ (T-0010, core.py); `[communities]`, `separate` and `strip_prefixes`
18
+ (cli.py); `[[extensions]]` (docs/contribution.md).
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import shutil
25
+ import subprocess
26
+ import sys
27
+ import tomllib
28
+ from pathlib import Path, PurePosixPath
29
+
30
+ def root() -> Path:
31
+ if os.environ.get("GRAPHE_ROOT"):
32
+ return Path(os.environ["GRAPHE_ROOT"]).resolve()
33
+ try:
34
+ r = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True, timeout=10)
35
+ if r.returncode == 0 and r.stdout.strip():
36
+ return Path(r.stdout.strip()).resolve()
37
+ except (OSError, subprocess.SubprocessError):
38
+ pass
39
+ return Path.cwd().resolve()
40
+
41
+
42
+ ROOT = root()
43
+ OUTPUT = ROOT / "graphe" # the output: never read as a host file (its cache/ serves the Python reader)
44
+ CONFIGURATION = "graphe.toml"
45
+
46
+
47
+ def configuration(root: Path = ROOT) -> dict:
48
+ path = root / CONFIGURATION
49
+ return tomllib.loads(path.read_text(encoding="utf-8")) if path.is_file() else {}
50
+
51
+
52
+ def designates(rel: str, patterns: list[str]) -> bool:
53
+ """True if one of the patterns designates `rel`: `build`, the build/ folder at the root; `**/tests`, any tests/
54
+ folder. Serves `exclude` and `[documents] patterns`."""
55
+ p = PurePosixPath(rel)
56
+ return any(p.full_match(m) or p.full_match(f"{m}/**") for m in patterns)
57
+
58
+
59
+ def files(suffix: str, root: Path = ROOT) -> list[Path]:
60
+ """The host's files that end with `suffix` (`.py`), sorted."""
61
+ r = subprocess.run(["git", "ls-files", "-z", "--cached", "--others", "--exclude-standard"], cwd=root,
62
+ capture_output=True, text=True, encoding="utf-8", timeout=60)
63
+ if r.returncode:
64
+ raise RuntimeError(f"{root} is not a git repository: graphe reads the files git tracks")
65
+ patterns = [OUTPUT.name, *configuration(root).get("exclude", [])]
66
+ # Sorted Paths, like the old rglob: the reading order does not change.
67
+ return sorted(root / rel for rel in set(r.stdout.split("\0"))
68
+ if rel.endswith(suffix) and not designates(rel, patterns) and (root / rel).is_file())
69
+
70
+
71
+ def executable(section: str, name: str, root: Path = ROOT) -> Path | None:
72
+ """A reader's program `name`: `[section] executable` of graphe.toml, else the PATH, else None."""
73
+ given = configuration(root).get(section, {}).get("executable")
74
+ if given:
75
+ if (path := root / given).is_file(): # an absolute path stays absolute
76
+ return path
77
+ print(f"graphe: {path} not found ([{section}] executable, {CONFIGURATION})", file=sys.stderr)
78
+ if found := shutil.which(name):
79
+ return Path(found)
80
+ print(f"graphe: {name} not found, neither by [{section}] executable in {CONFIGURATION} nor in the PATH:"
81
+ f" the reader goes on without it", file=sys.stderr)
82
+ return None
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphe-code
3
+ Version: 0.1.0
4
+ Summary: The code graph of a host project: what calls what, what cites what.
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.13
7
+ License-File: LICENSE
8
+ Requires-Dist: networkx>=3.6.1
9
+ Requires-Dist: numpy>=2.4.4
10
+ Requires-Dist: scipy>=1.18.1
11
+ Requires-Dist: tree-sitter<0.27,>=0.26.1
12
+ Requires-Dist: tree-sitter-c<0.25,>=0.24.2
13
+ Requires-Dist: tree-sitter-c-sharp<0.25,>=0.24.0
14
+ Requires-Dist: tree-sitter-cpp<0.24,>=0.23.4
15
+ Requires-Dist: tree-sitter-go<0.26,>=0.25.0
16
+ Requires-Dist: tree-sitter-java<0.24,>=0.23.5
17
+ Requires-Dist: tree-sitter-javascript<0.26,>=0.25.0
18
+ Requires-Dist: tree-sitter-kotlin<2,>=1.1.0
19
+ Requires-Dist: tree-sitter-php<0.26,>=0.25.2
20
+ Requires-Dist: tree-sitter-ruby<0.24,>=0.23.1
21
+ Requires-Dist: tree-sitter-rust<0.25,>=0.24.2
22
+ Requires-Dist: tree-sitter-swift<0.8,>=0.7.4
23
+ Requires-Dist: tree-sitter-typescript<0.24,>=0.23.2
24
+ Dynamic: license-file
@@ -0,0 +1,14 @@
1
+ graphe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ graphe/cli.py,sha256=pp64cg8m2fVSMB7-0qbJDmgVGzNA2MFLyBBZDfz3zSM,54053
3
+ graphe/core.py,sha256=2D3cHeK1sMD9Ky_UWZAZ1KaN-vmHERRrNlQhHmw2xPY,22543
4
+ graphe/generic.py,sha256=XnX2gneppM3ZpCrVUcgm2FgN5P_akd-cf1wa-rjMiow,48191
5
+ graphe/godot.py,sha256=O9QJ0edUYHUgdGMV_a1VEnnAn3kfmi5fY_o3IDPUsR8,18321
6
+ graphe/js.py,sha256=i3DJW8hBTVIQICCxLCTa_Ij8agFbizv1sfw6g_vFQR4,31087
7
+ graphe/python.py,sha256=7RkQ-jbB05_sA1F8uDMWpASgiVRV0FurJqtUX-WdmW8,44642
8
+ graphe/root.py,sha256=dUMaGu3N5lLBKG0ZDkifeWcaoMP4NgAeTOaZe0qr6oQ,3627
9
+ graphe_code-0.1.0.dist-info/licenses/LICENSE,sha256=DhXu9QpTc7jeNkXF0I-cfOaXEfV6IGJR1ojQ0OQB5kk,1074
10
+ graphe_code-0.1.0.dist-info/METADATA,sha256=qUAoT09NGJwPcAfJ3-TffckOWlZM5gQweGrLvMqV1X0,910
11
+ graphe_code-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
12
+ graphe_code-0.1.0.dist-info/entry_points.txt,sha256=c01q4nJLdV7jrAHUfnERn_EHmh9SkHIjyb_qXPuOEF0,43
13
+ graphe_code-0.1.0.dist-info/top_level.txt,sha256=LLgWQnnvrBrH7F7-RJ-cwjKmyTO1SYvwHJMoIRyWqtA,7
14
+ graphe_code-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ graphe = graphe.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amélien Bergerot
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
+ graphe