nixpkgs-plugin-update: format updater code

This commit is contained in:
Austin Horstman
2026-04-26 12:21:08 -05:00
parent d1c9df524a
commit 9f1639ef52
2 changed files with 24 additions and 13 deletions
@@ -36,9 +36,7 @@ from nixpkgs_plugin_update import PluginDesc, run_nix_expr
treesitter = importlib.import_module("nvim-treesitter.update")
HEADER = (
"# GENERATED by ./pkgs/applications/editors/vim/plugins/utils/update.py. Do not edit!"
)
HEADER = "# GENERATED by ./pkgs/applications/editors/vim/plugins/utils/update.py. Do not edit!"
NIXPKGS_NVIMTREESITTER_FOLDER = "pkgs/applications/editors/vim/plugins/nvim-treesitter"
@@ -47,7 +45,9 @@ class VimEditor(nixpkgs_plugin_update.Editor):
nvim_treesitter_updated = False
def generate_nix(
self, plugins: List[Tuple[PluginDesc, nixpkgs_plugin_update.Plugin]], outfile: str
self,
plugins: List[Tuple[PluginDesc, nixpkgs_plugin_update.Plugin]],
outfile: str,
):
log.info("Generating nix code")
log.debug("Loading nvim-treesitter source reference from nix...")
@@ -93,7 +93,10 @@ class VimEditor(nixpkgs_plugin_update.Editor):
for pdesc, plugin in plugins:
content = self.plugin2nix(pdesc, plugin, _isNeovimPlugin(plugin))
f.write(content)
if plugin.name == "nvim-treesitter" and (plugin.tag or plugin.commit) != nvim_treesitter_ref:
if (
plugin.name == "nvim-treesitter"
and (plugin.tag or plugin.commit) != nvim_treesitter_ref
):
self.nvim_treesitter_updated = True
f.write("}\n")
print(f"updated {outfile}")
@@ -102,7 +105,9 @@ class VimEditor(nixpkgs_plugin_update.Editor):
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")
raise RuntimeError(
f"Plugin {plugin.name} is already packaged in `luaPackages`, please use that"
)
repo = pdesc.repo
content = f" {plugin.normalized_name} = "
@@ -234,7 +234,9 @@ class Repo:
def as_nix(self, plugin: "Plugin") -> str:
ref_attr = (
f'tag = "{plugin.tag}";' if plugin.tag is not None else f'rev = "{plugin.commit}";'
f'tag = "{plugin.tag}";'
if plugin.tag is not None
else f'rev = "{plugin.commit}";'
)
return f"""fetchgit {{
url = "{self.uri}";
@@ -439,9 +441,7 @@ class RepoGitHub(Repo):
def _check_for_redirect(self, url: str, req: http.client.HTTPResponse):
response_url = req.geturl()
if url != response_url:
new_owner, new_name = (
urlsplit(response_url).path.strip("/").split("/")[:2]
)
new_owner, new_name = urlsplit(response_url).path.strip("/").split("/")[:2]
new_repo = RepoGitHub(owner=new_owner, repo=new_name, branch=self._branch)
self.redirect = new_repo
@@ -467,7 +467,9 @@ class RepoGitHub(Repo):
submodule_attr = ""
ref_attr = (
f'tag = "{plugin.tag}";' if plugin.tag is not None else f'rev = "{plugin.commit}";'
f'tag = "{plugin.tag}";'
if plugin.tag is not None
else f'rev = "{plugin.commit}";'
)
return f"""fetchFromGitHub {{
@@ -1105,7 +1107,9 @@ def prefetch_plugin(
latest_tag,
)
cached_plugin = cache[target_cache_key(p.repo.uri, commit, source_tag)] if cache else None
cached_plugin = (
cache[target_cache_key(p.repo.uri, commit, source_tag)] if cache else None
)
if cached_plugin is not None:
log.debug(f"Cache hit for {p.name}!")
return (
@@ -1124,7 +1128,9 @@ def prefetch_plugin(
has_submodules = p.repo.has_submodules()
log.debug(f"prefetch {p.name}")
sha256 = (
p.repo.prefetch(f"{GIT_TAGS_PREFIX}{source_tag}") if source_tag else p.repo.prefetch(commit)
p.repo.prefetch(f"{GIT_TAGS_PREFIX}{source_tag}")
if source_tag
else p.repo.prefetch(commit)
)
return (