jnv: 0.4.2 -> 0.5.0 (#371655)
[NixPkgs.git] / pkgs / applications / editors / kakoune / plugins / update.py
blob9b06d0c06e9c80e2b1eb20236b7ec5ea3a9ba96c
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
16 # Import plugin update library from maintainers/scripts/pluginupdate.py
17 ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) # type: ignore
18 sys.path.insert(
19 0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
21 import pluginupdate
23 GET_PLUGINS = f"""with import <localpkgs> {{ }};
24 let
25 inherit (kakouneUtils.override {{ }}) buildKakounePluginFrom2Nix;
26 generated = callPackage {ROOT}/generated.nix {{ inherit buildKakounePluginFrom2Nix; }};
28 hasChecksum =
29 value:
30 lib.isAttrs value
31 && lib.hasAttrByPath [
32 "src"
33 "outputHash"
34 ] value;
36 parse = name: value: {{
37 pname = value.pname;
38 version = value.version;
39 homePage = value.meta.homepage;
40 checksum =
41 if hasChecksum value then
43 submodules = value.src.fetchSubmodules or false;
44 sha256 = value.src.outputHash;
45 rev = value.src.rev;
47 else
48 null;
49 }};
51 lib.mapAttrs parse generated"""
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()