From 351cec5db3b7ca839779316a8b7c524ea8941f0f Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 14 Apr 2023 22:02:17 +0200 Subject: use subcommands in plugin updaters (#223164) * update.py: introduce subparsers for plugin updaters This is preliminary work to help create more powerful plugin updaters. Namely I would like to be able to "just add" plugins without refreshing the older ones (helpful when github temporarily removes a user from github due to automated bot detection). Also concerning the lua updater, we pin some of the dependencies, and I would like to be able to unpin the package without editing the csv (coming in later PRs). * doc/updaters: update command to update editor plugins including vim, kakoune and lua packages Co-authored-by: figsoda --- pkgs/applications/editors/vim/plugins/update.py | 63 +++++++++++-------------- 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'pkgs/applications/editors/vim/plugins/update.py') diff --git a/pkgs/applications/editors/vim/plugins/update.py b/pkgs/applications/editors/vim/plugins/update.py index 20336c66ed6ec..09606634f9e53 100755 --- a/pkgs/applications/editors/vim/plugins/update.py +++ b/pkgs/applications/editors/vim/plugins/update.py @@ -42,28 +42,14 @@ sys.path.insert(0, os.path.join(ROOT.parent.parent.parent.parent.parent, "mainta import pluginupdate from pluginupdate import run_nix_expr, PluginDesc -GET_PLUGINS = f"""(with import {{}}; -let - inherit (vimUtils.override {{inherit vim;}}) buildNeovimPluginFrom2Nix buildVimPluginFrom2Nix; - generated = callPackage {ROOT}/generated.nix {{ - inherit buildNeovimPluginFrom2Nix buildVimPluginFrom2Nix; - }}; - hasChecksum = value: lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value; - getChecksum = name: value: - if hasChecksum value then {{ - submodules = value.src.fetchSubmodules or false; - sha256 = value.src.outputHash; - rev = value.src.rev; - }} else null; - checksums = lib.mapAttrs getChecksum generated; -in lib.filterAttrs (n: v: v != null) checksums)""" + GET_PLUGINS_LUA = """ with import {}; lib.attrNames lua51Packages""" HEADER = ( - "# This file has been generated by ./pkgs/applications/editors/vim/plugins/update.py. Do not edit!" + "# GENERATED by ./pkgs/applications/editors/vim/plugins/update.py. Do not edit!" ) def isNeovimPlugin(plug: pluginupdate.Plugin) -> bool: @@ -118,34 +104,39 @@ class VimEditor(pluginupdate.Editor): """.format( buildFn="buildNeovimPluginFrom2Nix" if isNeovim else "buildVimPluginFrom2Nix", plugin=plugin, src_nix=src_nix, repo=repo) - print(content) + log.debug(content) return content + + def update(self, args): + pluginupdate.update_plugins(self, args) + + if self.nvim_treesitter_updated: + print("updating nvim-treesitter grammars") + nvim_treesitter_dir = ROOT.joinpath("nvim-treesitter") + subprocess.check_call([nvim_treesitter_dir.joinpath("update.py")]) + + if self.nixpkgs_repo: + index = self.nixpkgs_repo.index + for diff in index.diff(None): + if diff.a_path == "pkgs/applications/editors/vim/plugins/nvim-treesitter/generated.nix": + msg = "vimPlugins.nvim-treesitter: update grammars" + print(f"committing to nixpkgs: {msg}") + index.add([str(nvim_treesitter_dir.joinpath("generated.nix"))]) + index.commit(msg) + return + print("no updates to nvim-treesitter grammars") + + def main(): global luaPlugins luaPlugins = run_nix_expr(GET_PLUGINS_LUA) + with open(f"{ROOT}/get-plugins.nix") as f: + GET_PLUGINS = f.read() editor = VimEditor("vim", ROOT, GET_PLUGINS) - parser = editor.create_parser() - args = parser.parse_args() - pluginupdate.update_plugins(editor, args) - - if editor.nvim_treesitter_updated: - print("updating nvim-treesitter grammars") - nvim_treesitter_dir = ROOT.joinpath("nvim-treesitter") - subprocess.check_call([nvim_treesitter_dir.joinpath("update.py")]) - - if editor.nixpkgs_repo: - index = editor.nixpkgs_repo.index - for diff in index.diff(None): - if diff.a_path == "pkgs/applications/editors/vim/plugins/nvim-treesitter/generated.nix": - msg = "vimPlugins.nvim-treesitter: update grammars" - print(f"committing to nixpkgs: {msg}") - index.add([str(nvim_treesitter_dir.joinpath("generated.nix"))]) - index.commit(msg) - return - print("no updates to nvim-treesitter grammars") + editor.run() if __name__ == "__main__": -- cgit 1.4.1