2021-02-20 10:12:21 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
2021-09-03 16:50:36 +02:00
|
|
|
#!nix-shell update-shell.nix -i python3
|
|
|
|
|
2021-02-20 10:12:21 +01:00
|
|
|
|
|
|
|
# format:
|
|
|
|
# $ nix run nixpkgs.python3Packages.black -c black update.py
|
|
|
|
# type-check:
|
|
|
|
# $ nix run nixpkgs.python3Packages.mypy -c mypy update.py
|
|
|
|
# linted:
|
|
|
|
# $ nix run nixpkgs.python3Packages.flake8 -c flake8 --ignore E501,E265,E402 update.py
|
|
|
|
|
2021-08-31 13:36:11 +02:00
|
|
|
# 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
|
|
|
|
|
2021-02-20 10:12:21 +01:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
2021-07-30 02:25:15 +02:00
|
|
|
import logging
|
|
|
|
import textwrap
|
2021-02-20 10:12:21 +01:00
|
|
|
from typing import List, Tuple
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-07-30 02:25:15 +02:00
|
|
|
log = logging.getLogger()
|
|
|
|
log.addHandler(logging.StreamHandler())
|
|
|
|
|
2021-02-20 10:12:21 +01:00
|
|
|
# Import plugin update library from maintainers/scripts/pluginupdate.py
|
|
|
|
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
|
|
|
|
sys.path.insert(0, os.path.join(ROOT.parent.parent.parent, "maintainers", "scripts"))
|
|
|
|
import pluginupdate
|
|
|
|
|
|
|
|
GET_PLUGINS = f"""(with import <localpkgs> {{}};
|
|
|
|
let
|
|
|
|
inherit (vimUtils.override {{inherit vim;}}) buildVimPluginFrom2Nix;
|
|
|
|
generated = callPackage {ROOT}/generated.nix {{
|
|
|
|
inherit buildVimPluginFrom2Nix;
|
|
|
|
}};
|
|
|
|
hasChecksum = value: lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value;
|
|
|
|
getChecksum = name: value:
|
|
|
|
if hasChecksum value then {{
|
|
|
|
submodules = value.src.fetchSubmodules or false;
|
|
|
|
sha256 = value.src.outputHash;
|
|
|
|
rev = value.src.rev;
|
|
|
|
}} else null;
|
|
|
|
checksums = lib.mapAttrs getChecksum generated;
|
|
|
|
in lib.filterAttrs (n: v: v != null) checksums)"""
|
|
|
|
|
|
|
|
HEADER = (
|
|
|
|
"# This file has been generated by ./pkgs/misc/vim-plugins/update.py. Do not edit!"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-30 02:25:15 +02:00
|
|
|
class VimEditor(pluginupdate.Editor):
|
2022-01-11 00:20:52 +01:00
|
|
|
def generate_nix(self, plugins: List[Tuple[pluginupdate.PluginDesc, pluginupdate.Plugin]], outfile: str):
|
|
|
|
sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower())
|
2021-07-30 02:25:15 +02:00
|
|
|
|
|
|
|
with open(outfile, "w+") as f:
|
|
|
|
f.write(HEADER)
|
|
|
|
f.write(textwrap.dedent("""
|
2022-01-11 00:20:52 +01:00
|
|
|
{ lib, buildVimPluginFrom2Nix, fetchFromGitHub, fetchgit }:
|
2021-07-30 02:25:15 +02:00
|
|
|
|
|
|
|
final: prev:
|
|
|
|
{"""
|
|
|
|
))
|
2022-01-11 00:20:52 +01:00
|
|
|
for pdesc, plugin in sorted_plugins:
|
2021-07-30 02:25:15 +02:00
|
|
|
|
2022-01-11 00:20:52 +01:00
|
|
|
repo = pdesc.repo
|
|
|
|
src_nix = repo.as_nix(plugin)
|
|
|
|
f.write(
|
2021-07-30 02:25:15 +02:00
|
|
|
f"""
|
2021-08-14 18:19:00 +02:00
|
|
|
{plugin.normalized_name} = buildVimPluginFrom2Nix {{
|
2021-08-30 02:05:12 +02:00
|
|
|
pname = "{plugin.name}";
|
2021-08-14 18:19:00 +02:00
|
|
|
version = "{plugin.version}";
|
2022-01-11 00:20:52 +01:00
|
|
|
src = {src_nix};
|
|
|
|
meta.homepage = "{repo.uri}";
|
2021-08-14 18:19:00 +02:00
|
|
|
}};
|
|
|
|
"""
|
2022-01-11 00:20:52 +01:00
|
|
|
)
|
2021-08-14 18:19:00 +02:00
|
|
|
f.write("\n}\n")
|
2021-07-30 02:25:15 +02:00
|
|
|
print(f"updated {outfile}")
|
|
|
|
|
2021-02-20 10:12:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-07-30 02:25:15 +02:00
|
|
|
editor = VimEditor("vim", ROOT, GET_PLUGINS)
|
|
|
|
parser = editor.create_parser()
|
|
|
|
args = parser.parse_args()
|
|
|
|
pluginupdate.update_plugins(editor, args)
|
2021-02-20 10:12:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|