diff options
Diffstat (limited to 'pkgs/applications/editors/vim/plugins/update.py')
-rwxr-xr-x | pkgs/applications/editors/vim/plugins/update.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/pkgs/applications/editors/vim/plugins/update.py b/pkgs/applications/editors/vim/plugins/update.py index 438a231ec47..b658ca7e2bd 100755 --- a/pkgs/applications/editors/vim/plugins/update.py +++ b/pkgs/applications/editors/vim/plugins/update.py @@ -23,11 +23,12 @@ import os import logging import textwrap import json +import subprocess from typing import List, Tuple from pathlib import Path -log = logging.getLogger() +log = logging.getLogger("vim-updater") sh = logging.StreamHandler() formatter = logging.Formatter("%(name)s:%(levelname)s: %(message)s") @@ -39,15 +40,14 @@ ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe import pluginupdate import importlib from pluginupdate import run_nix_expr, PluginDesc -from treesitter import update_grammars +import treesitter HEADER = ( "# GENERATED by ./pkgs/applications/editors/vim/plugins/update.py. Do not edit!" ) -NIXPKGS_NVIMTREESITTER_FOLDER = \ - "pkgs/applications/editors/vim/plugins/nvim-treesitter/generated.nix" +NIXPKGS_NVIMTREESITTER_FOLDER = "pkgs/applications/editors/vim/plugins/nvim-treesitter" class VimEditor(pluginupdate.Editor): @@ -58,8 +58,7 @@ class VimEditor(pluginupdate.Editor): ): sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower()) nvim_treesitter_rev = pluginupdate.run_nix_expr( - "(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev", - self.nixpkgs + "(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev", self.nixpkgs ) with open(outfile, "w+") as f: @@ -78,7 +77,8 @@ class VimEditor(pluginupdate.Editor): content = self.plugin2nix(pdesc, plugin) f.write(content) if ( - plugin.name == "nvim-treesitter" and plugin.commit != nvim_treesitter_rev + plugin.name == "nvim-treesitter" + and plugin.commit != nvim_treesitter_rev ): self.nvim_treesitter_updated = True f.write("\n}\n") @@ -126,13 +126,19 @@ class VimEditor(pluginupdate.Editor): def update(self, args): pluginupdate.update_plugins(self, args) + # TODO this should probably be skipped when running outside a nixpkgs checkout if self.nvim_treesitter_updated: print("updating nvim-treesitter grammars") - nvim_treesitter_dir = ROOT.joinpath("nvim-treesitter") - lockfile = os.path.join(args.nixpkgs.join(NIXPKGS_NVIMTREESITTER_FOLDER, "lockfile.json")) - lockfile = json.load(open(lockfile)) + cmd = [ + "nix", "build", + "vimPlugins.nvim-treesitter.src", "-f", self.nixpkgs + , "--print-out-paths" + ] + log.debug("Running command: %s", " ".join(cmd)) + nvim_treesitter_dir = subprocess.check_output(cmd, text=True, timeout=90).strip() - nvim_treesitter.update_grammars(lockfile) + generated = treesitter.update_grammars(nvim_treesitter_dir) + open(os.path.join(args.nixpkgs, "generated.nix"), "w").write(generated) if self.nixpkgs_repo: index = self.nixpkgs_repo.index @@ -147,13 +153,14 @@ class VimEditor(pluginupdate.Editor): def main(): - global luaPlugins log.debug(f"Loading from {ROOT}/../get-plugins.nix") with open(f"{ROOT}/../get-plugins.nix") as f: GET_PLUGINS = f.read() - editor = VimEditor("vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS) + editor = VimEditor( + "vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS + ) editor.run() |