1#!/usr/bin/env nix-shell
2#!nix-shell update-shell.nix -i python3
3
4# format:
5# $ nix run nixpkgs#python3Packages.ruff -- update.py
6# type-check:
7# $ nix run nixpkgs#python3Packages.mypy -- update.py
8# linted:
9# $ nix run nixpkgs#python3Packages.flake8 -- --ignore E501,E265,E402 update.py
10
11import inspect
12import os
13import sys
14from pathlib import Path
15
16# Import plugin update library from maintainers/scripts/pluginupdate.py
17ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) # type: ignore
18sys.path.insert(
19 0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
20)
21import pluginupdate
22
23GET_PLUGINS = f"""with import <localpkgs> {{ }};
24let
25 inherit (kakouneUtils.override {{ }}) buildKakounePluginFrom2Nix;
26 generated = callPackage {ROOT}/generated.nix {{ inherit buildKakounePluginFrom2Nix; }};
27
28 hasChecksum =
29 value:
30 lib.isAttrs value
31 && lib.hasAttrByPath [
32 "src"
33 "outputHash"
34 ] value;
35
36 parse = name: value: {{
37 pname = value.pname;
38 version = value.version;
39 homePage = value.meta.homepage;
40 checksum =
41 if hasChecksum value then
42 {{
43 submodules = value.src.fetchSubmodules or false;
44 sha256 = value.src.outputHash;
45 rev = value.src.rev;
46 }}
47 else
48 null;
49 }};
50in
51lib.mapAttrs parse generated"""
52
53HEADER = "# This file has been @generated by ./pkgs/applications/editors/kakoune/plugins/update.py. Do not edit!"
54
55
56class KakouneEditor(pluginupdate.Editor):
57 def generate_nix(
58 self,
59 plugins: list[tuple[pluginupdate.PluginDesc, pluginupdate.Plugin]],
60 outfile: str,
61 ):
62 with open(outfile, "w+") as f:
63 f.write(HEADER)
64 f.write(
65 """
66{ lib, buildKakounePluginFrom2Nix, fetchFromGitHub, overrides ? (self: super: {}) }:
67let
68packages = ( self:
69{"""
70 )
71 for pluginDesc, plugin in plugins:
72 f.write(
73 f"""
74 {plugin.normalized_name} = buildKakounePluginFrom2Nix {{
75 pname = "{plugin.normalized_name}";
76 version = "{plugin.version}";
77 src = {pluginDesc.repo.as_nix(plugin)};
78 meta.homepage = "{pluginDesc.repo.url("")}";
79 }};
80"""
81 )
82 f.write(
83 """
84});
85in lib.fix' (lib.extends overrides packages)
86"""
87 )
88 print(f"updated {outfile}")
89
90 def update(self, args):
91 pluginupdate.update_plugins(self, args)
92
93
94def main():
95 editor = KakouneEditor("kakoune", ROOT, GET_PLUGINS)
96 editor.run()
97
98
99if __name__ == "__main__":
100 main()