Merge pull request #199553 from figsoda/nvim-treesitter

vimPlugins: also update nvim-treesitter grammars in the update script
This commit is contained in:
figsoda 2022-11-08 15:32:27 -05:00 committed by GitHub
commit 29b89141bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View file

@ -342,6 +342,7 @@ class Editor:
self.default_out = default_out or root.joinpath("generated.nix") self.default_out = default_out or root.joinpath("generated.nix")
self.deprecated = deprecated or root.joinpath("deprecated.json") self.deprecated = deprecated or root.joinpath("deprecated.json")
self.cache_file = cache_file or f"{name}-plugin-cache.json" self.cache_file = cache_file or f"{name}-plugin-cache.json"
self.nixpkgs_repo = None
def get_current_plugins(self) -> List[Plugin]: def get_current_plugins(self) -> List[Plugin]:
"""To fill the cache""" """To fill the cache"""
@ -670,16 +671,15 @@ def update_plugins(editor: Editor, args):
autocommit = not args.no_commit autocommit = not args.no_commit
nixpkgs_repo = None
if autocommit: if autocommit:
nixpkgs_repo = git.Repo(editor.root, search_parent_directories=True) editor.nixpkgs_repo = git.Repo(editor.root, search_parent_directories=True)
commit(nixpkgs_repo, f"{editor.attr_path}: update", [args.outfile]) commit(editor.nixpkgs_repo, f"{editor.attr_path}: update", [args.outfile])
if redirects: if redirects:
update() update()
if autocommit: if autocommit:
commit( commit(
nixpkgs_repo, editor.nixpkgs_repo,
f"{editor.attr_path}: resolve github repository redirects", f"{editor.attr_path}: resolve github repository redirects",
[args.outfile, args.input_file, editor.deprecated], [args.outfile, args.input_file, editor.deprecated],
) )
@ -692,7 +692,7 @@ def update_plugins(editor: Editor, args):
plugin, _ = prefetch_plugin(pdesc, ) plugin, _ = prefetch_plugin(pdesc, )
if autocommit: if autocommit:
commit( commit(
nixpkgs_repo, editor.nixpkgs_repo,
"{drv_name}: init at {version}".format( "{drv_name}: init at {version}".format(
drv_name=editor.get_drv_name(plugin.normalized_name), drv_name=editor.get_drv_name(plugin.normalized_name),
version=plugin.version version=plugin.version

View file

@ -21,10 +21,13 @@ import inspect
import os import os
import sys import sys
import logging import logging
import subprocess
import textwrap import textwrap
from typing import List, Tuple from typing import List, Tuple
from pathlib import Path from pathlib import Path
import git
log = logging.getLogger() log = logging.getLogger()
sh = logging.StreamHandler() sh = logging.StreamHandler()
@ -76,8 +79,11 @@ def isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
class VimEditor(pluginupdate.Editor): class VimEditor(pluginupdate.Editor):
nvim_treesitter_updated = False
def generate_nix(self, plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], outfile: str): def generate_nix(self, plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], outfile: str):
sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower()) 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")
with open(outfile, "w+") as f: with open(outfile, "w+") as f:
f.write(HEADER) f.write(HEADER)
@ -91,6 +97,8 @@ class VimEditor(pluginupdate.Editor):
for pdesc, plugin in sorted_plugins: for pdesc, plugin in sorted_plugins:
content = self.plugin2nix(pdesc, plugin) content = self.plugin2nix(pdesc, plugin)
f.write(content) f.write(content)
if plugin.name == "nvim-treesitter" and plugin.commit != nvim_treesitter_rev:
self.nvim_treesitter_updated = True
f.write("\n}\n") f.write("\n}\n")
print(f"updated {outfile}") print(f"updated {outfile}")
@ -123,6 +131,18 @@ def main():
args = parser.parse_args() args = parser.parse_args()
pluginupdate.update_plugins(editor, 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:
msg = "vimPlugins.nvim-treesitter: update grammars"
print(f"committing to nixpkgs: {msg}")
index = editor.nixpkgs_repo.index
index.add([str(nvim_treesitter_dir.joinpath("generated.nix"))])
index.commit(msg)
if __name__ == "__main__": if __name__ == "__main__":
main() main()