python313Packages.nixpkgs-plugin-update: init from maintainer script

We have machinery for Python packaging, so let’s make use of
it. This also helps unblock moving `by-name` overrides out of
`all-packages.nix`, as it was previously being used to work around
`nixpkgs-vet` forbidding the direct reference to the path.
This commit is contained in:
Emily
2025-10-20 19:32:57 +01:00
parent 3de337e9ed
commit 00c40f1069
13 changed files with 99 additions and 40 deletions
@@ -4,7 +4,7 @@
with pkgs;
let
pyEnv = python3.withPackages (ps: [ ps.gitpython ]);
pyEnv = python3.withPackages (ps: [ ps.nixpkgs-plugin-update ]);
in
mkShell {
@@ -13,12 +13,9 @@ import os
import sys
from pathlib import Path
# Import plugin update library from maintainers/scripts/pluginupdate.py
import nixpkgs_plugin_update
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) # type: ignore
sys.path.insert(
0, os.path.join(ROOT.parent.parent.parent.parent.parent, "maintainers", "scripts")
)
import pluginupdate
GET_PLUGINS = f"""with import <localpkgs> {{ }};
let
@@ -53,10 +50,10 @@ lib.mapAttrs parse generated"""
HEADER = "# This file has been @generated by ./pkgs/applications/editors/kakoune/plugins/update.py. Do not edit!"
class KakouneEditor(pluginupdate.Editor):
class KakouneEditor(nixpkgs_plugin_update.Editor):
def generate_nix(
self,
plugins: list[tuple[pluginupdate.PluginDesc, pluginupdate.Plugin]],
plugins: list[tuple[nixpkgs_plugin_update.PluginDesc, nixpkgs_plugin_update.Plugin]],
outfile: str,
):
with open(outfile, "w+") as f:
@@ -88,7 +85,7 @@ in lib.fix' (lib.extends overrides packages)
print(f"updated {outfile}")
def update(self, args):
pluginupdate.update_plugins(self, args)
nixpkgs_plugin_update.update_plugins(self, args)
def main():
@@ -27,12 +27,11 @@ from typing import List, Tuple
log = logging.getLogger("vim-updater")
# Import plugin update library from maintainers/scripts/pluginupdate.py
ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
import importlib
import pluginupdate
from pluginupdate import PluginDesc, run_nix_expr
import nixpkgs_plugin_update
from nixpkgs_plugin_update import PluginDesc, run_nix_expr
treesitter = importlib.import_module("nvim-treesitter.update")
@@ -44,15 +43,15 @@ HEADER = (
NIXPKGS_NVIMTREESITTER_FOLDER = "pkgs/applications/editors/vim/plugins/nvim-treesitter"
class VimEditor(pluginupdate.Editor):
class VimEditor(nixpkgs_plugin_update.Editor):
nvim_treesitter_updated = False
def generate_nix(
self, plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], outfile: str
self, plugins: List[Tuple[PluginDesc, nixpkgs_plugin_update.Plugin]], outfile: str
):
log.info("Generating nix code")
log.debug("Loading nvim-treesitter revision from nix...")
nvim_treesitter_rev = pluginupdate.run_nix_expr(
nvim_treesitter_rev = nixpkgs_plugin_update.run_nix_expr(
"(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev",
self.nixpkgs,
timeout=10,
@@ -64,7 +63,7 @@ class VimEditor(pluginupdate.Editor):
log.debug("Loading list of lua plugins...")
luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs, timeout=30)
def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
def _isNeovimPlugin(plug: nixpkgs_plugin_update.Plugin) -> bool:
"""
Whether it's a neovim-only plugin
We can check if it's available in lua packages
@@ -103,7 +102,7 @@ class VimEditor(pluginupdate.Editor):
print(f"updated {outfile}")
def plugin2nix(
self, pdesc: PluginDesc, plugin: pluginupdate.Plugin, isNeovim: bool
self, pdesc: PluginDesc, plugin: nixpkgs_plugin_update.Plugin, isNeovim: bool
) -> str:
if isNeovim:
raise RuntimeError(f"Plugin {plugin.name} is already packaged in `luaPackages`, please use that")
@@ -129,7 +128,7 @@ class VimEditor(pluginupdate.Editor):
return content
def update(self, args):
pluginupdate.update_plugins(self, args)
nixpkgs_plugin_update.update_plugins(self, args)
# TODO this should probably be skipped when running outside a nixpkgs checkout
if self.nvim_treesitter_updated:
@@ -24,8 +24,8 @@ buildPythonApplication {
];
pythonPath = [
python3Packages.gitpython
python3Packages.requests
python3Packages.nixpkgs-plugin-update
];
dontUnpack = true;
@@ -43,12 +43,12 @@ buildPythonApplication {
neovim-unwrapped
nurl
]
}" --prefix PYTHONPATH : "${./.}:${../../../../../../maintainers/scripts/pluginupdate-py}" )
}" --prefix PYTHONPATH : "${./.}" )
wrapPythonPrograms
'';
shellHook = ''
export PYTHONPATH=pkgs/applications/editors/vim/plugins:maintainers/scripts/pluginupdate-py:$PYTHONPATH
export PYTHONPATH=pkgs/applications/editors/vim/plugins:$PYTHONPATH
'';
passthru.updateScript = writeShellScript "updateScript" ''
@@ -5,7 +5,6 @@
lib,
nix-prefetch-scripts,
luarocks-nix,
pluginupdate,
lua5_1,
lua5_2,
lua5_3,
@@ -41,18 +40,15 @@ python3Packages.buildPythonApplication {
];
dependencies = [
python3Packages.gitpython
python3Packages.nixpkgs-plugin-update
];
postFixup = ''
echo "pluginupdate folder ${pluginupdate}"
wrapProgram $out/bin/luarocks-packages-updater \
--prefix PYTHONPATH : "${pluginupdate}" \
--prefix PATH : "${path}"
'';
shellHook = ''
export PYTHONPATH="maintainers/scripts/pluginupdate-py:$PYTHONPATH"
export PATH="${path}:$PATH"
'';
@@ -18,8 +18,8 @@ from dataclasses import dataclass
from multiprocessing.dummy import Pool
from pathlib import Path
import pluginupdate
from pluginupdate import FetchConfig, update_plugins
import nixpkgs_plugin_update
from nixpkgs_plugin_update import FetchConfig, update_plugins
class ColoredFormatter(logging.Formatter):
@@ -88,7 +88,7 @@ class LuaPlugin:
# rename Editor to LangUpdate/ EcosystemUpdater
class LuaEditor(pluginupdate.Editor):
class LuaEditor(nixpkgs_plugin_update.Editor):
def create_parser(self):
parser = super().create_parser()
parser.set_defaults(proc=1)
@@ -0,0 +1,42 @@
{
lib,
buildPythonPackage,
uv-build,
gitpython,
ruff,
mypy,
}:
buildPythonPackage {
pname = "nixpkgs-plugin-update";
version = "0.1.0";
format = "pyproject";
src = ./nixpkgs-plugin-update;
build-system = [ uv-build ];
dependencies = [
gitpython
];
nativeCheckInputs = [
ruff
mypy
];
postInstallCheck = ''
ruff check
mypy
'';
meta = {
description = "Library for updating plugin collections in Nixpkgs";
license = lib.licenses.mit;
maintainers = [
lib.maintainers.teto
lib.maintainers.perchun
lib.maintainers.khaneliman
];
};
}
@@ -0,0 +1,14 @@
uv.lock
.ruff_cache/
.mypy_cache/
# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info
# Virtual environments
.venv
@@ -0,0 +1,20 @@
[project]
name = "nixpkgs-plugin-update"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"gitpython>=3.1.45",
]
[build-system]
requires = ["uv_build>=0.8.19"]
build-backend = "uv_build"
[dependency-groups]
dev = [
"mypy>=1.18.2",
"ruff>=0.14.1",
]
[tool.mypy]
packages = ["nixpkgs_plugin_update"]
@@ -3,13 +3,6 @@
# - pkgs/applications/editors/kakoune/plugins/update.py
# - pkgs/development/lua-modules/updater/updater.py
# format:
# $ nix run nixpkgs#ruff maintainers/scripts/pluginupdate.py
# type-check:
# $ nix run nixpkgs#python3.pkgs.mypy maintainers/scripts/pluginupdate.py
# linted:
# $ nix run nixpkgs#python3.pkgs.flake8 -- --ignore E501,E265 maintainers/scripts/pluginupdate.py
import argparse
import csv
import functools
-4
View File
@@ -5830,10 +5830,6 @@ with pkgs;
luarocks = luaPackages.luarocks;
luarocks-nix = luaPackages.luarocks-nix;
luarocks-packages-updater = callPackage ../by-name/lu/luarocks-packages-updater/package.nix {
pluginupdate = ../../maintainers/scripts/pluginupdate-py;
};
toluapp = callPackage ../development/tools/toluapp {
lua = lua5_1; # doesn't work with any other :(
};
+2
View File
@@ -10602,6 +10602,8 @@ self: super: with self; {
nix-prefetch-github = callPackage ../development/python-modules/nix-prefetch-github { };
nixpkgs-plugin-update = callPackage ../development/python-modules/nixpkgs-plugin-update { };
nixpkgs-pytools = callPackage ../development/python-modules/nixpkgs-pytools { };
nixpkgs-updaters-library = callPackage ../development/python-modules/nixpkgs-updaters-library { };