This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

skills.hedgedoc: speed up pad edit by replacing nix shell with PYTHONPATH

Use `nix build --print-out-paths` + PYTHONPATH instead of `nix shell`
for the websocket-client bootstrap. Caches the store path in /tmp.
Goes from 30s+ to under 1s.

+28 -13
+28 -13
skills/hedgedoc/pad-edit.py
··· 12 12 import subprocess 13 13 import os 14 14 15 - # Bootstrap: re-exec under nix shell with websocket-client 16 - os.execvp( 17 - "nix", 18 - [ 19 - "nix", 20 - "shell", 21 - "nixpkgs#python3Packages.websocket-client", 22 - "-c", 23 - "python3", 24 - __file__, 25 - ] 26 - + sys.argv[1:], 27 - ) 15 + # Bootstrap: get the store path for websocket-client and re-exec with PYTHONPATH. 16 + # Much faster than `nix shell` which sets up a full environment. 17 + # Cache the store path in /tmp so subsequent runs skip nix entirely. 18 + cache = "/tmp/.pad-edit-websocket-path" 19 + store_path = None 20 + if os.path.exists(cache): 21 + store_path = open(cache).read().strip() 22 + if not os.path.exists(store_path): 23 + store_path = None 24 + 25 + if not store_path: 26 + store_path = subprocess.check_output( 27 + ["nix", "build", "nixpkgs#python3Packages.websocket-client", 28 + "--no-link", "--print-out-paths"], 29 + text=True, 30 + ).strip() 31 + open(cache, "w").write(store_path) 32 + 33 + # Find the site-packages dir inside the store path 34 + import glob 35 + site_dirs = glob.glob(f"{store_path}/lib/python*/site-packages") 36 + if not site_dirs: 37 + print("ERROR: Could not find site-packages in websocket-client store path", file=sys.stderr) 38 + sys.exit(1) 39 + 40 + env = os.environ.copy() 41 + env["PYTHONPATH"] = site_dirs[0] + (":" + env["PYTHONPATH"] if "PYTHONPATH" in env else "") 42 + os.execve(sys.executable, [sys.executable, __file__] + sys.argv[1:], env) 28 43 29 44 HEDGEDOC_URL = "https://pad.lassul.us" 30 45