From 00c40f106941764b01cb394a276e04134e15796d Mon Sep 17 00:00:00 2001 From: Emily Date: Mon, 20 Oct 2025 18:28:41 +0100 Subject: [PATCH] python313Packages.nixpkgs-plugin-update: init from maintainer script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../editors/kakoune/plugins/update-shell.nix | 2 +- .../editors/kakoune/plugins/update.py | 13 +++--- .../editors/vim/plugins/utils/update.py | 17 ++++---- .../editors/vim/plugins/utils/updater.nix | 6 +-- .../lu/luarocks-packages-updater/package.nix | 6 +-- .../lu/luarocks-packages-updater/updater.py | 6 +-- .../nixpkgs-plugin-update/default.nix | 42 +++++++++++++++++++ .../nixpkgs-plugin-update/.gitignore | 14 +++++++ .../nixpkgs-plugin-update/pyproject.toml | 20 +++++++++ .../src/nixpkgs_plugin_update/__init__.py | 7 ---- .../src/nixpkgs_plugin_update/py.typed | 0 pkgs/top-level/all-packages.nix | 4 -- pkgs/top-level/python-packages.nix | 2 + 13 files changed, 99 insertions(+), 40 deletions(-) create mode 100644 pkgs/development/python-modules/nixpkgs-plugin-update/default.nix create mode 100644 pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/.gitignore create mode 100644 pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/pyproject.toml rename maintainers/scripts/pluginupdate-py/pluginupdate.py => pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/__init__.py (99%) rename maintainers/scripts/pluginupdate-py/__init__.py => pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/py.typed (100%) diff --git a/pkgs/applications/editors/kakoune/plugins/update-shell.nix b/pkgs/applications/editors/kakoune/plugins/update-shell.nix index 787891309237..761ed6aad3ca 100644 --- a/pkgs/applications/editors/kakoune/plugins/update-shell.nix +++ b/pkgs/applications/editors/kakoune/plugins/update-shell.nix @@ -4,7 +4,7 @@ with pkgs; let - pyEnv = python3.withPackages (ps: [ ps.gitpython ]); + pyEnv = python3.withPackages (ps: [ ps.nixpkgs-plugin-update ]); in mkShell { diff --git a/pkgs/applications/editors/kakoune/plugins/update.py b/pkgs/applications/editors/kakoune/plugins/update.py index 9b06d0c06e9c..169304c9aa4e 100755 --- a/pkgs/applications/editors/kakoune/plugins/update.py +++ b/pkgs/applications/editors/kakoune/plugins/update.py @@ -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 {{ }}; 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(): diff --git a/pkgs/applications/editors/vim/plugins/utils/update.py b/pkgs/applications/editors/vim/plugins/utils/update.py index 9458b8f074d7..c167f0a92386 100755 --- a/pkgs/applications/editors/vim/plugins/utils/update.py +++ b/pkgs/applications/editors/vim/plugins/utils/update.py @@ -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 { }).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: diff --git a/pkgs/applications/editors/vim/plugins/utils/updater.nix b/pkgs/applications/editors/vim/plugins/utils/updater.nix index 9560708fbb0e..369b1b79e9b6 100644 --- a/pkgs/applications/editors/vim/plugins/utils/updater.nix +++ b/pkgs/applications/editors/vim/plugins/utils/updater.nix @@ -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" '' diff --git a/pkgs/by-name/lu/luarocks-packages-updater/package.nix b/pkgs/by-name/lu/luarocks-packages-updater/package.nix index cf41d472435e..d597834c7bc0 100644 --- a/pkgs/by-name/lu/luarocks-packages-updater/package.nix +++ b/pkgs/by-name/lu/luarocks-packages-updater/package.nix @@ -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" ''; diff --git a/pkgs/by-name/lu/luarocks-packages-updater/updater.py b/pkgs/by-name/lu/luarocks-packages-updater/updater.py index 4aa7ea6b9db0..555cde43ec55 100755 --- a/pkgs/by-name/lu/luarocks-packages-updater/updater.py +++ b/pkgs/by-name/lu/luarocks-packages-updater/updater.py @@ -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) diff --git a/pkgs/development/python-modules/nixpkgs-plugin-update/default.nix b/pkgs/development/python-modules/nixpkgs-plugin-update/default.nix new file mode 100644 index 000000000000..ddba0da26cbb --- /dev/null +++ b/pkgs/development/python-modules/nixpkgs-plugin-update/default.nix @@ -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 + ]; + }; +} diff --git a/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/.gitignore b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/.gitignore new file mode 100644 index 000000000000..688db6151f29 --- /dev/null +++ b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/.gitignore @@ -0,0 +1,14 @@ +uv.lock +.ruff_cache/ +.mypy_cache/ + +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/pyproject.toml b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/pyproject.toml new file mode 100644 index 000000000000..4c55bbb015b7 --- /dev/null +++ b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/pyproject.toml @@ -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"] diff --git a/maintainers/scripts/pluginupdate-py/pluginupdate.py b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/__init__.py similarity index 99% rename from maintainers/scripts/pluginupdate-py/pluginupdate.py rename to pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/__init__.py index d42ec2709470..299d5a056a99 100644 --- a/maintainers/scripts/pluginupdate-py/pluginupdate.py +++ b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/__init__.py @@ -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 diff --git a/maintainers/scripts/pluginupdate-py/__init__.py b/pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/py.typed similarity index 100% rename from maintainers/scripts/pluginupdate-py/__init__.py rename to pkgs/development/python-modules/nixpkgs-plugin-update/nixpkgs-plugin-update/src/nixpkgs_plugin_update/py.typed diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a2c59749b7bc..ff1e9554de01 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 :( }; diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 8eb2ed8fda8a..25f943dce4ea 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -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 { };