vim/update.py: ran through black
for formatting
This commit is contained in:
parent
14a2eeca9e
commit
6013fe8f41
|
@ -31,17 +31,19 @@ import git
|
|||
log = logging.getLogger()
|
||||
|
||||
sh = logging.StreamHandler()
|
||||
formatter = logging.Formatter('%(name)s:%(levelname)s: %(message)s')
|
||||
formatter = logging.Formatter("%(name)s:%(levelname)s: %(message)s")
|
||||
sh.setFormatter(formatter)
|
||||
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"))
|
||||
sys.path.insert(
|
||||
0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
|
||||
)
|
||||
import pluginupdate
|
||||
from pluginupdate import run_nix_expr, PluginDesc
|
||||
|
||||
nvim_treesitter = importlib.import_module("treesitter")
|
||||
|
||||
|
||||
GET_PLUGINS_LUA = """
|
||||
|
@ -52,11 +54,12 @@ 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)
|
||||
|
@ -67,29 +70,38 @@ def isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
|
|||
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())
|
||||
nvim_treesitter_rev = pluginupdate.run_nix_expr("(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev")
|
||||
nvim_treesitter_rev = pluginupdate.run_nix_expr(
|
||||
"(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev"
|
||||
)
|
||||
|
||||
with open(outfile, "w+") as f:
|
||||
f.write(HEADER)
|
||||
f.write(textwrap.dedent("""
|
||||
f.write(
|
||||
textwrap.dedent(
|
||||
"""
|
||||
{ lib, buildVimPlugin, buildNeovimPlugin, fetchFromGitHub, fetchgit }:
|
||||
|
||||
final: prev:
|
||||
{
|
||||
"""
|
||||
))
|
||||
)
|
||||
)
|
||||
for pdesc, plugin in sorted_plugins:
|
||||
content = self.plugin2nix(pdesc, plugin)
|
||||
f.write(content)
|
||||
if plugin.name == "nvim-treesitter" and plugin.commit != nvim_treesitter_rev:
|
||||
if (
|
||||
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:
|
||||
|
||||
repo = pdesc.repo
|
||||
isNeovim = isNeovimPlugin(plugin)
|
||||
|
||||
|
@ -103,23 +115,30 @@ class VimEditor(pluginupdate.Editor):
|
|||
}};
|
||||
|
||||
""".format(
|
||||
buildFn="buildNeovimPlugin" if isNeovim else "buildVimPlugin", plugin=plugin, src_nix=src_nix, repo=repo)
|
||||
buildFn="buildNeovimPlugin" if isNeovim else "buildVimPlugin",
|
||||
plugin=plugin,
|
||||
src_nix=src_nix,
|
||||
repo=repo,
|
||||
)
|
||||
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")])
|
||||
# subprocess.check_call([nvim_treesitter_dir.joinpath("update.py")])
|
||||
nvim_treesitter.update_grammars()
|
||||
|
||||
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
|
||||
== "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"))])
|
||||
|
@ -129,7 +148,6 @@ class VimEditor(pluginupdate.Editor):
|
|||
|
||||
|
||||
def main():
|
||||
|
||||
global luaPlugins
|
||||
luaPlugins = run_nix_expr(GET_PLUGINS_LUA)
|
||||
|
||||
|
|
Loading…
Reference in a new issue