2021-02-20 09:12:21 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2021-09-03 14:50:36 +00:00
|
|
|
#!nix-shell update-shell.nix -i python3
|
|
|
|
|
2021-02-20 09:12:21 +00: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 11:36:11 +00: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
|
2022-02-17 06:56:44 +00:00
|
|
|
#
|
|
|
|
# (or the equivalent file /doc/languages-frameworks/vim.section.md from Nixpkgs master tree).
|
|
|
|
#
|
2021-08-31 11:36:11 +00:00
|
|
|
|
2021-02-20 09:12:21 +00:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
import sys
|
2021-07-30 00:25:15 +00:00
|
|
|
import logging
|
|
|
|
import textwrap
|
2021-02-20 09:12:21 +00:00
|
|
|
from typing import List, Tuple
|
|
|
|
from pathlib import Path
|
|
|
|
|
2021-07-30 00:25:15 +00:00
|
|
|
log = logging.getLogger()
|
|
|
|
log.addHandler(logging.StreamHandler())
|
|
|
|
|
2021-02-20 09:12:21 +00:00
|
|
|
# Import plugin update library from maintainers/scripts/pluginupdate.py
|
|
|
|
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
|
2022-02-17 06:56:44 +00:00
|
|
|
# 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"))
|
2021-02-20 09:12:21 +00:00
|
|
|
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 = (
|
2022-02-16 14:55:43 +00:00
|
|
|
"# This file has been generated by ./pkgs/applications/editors/vim/plugins/update.py. Do not edit!"
|
2021-02-20 09:12:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-30 00:25:15 +00:00
|
|
|
class VimEditor(pluginupdate.Editor):
|
2022-01-10 23:20:52 +00: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 00:25:15 +00:00
|
|
|
|
|
|
|
with open(outfile, "w+") as f:
|
|
|
|
f.write(HEADER)
|
|
|
|
f.write(textwrap.dedent("""
|
2022-01-10 23:20:52 +00:00
|
|
|
{ lib, buildVimPluginFrom2Nix, fetchFromGitHub, fetchgit }:
|
2021-07-30 00:25:15 +00:00
|
|
|
|
|
|
|
final: prev:
|
|
|
|
{"""
|
|
|
|
))
|
2022-01-10 23:20:52 +00:00
|
|
|
for pdesc, plugin in sorted_plugins:
|
2021-07-30 00:25:15 +00:00
|
|
|
|
2022-01-10 23:20:52 +00:00
|
|
|
repo = pdesc.repo
|
|
|
|
src_nix = repo.as_nix(plugin)
|
|
|
|
f.write(
|
2021-07-30 00:25:15 +00:00
|
|
|
f"""
|
2021-08-14 16:19:00 +00:00
|
|
|
{plugin.normalized_name} = buildVimPluginFrom2Nix {{
|
2021-08-30 00:05:12 +00:00
|
|
|
pname = "{plugin.name}";
|
2021-08-14 16:19:00 +00:00
|
|
|
version = "{plugin.version}";
|
2022-01-10 23:20:52 +00:00
|
|
|
src = {src_nix};
|
|
|
|
meta.homepage = "{repo.uri}";
|
2021-08-14 16:19:00 +00:00
|
|
|
}};
|
|
|
|
"""
|
2022-01-10 23:20:52 +00:00
|
|
|
)
|
2021-08-14 16:19:00 +00:00
|
|
|
f.write("\n}\n")
|
2021-07-30 00:25:15 +00:00
|
|
|
print(f"updated {outfile}")
|
|
|
|
|
2021-02-20 09:12:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-07-30 00:25:15 +00:00
|
|
|
editor = VimEditor("vim", ROOT, GET_PLUGINS)
|
|
|
|
parser = editor.create_parser()
|
|
|
|
args = parser.parse_args()
|
|
|
|
pluginupdate.update_plugins(editor, args)
|
2021-02-20 09:12:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|