anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / editors / kakoune / plugins / update.py
blob333c96807dd4ce084424fd599c0c861a5b0f3d09
1 #!/usr/bin/env nix-shell
2 #!nix-shell update-shell.nix -i python3
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
11 import inspect
12 import os
13 import sys
14 from pathlib import Path
15 from typing import List, Tuple
17 # Import plugin update library from maintainers/scripts/pluginupdate.py
18 ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) # type: ignore
19 sys.path.insert(
20 0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
22 import pluginupdate
24 GET_PLUGINS = f"""(
25 with import <localpkgs> {{ }};
26 let
27 inherit (kakouneUtils.override {{ }}) buildKakounePluginFrom2Nix;
28 generated = callPackage {ROOT}/generated.nix {{
29 inherit buildKakounePluginFrom2Nix;
30 }};
31 hasChecksum =
32 value:
33 lib.isAttrs value
34 && lib.hasAttrByPath [
35 "src"
36 "outputHash"
37 ] value;
38 getChecksum =
39 name: value:
40 if hasChecksum value then
42 submodules = value.src.fetchSubmodules or false;
43 sha256 = value.src.outputHash;
44 rev = value.src.rev;
46 else
47 null;
48 checksums = lib.mapAttrs getChecksum generated;
50 lib.filterAttrs (n: v: v != null) checksums
51 )"""
53 HEADER = "# This file has been @generated by ./pkgs/applications/editors/kakoune/plugins/update.py. Do not edit!"
56 class KakouneEditor(pluginupdate.Editor):
57 def generate_nix(
58 self,
59 plugins: List[Tuple[pluginupdate.PluginDesc, pluginupdate.Plugin]],
60 outfile: str,
62 with open(outfile, "w+") as f:
63 f.write(HEADER)
64 f.write(
65 """
66 { lib, buildKakounePluginFrom2Nix, fetchFromGitHub, overrides ? (self: super: {}) }:
67 let
68 packages = ( self:
69 {"""
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 """
82 f.write(
83 """
84 });
85 in lib.fix' (lib.extends overrides packages)
86 """
88 print(f"updated {outfile}")
90 def update(self, args):
91 pluginupdate.update_plugins(self, args)
94 def main():
95 editor = KakouneEditor("kakoune", ROOT, GET_PLUGINS)
96 editor.run()
99 if __name__ == "__main__":
100 main()