wirez-py 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.
wires/__init__.py ADDED
@@ -0,0 +1,37 @@
1
+ """
2
+ wires — remember and retrieve file paths by name.
3
+ """
4
+
5
+ from .registry import save, remember, get, recall, remove, list_all, path
6
+ from .debug import enable_debug, enable_warnings
7
+
8
+ __all__ = [
9
+ "save", "remember",
10
+ "get", "recall",
11
+ "remove", "list_all", "path",
12
+ "enable_debug", "enable_warnings",
13
+ ]
14
+
15
+ print(r"""
16
+ _____ _____ _____ _____ _____
17
+ /\ \ /\ \ /\ \ /\ \ /\ \
18
+ /::\____\ /::\ \ /::\ \ /::\ \ /::\ \
19
+ /:::/ / \:::\ \ /::::\ \ /::::\ \ /::::\ \
20
+ /:::/ _/___ \:::\ \ /::::::\ \ /::::::\ \ /::::::\ \
21
+ /:::/ /\ \ \:::\ \ /:::/\:::\ \ /:::/\:::\ \ /:::/\:::\ \
22
+ /:::/ /::\____\ \:::\ \ /:::/__\:::\ \ /:::/__\:::\ \ /:::/__\:::\ \
23
+ /:::/ /:::/ / /::::\ \ /::::\ \:::\ \ /::::\ \:::\ \ \:::\ \:::\ \
24
+ /:::/ /:::/ _/___ ____ /::::::\ \ /::::::\ \:::\ \ /::::::\ \:::\ \ ___\:::\ \:::\ \
25
+ /:::/___/:::/ /\ \ /\ \ /:::/\:::\ \ /:::/\:::\ \:::\____\ /:::/\:::\ \:::\ \ /\ \:::\ \:::\ \
26
+ |:::| /:::/ /::\____\/::\ \/:::/ \:::\____\/:::/ \:::\ \:::| |/:::/__\:::\ \:::\____\/::\ \:::\ \:::\____\
27
+ |:::|__/:::/ /:::/ /\:::\ /:::/ \::/ /\::/ |::::\ /:::|____|\:::\ \:::\ \::/ /\:::\ \:::\ \::/ /
28
+ \:::\/:::/ /:::/ / \:::\/:::/ / \/____/ \/____|:::::\/:::/ / \:::\ \:::\ \/____/ \:::\ \:::\ \/____/
29
+ \::::::/ /:::/ / \::::::/ / |:::::::::/ / \:::\ \:::\ \ \:::\ \:::\ \
30
+ \::::/___/:::/ / \::::/____/ |::|\::::/ / \:::\ \:::\____\ \:::\ \:::\____\
31
+ \:::\__/:::/ / \:::\ \ |::| \::/____/ \:::\ \::/ / \:::\ /:::/ /
32
+ \::::::::/ / \:::\ \ |::| ~| \:::\ \/____/ \:::\/:::/ /
33
+ \::::::/ / \:::\ \ |::| | \:::\ \ \::::::/ /
34
+ \::::/ / \:::\____\ \::| | \:::\____\ \::::/ /
35
+ \::/____/ \::/ / \:| | \::/ / \::/ /
36
+ ~~ \/____/ \|___| \/____/ \/____/
37
+ """)
wires/debug.py ADDED
@@ -0,0 +1,47 @@
1
+ import os
2
+ import sys
3
+
4
+ _debug_enabled = False
5
+ _warn_enabled = True
6
+
7
+ RESET = "\033[0m"
8
+ YELLOW = "\033[93m"
9
+ RED = "\033[91m"
10
+ CYAN = "\033[96m"
11
+ GREEN = "\033[92m"
12
+ BOLD = "\033[1m"
13
+
14
+ _SUPPORTS_COLOR = hasattr(sys.stdout, "isatty") and sys.stdout.isatty()
15
+
16
+
17
+ def _color(code: str, text: str) -> str:
18
+ return f"{code}{text}{RESET}" if _SUPPORTS_COLOR else text
19
+
20
+
21
+ def enable_debug(on: bool = True) -> None:
22
+ global _debug_enabled
23
+ _debug_enabled = on
24
+
25
+
26
+ def enable_warnings(on: bool = True) -> None:
27
+ global _warn_enabled
28
+ _warn_enabled = on
29
+
30
+
31
+ def log(msg: str) -> None:
32
+ if _debug_enabled:
33
+ print(_color(CYAN, f"[wires debug] {msg}"), file=sys.stderr)
34
+
35
+
36
+ def warn(msg: str) -> None:
37
+ if _warn_enabled:
38
+ print(_color(YELLOW, f"[wires warn] {msg}"), file=sys.stderr)
39
+
40
+
41
+ def error(msg: str) -> None:
42
+ print(_color(RED, f"[wires error] {msg}"), file=sys.stderr)
43
+
44
+
45
+ def ok(msg: str) -> None:
46
+ if _debug_enabled:
47
+ print(_color(GREEN, f"[wires ok] {msg}"), file=sys.stderr)
wires/registry.py ADDED
@@ -0,0 +1,94 @@
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+ from . import debug as _dbg
5
+
6
+ _REGISTRY_DIR = Path.home() / ".wires"
7
+ _REGISTRY_FILE = _REGISTRY_DIR / "registry.json"
8
+
9
+
10
+ def _load() -> dict:
11
+ if not _REGISTRY_FILE.exists():
12
+ _dbg.log(f"Registry not found at {_REGISTRY_FILE}, starting empty")
13
+ return {}
14
+ with open(_REGISTRY_FILE, "r", encoding="utf-8") as f:
15
+ data = json.load(f)
16
+ _dbg.log(f"Loaded registry ({len(data)} entries)")
17
+ return data
18
+
19
+
20
+ def _dump(data: dict) -> None:
21
+ _REGISTRY_DIR.mkdir(parents=True, exist_ok=True)
22
+ with open(_REGISTRY_FILE, "w", encoding="utf-8") as f:
23
+ json.dump(data, f, indent=2)
24
+ _dbg.log(f"Registry saved to {_REGISTRY_FILE}")
25
+
26
+
27
+ def save(name: str, file_path: str | os.PathLike) -> None:
28
+ """Register a file path under a name."""
29
+ resolved = str(Path(file_path).resolve())
30
+
31
+ data = _load()
32
+
33
+ if name in data:
34
+ _dbg.warn(f"'{name}' already exists ({data[name]}) — overwriting with {resolved}")
35
+ else:
36
+ _dbg.log(f"Registering new wire: '{name}' → {resolved}")
37
+
38
+ if not Path(resolved).exists():
39
+ _dbg.warn(f"The file '{resolved}' does not exist on disk — saving path anyway")
40
+
41
+ data[name] = resolved
42
+ _dump(data)
43
+ _dbg.ok(f"Saved '{name}'")
44
+
45
+
46
+ # alias
47
+ remember = save
48
+
49
+
50
+ def get(name: str) -> str:
51
+ """Return the path string registered under name."""
52
+ data = _load()
53
+ if name not in data:
54
+ _dbg.error(f"No wire named '{name}' — available: {list(data.keys())}")
55
+ raise KeyError(f"No wire named '{name}'")
56
+
57
+ result = data[name]
58
+ _dbg.log(f"Retrieved '{name}' → {result}")
59
+
60
+ if not Path(result).exists():
61
+ _dbg.warn(f"Wire '{name}' points to '{result}' which no longer exists on disk")
62
+
63
+ return result
64
+
65
+
66
+ # alias
67
+ recall = get
68
+
69
+
70
+ def path(name: str) -> Path:
71
+ """Return the registered path as a pathlib.Path."""
72
+ return Path(get(name))
73
+
74
+
75
+ def remove(name: str) -> None:
76
+ """Unregister a name."""
77
+ data = _load()
78
+ if name not in data:
79
+ _dbg.error(f"Cannot remove '{name}' — not found. Available: {list(data.keys())}")
80
+ raise KeyError(f"No wire named '{name}'")
81
+ old = data.pop(name)
82
+ _dump(data)
83
+ _dbg.ok(f"Removed '{name}' (was → {old})")
84
+
85
+
86
+ def list_all() -> dict[str, str]:
87
+ """Return a copy of all registered name→path mappings."""
88
+ data = _load()
89
+ _dbg.log(f"Listing all wires: {list(data.keys())}")
90
+ # warn about any stale paths
91
+ for name, p in data.items():
92
+ if not Path(p).exists():
93
+ _dbg.warn(f"Stale wire: '{name}' → '{p}' (file not found)")
94
+ return dict(data)
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.4
2
+ Name: wirez-py
3
+ Version: 1.0.0
4
+ Summary: Remember and retrieve file paths by name — from any program, anywhere.
5
+ Author:
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/kulbir/wires
8
+ Keywords: files,path,registry,bookmark,wires
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ Dynamic: requires-python
15
+
16
+ # wires
17
+
18
+ **Remember and retrieve file paths by name — from any program, anywhere.**
19
+
20
+ ```
21
+ pip install wires
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Usage
27
+
28
+ ```python
29
+ import wires
30
+
31
+ # Save / remember a file
32
+ wires.save("my_config", "/path/to/config.json")
33
+ wires.remember("my_config", "/path/to/config.json") # same thing
34
+
35
+ # Retrieve it later — from any program
36
+ wires.get("my_config") # → "/path/to/config.json" (str)
37
+ wires.recall("my_config") # same thing
38
+ wires.path("my_config") # → pathlib.Path
39
+
40
+ # See all saved files
41
+ wires.list_all() # → {"my_config": "/path/to/config.json", ...}
42
+
43
+ # Remove
44
+ wires.remove("my_config")
45
+ ```
46
+
47
+ ## How it works
48
+
49
+ Wires stores all registrations in `~/.wires/registry.json`. Every program on the machine shares this registry, so a path saved in one script is instantly accessible in another.
50
+
51
+ ## License
52
+
53
+ MIT
@@ -0,0 +1,7 @@
1
+ wires/__init__.py,sha256=8zpWmVtsrs63k3iP4vmAPy4SzwGaJcHJZttg-RtwZRs,2866
2
+ wires/debug.py,sha256=PNoI34NxJcpeO4pPu4lSGa2zxb2iPrKXm1jb2JWj-6g,1015
3
+ wires/registry.py,sha256=7Sc5x4Fn2E5mRkolhfyMQwjaA4iYRtqHpyJaT5yYFKY,2621
4
+ wirez_py-1.0.0.dist-info/METADATA,sha256=tgWPSfa7_M16xb5siMAKY0r8cLZ-3pmIgzR-gOnM6dM,1370
5
+ wirez_py-1.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ wirez_py-1.0.0.dist-info/top_level.txt,sha256=GF8jMwKatrT-C_vDdmzM89edvYZqwprZaL_LqjL8n_Y,6
7
+ wirez_py-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ wires