Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/applications/editors/kakoune/plugins/update-shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

with pkgs;
let
pyEnv = python3.withPackages (ps: [ ps.gitpython ]);
pyEnv = python3.withPackages (ps: [ ps.nixpkgs-plugin-update ]);
in

mkShell {
Expand Down
13 changes: 5 additions & 8 deletions pkgs/applications/editors/kakoune/plugins/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
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
Expand Down Expand Up @@ -53,10 +50,10 @@
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:
Expand Down Expand Up @@ -88,7 +85,7 @@ def generate_nix(
print(f"updated {outfile}")

def update(self, args):
pluginupdate.update_plugins(self, args)
nixpkgs_plugin_update.update_plugins(self, args)


def main():
Expand Down
17 changes: 8 additions & 9 deletions pkgs/applications/editors/vim/plugins/utils/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@

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")

Expand All @@ -44,15 +43,15 @@
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,
Expand All @@ -64,7 +63,7 @@ def generate_nix(
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
Expand Down Expand Up @@ -103,7 +102,7 @@ def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
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")
Expand All @@ -129,7 +128,7 @@ def plugin2nix(
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:
Expand Down
6 changes: 3 additions & 3 deletions pkgs/applications/editors/vim/plugins/utils/updater.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ buildPythonApplication {
];

pythonPath = [
python3Packages.gitpython
python3Packages.requests
python3Packages.nixpkgs-plugin-update
];

dontUnpack = true;
Expand All @@ -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" ''
Expand Down
6 changes: 1 addition & 5 deletions pkgs/by-name/lu/luarocks-packages-updater/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
lib,
nix-prefetch-scripts,
luarocks-nix,
pluginupdate,
lua5_1,
lua5_2,
lua5_3,
Expand Down Expand Up @@ -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"
'';

Expand Down
6 changes: 3 additions & 3 deletions pkgs/by-name/lu/luarocks-packages-updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
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):
Expand Down Expand Up @@ -88,7 +88,7 @@ def normalized_name(self) -> str:


# 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)
Expand Down
42 changes: 42 additions & 0 deletions pkgs/development/python-modules/nixpkgs-plugin-update/default.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uv.lock
.ruff_cache/
.mypy_cache/

# Python-generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# Virtual environments
.venv
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -104,7 +97,7 @@ def __init__(self, uri: str, branch: str) -> None:
self._branch = branch
# Redirect is the new Repo to use
self.redirect: "Repo | None" = None
self.token = "dummy_token"
self.token: str | None = "dummy_token"

@property
def name(self):
Expand Down Expand Up @@ -141,7 +134,7 @@ def _prefetch(self, ref: str | None):
loaded = json.loads(data)
return loaded

def prefetch(self, ref: str | None) -> str:
def prefetch(self, ref: str) -> str:
log.info("Prefetching %s", self.uri)
loaded = self._prefetch(ref)
return loaded["sha256"]
Expand Down Expand Up @@ -202,12 +195,12 @@ def latest_commit(self) -> tuple[str, datetime]:
latest_entry = root.find(ATOM_ENTRY)
assert latest_entry is not None, f"No commits found in repository {self}"
commit_link = latest_entry.find(ATOM_LINK)
assert commit_link is not None, f"No link tag found feed entry {xml}"
assert commit_link is not None, f"No link tag found feed entry {xml!r}"
url = urlparse(commit_link.get("href"))
updated_tag = latest_entry.find(ATOM_UPDATED)
assert (
updated_tag is not None and updated_tag.text is not None
), f"No updated tag found feed entry {xml}"
), f"No updated tag found feed entry {xml!r}"
updated = datetime.strptime(updated_tag.text, "%Y-%m-%dT%H:%M:%SZ")
return Path(str(url.path)).name, updated

Expand Down Expand Up @@ -372,7 +365,7 @@ def __init__(
self.default_out = default_out or root.joinpath("generated.nix")
self.deprecated = deprecated or root.joinpath("deprecated.json")
self.cache_file = cache_file or f"{name}-plugin-cache.json"
self.nixpkgs_repo = None
self.nixpkgs_repo: git.Repo | None = None

def add(self, args):
"""CSV spec"""
Expand Down Expand Up @@ -403,6 +396,7 @@ def add(self, args):

autocommit = not args.no_commit
if autocommit:
assert editor.nixpkgs_repo is not None
commit(
editor.nixpkgs_repo,
"{drv_name}: init at {version}".format(
Expand Down Expand Up @@ -788,11 +782,10 @@ def make_repo(uri: str, branch) -> Repo:
# dumb check to see if it's of the form owner/repo (=> github) or https://...
res = urlparse(uri)
if res.netloc in ["github.com", ""]:
res = res.path.strip("/").split("/")
repo = RepoGitHub(res[0], res[1], branch)
owner, repo = res.path.strip("/").split("/")
return RepoGitHub(owner, repo, branch)
else:
repo = Repo(uri.strip(), branch)
return repo
return Repo(uri.strip(), branch)


def get_cache_path(cache_file_name: str) -> Path | None:
Expand Down Expand Up @@ -928,7 +921,7 @@ def update_plugins(editor: Editor, args):
All input arguments are grouped in the `Editor`."""

log.info("Start updating plugins")
if args.proc > 1 and args.github_token == None:
if args.proc > 1 and args.github_token is None:
log.warning(
"You have enabled parallel updates but haven't set a github token.\n"
"You may be hit with `HTTP Error 429: too many requests` as a consequence."
Expand Down Expand Up @@ -966,6 +959,7 @@ def update_plugins(editor: Editor, args):
if redirects:
update()
if autocommit:
assert editor.nixpkgs_repo is not None
commit(
editor.nixpkgs_repo,
f"{editor.attr_path}: resolve github repository redirects",
Expand Down
4 changes: 0 additions & 4 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 :(
};
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down
Loading