at 21.11-pre 2.6 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -p nix-prefetch-git -p python3 -p python3Packages.GitPython nix -i python3 3 4# format: 5# $ nix run nixpkgs.python3Packages.black -c black update.py 6# type-check: 7# $ nix run nixpkgs.python3Packages.mypy -c mypy update.py 8# linted: 9# $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265,E402 update.py 10 11import inspect 12import os 13import sys 14from typing import List, Tuple 15from pathlib import Path 16 17# Import plugin update library from maintainers/scripts/pluginupdate.py 18ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) 19sys.path.insert(0, os.path.join(ROOT.parent.parent.parent, "maintainers", "scripts")) 20import pluginupdate 21 22GET_PLUGINS = f"""(with import <localpkgs> {{}}; 23let 24 inherit (vimUtils.override {{inherit vim;}}) buildVimPluginFrom2Nix; 25 generated = callPackage {ROOT}/generated.nix {{ 26 inherit buildVimPluginFrom2Nix; 27 }}; 28 hasChecksum = value: lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value; 29 getChecksum = name: value: 30 if hasChecksum value then {{ 31 submodules = value.src.fetchSubmodules or false; 32 sha256 = value.src.outputHash; 33 rev = value.src.rev; 34 }} else null; 35 checksums = lib.mapAttrs getChecksum generated; 36in lib.filterAttrs (n: v: v != null) checksums)""" 37 38HEADER = ( 39 "# This file has been generated by ./pkgs/misc/vim-plugins/update.py. Do not edit!" 40) 41 42 43def generate_nix(plugins: List[Tuple[str, str, pluginupdate.Plugin]], outfile: str): 44 sorted_plugins = sorted(plugins, key=lambda v: v[2].name.lower()) 45 46 with open(outfile, "w+") as f: 47 f.write(HEADER) 48 f.write( 49 """ 50{ lib, buildVimPluginFrom2Nix, fetchFromGitHub }: 51 52final: prev: 53{""" 54 ) 55 for owner, repo, plugin in sorted_plugins: 56 if plugin.has_submodules: 57 submodule_attr = "\n fetchSubmodules = true;" 58 else: 59 submodule_attr = "" 60 61 f.write( 62 f""" 63 {plugin.normalized_name} = buildVimPluginFrom2Nix {{ 64 pname = "{plugin.normalized_name}"; 65 version = "{plugin.version}"; 66 src = fetchFromGitHub {{ 67 owner = "{owner}"; 68 repo = "{repo}"; 69 rev = "{plugin.commit}"; 70 sha256 = "{plugin.sha256}";{submodule_attr} 71 }}; 72 meta.homepage = "https://github.com/{owner}/{repo}/"; 73 }}; 74""" 75 ) 76 f.write( 77 """ 78} 79""" 80 ) 81 print(f"updated {outfile}") 82 83 84def main(): 85 editor = pluginupdate.Editor("vim", ROOT, GET_PLUGINS, generate_nix) 86 pluginupdate.update_plugins(editor) 87 88 89if __name__ == "__main__": 90 main()