vimPluginsUpdater: init
The nixpkgs documentation mentions how to update out of tree plugins but one problem is that it requires a nixpkgs clone. This makes it more convenient. I've had the need to generate vim plugins and lua overlays for other projects unrelated to nix and this will make updates easier (aka just run `nix run nixpkgs#vimPluginsUpdater -- --proc=1` or with the legacy commands: `nix-shell -p vimPluginsUpdater --run vim-plugins-updater`. I added an optional "nixpkgs" argument to command line parser, which is the path towards a nixpkgs checkout. By default the current folder. update-luarocks-packages: format with black
This commit is contained in:
@@ -1,32 +1,31 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell update-shell.nix -i python3
|
||||
|
||||
#!/usr/bin/env python
|
||||
|
||||
# run with:
|
||||
# $ nix run .\#vimPluginsUpdater
|
||||
# format:
|
||||
# $ nix run nixpkgs.python3Packages.black -c black update.py
|
||||
# $ nix run nixpkgs#python3Packages.black -- update.py
|
||||
# type-check:
|
||||
# $ nix run nixpkgs.python3Packages.mypy -c mypy update.py
|
||||
# $ nix run nixpkgs#python3Packages.mypy -- update.py
|
||||
# linted:
|
||||
# $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265,E402 update.py
|
||||
# $ nix run nixpkgs#python3Packages.flake8 -- --ignore E501,E265,E402 update.py
|
||||
|
||||
# If you see `HTTP Error 429: too many requests` errors while running this script,
|
||||
# refer to:
|
||||
# If you see `HTTP Error 429: too many requests` errors while running this
|
||||
# script, refer to:
|
||||
#
|
||||
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/vim.section.md#updating-plugins-in-nixpkgs-updating-plugins-in-nixpkgs
|
||||
#
|
||||
# (or the equivalent file /doc/languages-frameworks/vim.section.md from Nixpkgs master tree).
|
||||
# (or the equivalent file /doc/languages-frameworks/vim.section.md
|
||||
# from Nixpkgs master tree).
|
||||
#
|
||||
|
||||
import inspect
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import subprocess
|
||||
import textwrap
|
||||
import json
|
||||
from typing import List, Tuple
|
||||
from pathlib import Path
|
||||
|
||||
import git
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
@@ -37,34 +36,18 @@ log.addHandler(sh)
|
||||
|
||||
# Import plugin update library from maintainers/scripts/pluginupdate.py
|
||||
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
|
||||
# Ideally, ROOT.(parent^5) points to root of Nixpkgs official tree
|
||||
sys.path.insert(
|
||||
0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
|
||||
)
|
||||
import pluginupdate
|
||||
import importlib
|
||||
from pluginupdate import run_nix_expr, PluginDesc
|
||||
nvim_treesitter = importlib.import_module("treesitter")
|
||||
from treesitter import update_grammars
|
||||
|
||||
|
||||
GET_PLUGINS_LUA = """
|
||||
with import <localpkgs> {};
|
||||
lib.attrNames lua51Packages"""
|
||||
|
||||
HEADER = (
|
||||
"# GENERATED by ./pkgs/applications/editors/vim/plugins/update.py. Do not edit!"
|
||||
)
|
||||
|
||||
|
||||
def isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
|
||||
"""
|
||||
Whether it's a neovim-only plugin
|
||||
We can check if it's available in lua packages
|
||||
"""
|
||||
global luaPlugins
|
||||
if plug.normalized_name in luaPlugins:
|
||||
log.debug("%s is a neovim plugin", plug)
|
||||
return True
|
||||
return False
|
||||
NVIM_TREESITTER_GENERATED_NIX = \
|
||||
"pkgs/applications/editors/vim/plugins/nvim-treesitter/generated.nix"
|
||||
|
||||
|
||||
class VimEditor(pluginupdate.Editor):
|
||||
@@ -75,7 +58,8 @@ 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"
|
||||
"(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev",
|
||||
self.nixpkgs
|
||||
)
|
||||
|
||||
with open(outfile, "w+") as f:
|
||||
@@ -94,16 +78,32 @@ 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")
|
||||
print(f"updated {outfile}")
|
||||
|
||||
def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin) -> str:
|
||||
GET_PLUGINS_LUA = """
|
||||
with import <localpkgs> {};
|
||||
lib.attrNames lua51Packages"""
|
||||
luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs)
|
||||
|
||||
repo = pdesc.repo
|
||||
isNeovim = isNeovimPlugin(plugin)
|
||||
|
||||
def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
|
||||
"""
|
||||
Whether it's a neovim-only plugin
|
||||
We can check if it's available in lua packages
|
||||
"""
|
||||
# global luaPlugins
|
||||
if plug.normalized_name in luaPlugins:
|
||||
log.debug("%s is a neovim plugin", plug)
|
||||
return True
|
||||
return False
|
||||
|
||||
isNeovim = _isNeovimPlugin(plugin)
|
||||
|
||||
content = f" {plugin.normalized_name} = "
|
||||
src_nix = repo.as_nix(plugin)
|
||||
@@ -129,16 +129,14 @@ class VimEditor(pluginupdate.Editor):
|
||||
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")])
|
||||
nvim_treesitter.update_grammars()
|
||||
lockfile = json.load(open(args.nixpkgs.join(NVIM_TREESITTER_GENERATED_FILE, "lockfile.json")))
|
||||
|
||||
nvim_treesitter.update_grammars(lockfile)
|
||||
|
||||
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"
|
||||
):
|
||||
if diff.a_path == 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"))])
|
||||
@@ -148,12 +146,13 @@ class VimEditor(pluginupdate.Editor):
|
||||
|
||||
|
||||
def main():
|
||||
global luaPlugins
|
||||
luaPlugins = run_nix_expr(GET_PLUGINS_LUA)
|
||||
|
||||
with open(f"{ROOT}/get-plugins.nix") as f:
|
||||
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", ROOT, GET_PLUGINS)
|
||||
editor = VimEditor("vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS)
|
||||
editor.run()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user