wikilinksgraph 0.1.0__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.
- wikilinksgraph-0.1.0/PKG-INFO +10 -0
- wikilinksgraph-0.1.0/README.md +2 -0
- wikilinksgraph-0.1.0/pyproject.toml +20 -0
- wikilinksgraph-0.1.0/setup.cfg +4 -0
- wikilinksgraph-0.1.0/tests/test_main.py +40 -0
- wikilinksgraph-0.1.0/wikilinksgraph/__init__.py +0 -0
- wikilinksgraph-0.1.0/wikilinksgraph/main.py +65 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/PKG-INFO +10 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/SOURCES.txt +11 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/dependency_links.txt +1 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/entry_points.txt +3 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/requires.txt +1 -0
- wikilinksgraph-0.1.0/wikilinksgraph.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wikilinksgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pyvis
|
|
8
|
+
|
|
9
|
+
# Wiki-Links-Tree
|
|
10
|
+
Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wikilinksgraph"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"pyvis",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
wikilinksgraph = "wikilinksgraph.main:main"
|
|
17
|
+
wlg = "wikilinksgraph.main:main"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools]
|
|
20
|
+
packages = ["wikilinksgraph"]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from wikilinksgraph.main import File_Reader
|
|
4
|
+
|
|
5
|
+
def test_file_reader_initialization(tmp_path):
|
|
6
|
+
(tmp_path / "Home.md").write_text("[[Page 1]]")
|
|
7
|
+
(tmp_path / "Page 1.md").write_text("[[Home]]")
|
|
8
|
+
(tmp_path / "ignore.txt").write_text("This should not be parsed.")
|
|
9
|
+
|
|
10
|
+
reader = File_Reader(str(tmp_path))
|
|
11
|
+
|
|
12
|
+
assert len(reader.md_files) == 2
|
|
13
|
+
for file_info in reader.md_files:
|
|
14
|
+
assert isinstance(file_info[0], str)
|
|
15
|
+
assert file_info[0].endswith(".md")
|
|
16
|
+
assert isinstance(file_info[1], list)
|
|
17
|
+
assert len(file_info[1]) == 0
|
|
18
|
+
|
|
19
|
+
def test_read_file_extracts_links(tmp_path):
|
|
20
|
+
home_file = tmp_path / "Home.md"
|
|
21
|
+
home_file.write_text("Here is a link to [[Page 1]] and an aliased link to [[Page 2|alias]].")
|
|
22
|
+
|
|
23
|
+
reader = File_Reader(str(tmp_path))
|
|
24
|
+
reader.Read_file(str(home_file))
|
|
25
|
+
|
|
26
|
+
home_idx = next(i for i, f in enumerate(reader.md_files) if f[0] == str(home_file))
|
|
27
|
+
links = reader.md_files[home_idx][1]
|
|
28
|
+
|
|
29
|
+
assert len(links) == 2
|
|
30
|
+
assert "Page 1" in links
|
|
31
|
+
assert "Page 2|alias" in links
|
|
32
|
+
|
|
33
|
+
def test_read_file_invalid_input(tmp_path):
|
|
34
|
+
reader = File_Reader(str(tmp_path))
|
|
35
|
+
|
|
36
|
+
with pytest.raises(ValueError):
|
|
37
|
+
reader.Read_file("non_existent_file.md")
|
|
38
|
+
|
|
39
|
+
with pytest.raises(TypeError):
|
|
40
|
+
reader.Read_file(3.14)
|
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import tempfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from pyvis.network import Network
|
|
5
|
+
|
|
6
|
+
class File_Reader:
|
|
7
|
+
def __init__(self, path):
|
|
8
|
+
self.path = path
|
|
9
|
+
self.md_files = [[str(p), []] for p in Path(self.path).rglob("*.md")]
|
|
10
|
+
# Reads all Files in CWD
|
|
11
|
+
|
|
12
|
+
def Read_file(self, file):
|
|
13
|
+
if isinstance(file, int):
|
|
14
|
+
file_index = file
|
|
15
|
+
elif isinstance(file, str):
|
|
16
|
+
try:
|
|
17
|
+
file_index = next(i for i, v in enumerate(self.md_files) if v[0] == file)
|
|
18
|
+
except StopIteration:
|
|
19
|
+
raise ValueError(f"File '{file}' not found in md_files")
|
|
20
|
+
else:
|
|
21
|
+
raise TypeError("file parameter must be an int (index) or str (path)")
|
|
22
|
+
|
|
23
|
+
with open(self.md_files[file_index][0], 'r') as f:
|
|
24
|
+
a = f.read()
|
|
25
|
+
|
|
26
|
+
links = re.findall(r'\[\[(.*?)\]\]', a)
|
|
27
|
+
self.md_files[file_index][1] = links
|
|
28
|
+
|
|
29
|
+
def Make_Graph(self):
|
|
30
|
+
net = Network(directed=False, cdn_resources='remote')
|
|
31
|
+
|
|
32
|
+
for file_info in self.md_files:
|
|
33
|
+
file_path = file_info[0]
|
|
34
|
+
node_id = Path(file_path).stem
|
|
35
|
+
file_name = Path(file_path).name
|
|
36
|
+
net.add_node(node_id, label=file_name, title=file_name)
|
|
37
|
+
|
|
38
|
+
for file_info in self.md_files:
|
|
39
|
+
file_path = file_info[0]
|
|
40
|
+
links = file_info[1]
|
|
41
|
+
source_id = Path(file_path).stem
|
|
42
|
+
|
|
43
|
+
for link in links:
|
|
44
|
+
target_id = link.split("|")[0].strip()
|
|
45
|
+
if target_id not in net.get_nodes():
|
|
46
|
+
net.add_node(target_id, label=f"{target_id}.md", title=f"{target_id}.md", color="red")
|
|
47
|
+
net.add_edge(source_id, target_id)
|
|
48
|
+
|
|
49
|
+
temp_path = str(Path(tempfile.gettempdir()) / 'wiki_graph.html')
|
|
50
|
+
net.show(temp_path, notebook=False)
|
|
51
|
+
return temp_path
|
|
52
|
+
|
|
53
|
+
def main():
|
|
54
|
+
import sys
|
|
55
|
+
path = sys.argv[1] if len(sys.argv) > 1 else "."
|
|
56
|
+
reader = File_Reader(path)
|
|
57
|
+
|
|
58
|
+
for i in range(len(reader.md_files)):
|
|
59
|
+
reader.Read_file(i)
|
|
60
|
+
|
|
61
|
+
out_path = reader.Make_Graph()
|
|
62
|
+
print(out_path)
|
|
63
|
+
|
|
64
|
+
if __name__ == "__main__":
|
|
65
|
+
main()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wikilinksgraph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: pyvis
|
|
8
|
+
|
|
9
|
+
# Wiki-Links-Tree
|
|
10
|
+
Wiki Links Tree Maker, takes in a lot of md files that are interconnected with wiki links(Logseq or Obsidian DBs) and shows their structure
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
tests/test_main.py
|
|
4
|
+
wikilinksgraph/__init__.py
|
|
5
|
+
wikilinksgraph/main.py
|
|
6
|
+
wikilinksgraph.egg-info/PKG-INFO
|
|
7
|
+
wikilinksgraph.egg-info/SOURCES.txt
|
|
8
|
+
wikilinksgraph.egg-info/dependency_links.txt
|
|
9
|
+
wikilinksgraph.egg-info/entry_points.txt
|
|
10
|
+
wikilinksgraph.egg-info/requires.txt
|
|
11
|
+
wikilinksgraph.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyvis
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wikilinksgraph
|