vimPluginsUpdater: make development easier

`nix develop .#vimPluginsUpdater` now lets you enter a shell where you
can run `pkgs/applications/editors/vim/plugins/update.py` and
iteratively develop !

- removed `warn` warning from python by using `warning` instead
- `plugin2nix` was calling the same bit of code over and over thus
slowing down the generator by a lot

Changed files
+52 -36
maintainers
pkgs
applications
editors
vim
development
lua-modules
updater
maintainers/scripts/__init__.py

This is a binary file and will not be displayed.

+10 -4
maintainers/scripts/pluginupdate.py
··· 142 142 return loaded 143 143 144 144 def prefetch(self, ref: Optional[str]) -> str: 145 - print("Prefetching") 145 + print("Prefetching %s", self.uri) 146 146 loaded = self._prefetch(ref) 147 147 return loaded["sha256"] 148 148 ··· 266 266 267 267 @staticmethod 268 268 def load_from_csv(config: FetchConfig, row: Dict[str, str]) -> "PluginDesc": 269 + log.debug("Loading row %s", row) 269 270 branch = row["branch"] 270 271 repo = make_repo(row["repo"], branch.strip()) 271 272 repo.token = config.github_token ··· 328 329 329 330 330 331 331 - def run_nix_expr(expr, nixpkgs: str): 332 + def run_nix_expr(expr, nixpkgs: str, **args): 332 333 ''' 333 334 :param expr nix expression to fetch current plugins 334 335 :param nixpkgs Path towards a nixpkgs checkout ··· 347 348 nix_path, 348 349 ] 349 350 log.debug("Running command: %s", " ".join(cmd)) 350 - out = subprocess.check_output(cmd, timeout=90) 351 + out = subprocess.check_output(cmd, **args) 351 352 data = json.loads(out) 352 353 return data 353 354 ··· 736 737 redirects: Redirects = {}, 737 738 append: List[PluginDesc] = [], 738 739 ): 740 + log.info("Rewriting input file %s", input_file) 739 741 plugins = load_plugins_from_csv( 740 742 config, 741 743 input_file, ··· 744 746 plugins.extend(append) 745 747 746 748 if redirects: 749 + log.debug("Dealing with deprecated plugins listed in %s", deprecated) 750 + 747 751 cur_date_iso = datetime.now().strftime("%Y-%m-%d") 748 752 with open(deprecated, "r") as f: 749 753 deprecations = json.load(f) 754 + # TODO parallelize this step 750 755 for pdesc, new_repo in redirects.items(): 756 + log.info("Rewriting input file %s", input_file) 751 757 new_pdesc = PluginDesc(new_repo, pdesc.branch, pdesc.alias) 752 758 old_plugin, _ = prefetch_plugin(pdesc) 753 759 new_plugin, _ = prefetch_plugin(new_pdesc) ··· 791 797 start_time = time.time() 792 798 redirects = update() 793 799 duration = time.time() - start_time 794 - print(f"The plugin update took {duration}s.") 800 + print(f"The plugin update took {duration:.2f}s.") 795 801 editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, redirects) 796 802 797 803 autocommit = not args.no_commit
+32 -24
pkgs/applications/editors/vim/plugins/update.py
··· 40 40 import pluginupdate 41 41 import importlib 42 42 from pluginupdate import run_nix_expr, PluginDesc 43 - import treesitter 43 + 44 + treesitter = importlib.import_module('nvim-treesitter.update') 45 + 44 46 45 47 46 48 HEADER = ( ··· 54 56 nvim_treesitter_updated = False 55 57 56 58 def generate_nix( 57 - self, plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], outfile: str 59 + self, 60 + plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], 61 + outfile: str 58 62 ): 63 + log.info("Generating nix code") 59 64 sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower()) 65 + log.debug("Loading nvim-treesitter revision from nix...") 60 66 nvim_treesitter_rev = pluginupdate.run_nix_expr( 61 - "(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev", self.nixpkgs 67 + "(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev", 68 + self.nixpkgs, 69 + timeout=10 62 70 ) 63 71 72 + GET_PLUGINS_LUA = """ 73 + with import <localpkgs> {}; 74 + lib.attrNames lua51Packages""" 75 + log.debug("Loading list of lua plugins...") 76 + luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs, timeout=30) 77 + 78 + def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool: 79 + """ 80 + Whether it's a neovim-only plugin 81 + We can check if it's available in lua packages 82 + """ 83 + if plug.normalized_name in luaPlugins: 84 + log.debug("%s is a neovim plugin", plug) 85 + return True 86 + return False 87 + 64 88 with open(outfile, "w+") as f: 89 + log.debug("Writing to %s", outfile) 65 90 f.write(HEADER) 66 91 f.write( 67 92 textwrap.dedent( ··· 74 99 ) 75 100 ) 76 101 for pdesc, plugin in sorted_plugins: 77 - content = self.plugin2nix(pdesc, plugin) 102 + content = self.plugin2nix(pdesc, plugin, _isNeovimPlugin(plugin)) 78 103 f.write(content) 79 104 if ( 80 105 plugin.name == "nvim-treesitter" ··· 84 109 f.write("\n}\n") 85 110 print(f"updated {outfile}") 86 111 87 - def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin) -> str: 88 - GET_PLUGINS_LUA = """ 89 - with import <localpkgs> {}; 90 - lib.attrNames lua51Packages""" 91 - luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs) 112 + def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin, isNeovim: bool) -> str: 92 113 93 114 repo = pdesc.repo 94 - 95 - def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool: 96 - """ 97 - Whether it's a neovim-only plugin 98 - We can check if it's available in lua packages 99 - """ 100 - # global luaPlugins 101 - if plug.normalized_name in luaPlugins: 102 - log.debug("%s is a neovim plugin", plug) 103 - return True 104 - return False 105 - 106 - isNeovim = _isNeovimPlugin(plugin) 107 115 108 116 content = f" {plugin.normalized_name} = " 109 117 src_nix = repo.as_nix(plugin) ··· 159 167 def main(): 160 168 global luaPlugins 161 169 162 - log.debug(f"Loading from {ROOT}/../get-plugins.nix") 163 - with open(f"{ROOT}/../get-plugins.nix") as f: 170 + log.debug(f"Loading from {ROOT}/get-plugins.nix") 171 + with open(f"{ROOT}/get-plugins.nix") as f: 164 172 GET_PLUGINS = f.read() 165 173 editor = VimEditor( 166 174 "vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS
+9 -7
pkgs/applications/editors/vim/plugins/updater.nix
··· 7 7 , nurl 8 8 9 9 # optional 10 - , vimPlugins 11 - , neovim 10 + , neovim-unwrapped 12 11 }: 13 12 buildPythonApplication { 14 - format = "other"; 15 13 pname = "vim-plugins-updater"; 16 14 version = "0.1"; 15 + 16 + format = "other"; 17 17 18 18 nativeBuildInputs = [ 19 19 makeWrapper ··· 29 29 installPhase = '' 30 30 mkdir -p $out/bin $out/lib 31 31 cp ${./update.py} $out/bin/vim-plugins-updater 32 - cp ${./get-plugins.nix} $out/get-plugins.nix 33 - cp ${./nvim-treesitter/update.py} $out/lib/treesitter.py 34 - cp ${../../../../../maintainers/scripts/pluginupdate.py} $out/lib/pluginupdate.py 32 + cp ${./get-plugins.nix} $out/bin/get-plugins.nix 35 33 36 34 # wrap python scripts 37 35 makeWrapperArgs+=( --prefix PATH : "${lib.makeBinPath [ 38 - nix nix-prefetch-git neovim nurl ]}" --prefix PYTHONPATH : "$out/lib" ) 36 + nix nix-prefetch-git neovim-unwrapped nurl ]}" --prefix PYTHONPATH : "${./.}:${../../../../../maintainers/scripts}" ) 39 37 wrapPythonPrograms 40 38 ''; 39 + 40 + shellHook = '' 41 + export PYTHONPATH=pkgs/applications/editors/vim/plugins:maintainers/scripts:$PYTHONPATH 42 + ''; 41 43 42 44 meta.mainProgram = "vim-plugins-updater"; 43 45 }
+1 -1
pkgs/development/lua-modules/updater/updater.py
··· 177 177 "'version' and 'ref' will be ignored as the rockspec is hardcoded for package %s" 178 178 % plug.name 179 179 ) 180 - log.warn(msg) 180 + log.warning(msg) 181 181 182 182 log.debug("Updating from rockspec %s", plug.rockspec) 183 183 cmd.append(plug.rockspec)