vimPluginsUpdater: make development easier
`nix develop .#vimPluginsUpdater` now lets you enter a shell where you can run `pkgs/applications/editors/vim/plugins/update.py` and iteratively develop ! - removed `warn` warning from python by using `warning` instead - `plugin2nix` was calling the same bit of code over and over thus slowing down the generator by a lot
This commit is contained in:
parent
135b22c5e8
commit
35e972e3a4
maintainers/scripts
pkgs
0
maintainers/scripts/__init__.py
Normal file
0
maintainers/scripts/__init__.py
Normal file
@ -142,7 +142,7 @@ class Repo:
|
|||||||
return loaded
|
return loaded
|
||||||
|
|
||||||
def prefetch(self, ref: Optional[str]) -> str:
|
def prefetch(self, ref: Optional[str]) -> str:
|
||||||
print("Prefetching")
|
print("Prefetching %s", self.uri)
|
||||||
loaded = self._prefetch(ref)
|
loaded = self._prefetch(ref)
|
||||||
return loaded["sha256"]
|
return loaded["sha256"]
|
||||||
|
|
||||||
@ -266,6 +266,7 @@ class PluginDesc:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load_from_csv(config: FetchConfig, row: Dict[str, str]) -> "PluginDesc":
|
def load_from_csv(config: FetchConfig, row: Dict[str, str]) -> "PluginDesc":
|
||||||
|
log.debug("Loading row %s", row)
|
||||||
branch = row["branch"]
|
branch = row["branch"]
|
||||||
repo = make_repo(row["repo"], branch.strip())
|
repo = make_repo(row["repo"], branch.strip())
|
||||||
repo.token = config.github_token
|
repo.token = config.github_token
|
||||||
@ -328,7 +329,7 @@ def load_plugins_from_csv(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run_nix_expr(expr, nixpkgs: str):
|
def run_nix_expr(expr, nixpkgs: str, **args):
|
||||||
'''
|
'''
|
||||||
:param expr nix expression to fetch current plugins
|
:param expr nix expression to fetch current plugins
|
||||||
:param nixpkgs Path towards a nixpkgs checkout
|
:param nixpkgs Path towards a nixpkgs checkout
|
||||||
@ -347,7 +348,7 @@ def run_nix_expr(expr, nixpkgs: str):
|
|||||||
nix_path,
|
nix_path,
|
||||||
]
|
]
|
||||||
log.debug("Running command: %s", " ".join(cmd))
|
log.debug("Running command: %s", " ".join(cmd))
|
||||||
out = subprocess.check_output(cmd, timeout=90)
|
out = subprocess.check_output(cmd, **args)
|
||||||
data = json.loads(out)
|
data = json.loads(out)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -736,6 +737,7 @@ def rewrite_input(
|
|||||||
redirects: Redirects = {},
|
redirects: Redirects = {},
|
||||||
append: List[PluginDesc] = [],
|
append: List[PluginDesc] = [],
|
||||||
):
|
):
|
||||||
|
log.info("Rewriting input file %s", input_file)
|
||||||
plugins = load_plugins_from_csv(
|
plugins = load_plugins_from_csv(
|
||||||
config,
|
config,
|
||||||
input_file,
|
input_file,
|
||||||
@ -744,10 +746,14 @@ def rewrite_input(
|
|||||||
plugins.extend(append)
|
plugins.extend(append)
|
||||||
|
|
||||||
if redirects:
|
if redirects:
|
||||||
|
log.debug("Dealing with deprecated plugins listed in %s", deprecated)
|
||||||
|
|
||||||
cur_date_iso = datetime.now().strftime("%Y-%m-%d")
|
cur_date_iso = datetime.now().strftime("%Y-%m-%d")
|
||||||
with open(deprecated, "r") as f:
|
with open(deprecated, "r") as f:
|
||||||
deprecations = json.load(f)
|
deprecations = json.load(f)
|
||||||
|
# TODO parallelize this step
|
||||||
for pdesc, new_repo in redirects.items():
|
for pdesc, new_repo in redirects.items():
|
||||||
|
log.info("Rewriting input file %s", input_file)
|
||||||
new_pdesc = PluginDesc(new_repo, pdesc.branch, pdesc.alias)
|
new_pdesc = PluginDesc(new_repo, pdesc.branch, pdesc.alias)
|
||||||
old_plugin, _ = prefetch_plugin(pdesc)
|
old_plugin, _ = prefetch_plugin(pdesc)
|
||||||
new_plugin, _ = prefetch_plugin(new_pdesc)
|
new_plugin, _ = prefetch_plugin(new_pdesc)
|
||||||
@ -791,7 +797,7 @@ def update_plugins(editor: Editor, args):
|
|||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
redirects = update()
|
redirects = update()
|
||||||
duration = time.time() - start_time
|
duration = time.time() - start_time
|
||||||
print(f"The plugin update took {duration}s.")
|
print(f"The plugin update took {duration:.2f}s.")
|
||||||
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, redirects)
|
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, redirects)
|
||||||
|
|
||||||
autocommit = not args.no_commit
|
autocommit = not args.no_commit
|
||||||
|
@ -40,7 +40,9 @@ ROOT = Path(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe
|
|||||||
import pluginupdate
|
import pluginupdate
|
||||||
import importlib
|
import importlib
|
||||||
from pluginupdate import run_nix_expr, PluginDesc
|
from pluginupdate import run_nix_expr, PluginDesc
|
||||||
import treesitter
|
|
||||||
|
treesitter = importlib.import_module('nvim-treesitter.update')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HEADER = (
|
HEADER = (
|
||||||
@ -54,14 +56,37 @@ class VimEditor(pluginupdate.Editor):
|
|||||||
nvim_treesitter_updated = False
|
nvim_treesitter_updated = False
|
||||||
|
|
||||||
def generate_nix(
|
def generate_nix(
|
||||||
self, plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]], outfile: str
|
self,
|
||||||
|
plugins: List[Tuple[PluginDesc, pluginupdate.Plugin]],
|
||||||
|
outfile: str
|
||||||
):
|
):
|
||||||
|
log.info("Generating nix code")
|
||||||
sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower())
|
sorted_plugins = sorted(plugins, key=lambda v: v[0].name.lower())
|
||||||
|
log.debug("Loading nvim-treesitter revision from nix...")
|
||||||
nvim_treesitter_rev = pluginupdate.run_nix_expr(
|
nvim_treesitter_rev = pluginupdate.run_nix_expr(
|
||||||
"(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev", self.nixpkgs
|
"(import <localpkgs> { }).vimPlugins.nvim-treesitter.src.rev",
|
||||||
|
self.nixpkgs,
|
||||||
|
timeout=10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GET_PLUGINS_LUA = """
|
||||||
|
with import <localpkgs> {};
|
||||||
|
lib.attrNames lua51Packages"""
|
||||||
|
log.debug("Loading list of lua plugins...")
|
||||||
|
luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs, timeout=30)
|
||||||
|
|
||||||
|
def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
|
||||||
|
"""
|
||||||
|
Whether it's a neovim-only plugin
|
||||||
|
We can check if it's available in lua packages
|
||||||
|
"""
|
||||||
|
if plug.normalized_name in luaPlugins:
|
||||||
|
log.debug("%s is a neovim plugin", plug)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
with open(outfile, "w+") as f:
|
with open(outfile, "w+") as f:
|
||||||
|
log.debug("Writing to %s", outfile)
|
||||||
f.write(HEADER)
|
f.write(HEADER)
|
||||||
f.write(
|
f.write(
|
||||||
textwrap.dedent(
|
textwrap.dedent(
|
||||||
@ -74,7 +99,7 @@ class VimEditor(pluginupdate.Editor):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
for pdesc, plugin in sorted_plugins:
|
for pdesc, plugin in sorted_plugins:
|
||||||
content = self.plugin2nix(pdesc, plugin)
|
content = self.plugin2nix(pdesc, plugin, _isNeovimPlugin(plugin))
|
||||||
f.write(content)
|
f.write(content)
|
||||||
if (
|
if (
|
||||||
plugin.name == "nvim-treesitter"
|
plugin.name == "nvim-treesitter"
|
||||||
@ -84,27 +109,10 @@ class VimEditor(pluginupdate.Editor):
|
|||||||
f.write("\n}\n")
|
f.write("\n}\n")
|
||||||
print(f"updated {outfile}")
|
print(f"updated {outfile}")
|
||||||
|
|
||||||
def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin) -> str:
|
def plugin2nix(self, pdesc: PluginDesc, plugin: pluginupdate.Plugin, isNeovim: bool) -> str:
|
||||||
GET_PLUGINS_LUA = """
|
|
||||||
with import <localpkgs> {};
|
|
||||||
lib.attrNames lua51Packages"""
|
|
||||||
luaPlugins = run_nix_expr(GET_PLUGINS_LUA, self.nixpkgs)
|
|
||||||
|
|
||||||
repo = pdesc.repo
|
repo = pdesc.repo
|
||||||
|
|
||||||
def _isNeovimPlugin(plug: pluginupdate.Plugin) -> bool:
|
|
||||||
"""
|
|
||||||
Whether it's a neovim-only plugin
|
|
||||||
We can check if it's available in lua packages
|
|
||||||
"""
|
|
||||||
# global luaPlugins
|
|
||||||
if plug.normalized_name in luaPlugins:
|
|
||||||
log.debug("%s is a neovim plugin", plug)
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
isNeovim = _isNeovimPlugin(plugin)
|
|
||||||
|
|
||||||
content = f" {plugin.normalized_name} = "
|
content = f" {plugin.normalized_name} = "
|
||||||
src_nix = repo.as_nix(plugin)
|
src_nix = repo.as_nix(plugin)
|
||||||
content += """{buildFn} {{
|
content += """{buildFn} {{
|
||||||
@ -159,8 +167,8 @@ class VimEditor(pluginupdate.Editor):
|
|||||||
def main():
|
def main():
|
||||||
global luaPlugins
|
global luaPlugins
|
||||||
|
|
||||||
log.debug(f"Loading from {ROOT}/../get-plugins.nix")
|
log.debug(f"Loading from {ROOT}/get-plugins.nix")
|
||||||
with open(f"{ROOT}/../get-plugins.nix") as f:
|
with open(f"{ROOT}/get-plugins.nix") as f:
|
||||||
GET_PLUGINS = f.read()
|
GET_PLUGINS = f.read()
|
||||||
editor = VimEditor(
|
editor = VimEditor(
|
||||||
"vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS
|
"vim", Path("pkgs/applications/editors/vim/plugins"), GET_PLUGINS
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
, nurl
|
, nurl
|
||||||
|
|
||||||
# optional
|
# optional
|
||||||
, vimPlugins
|
, neovim-unwrapped
|
||||||
, neovim
|
|
||||||
}:
|
}:
|
||||||
buildPythonApplication {
|
buildPythonApplication {
|
||||||
format = "other";
|
|
||||||
pname = "vim-plugins-updater";
|
pname = "vim-plugins-updater";
|
||||||
version = "0.1";
|
version = "0.1";
|
||||||
|
|
||||||
|
format = "other";
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
makeWrapper
|
makeWrapper
|
||||||
python3Packages.wrapPython
|
python3Packages.wrapPython
|
||||||
@ -29,16 +29,18 @@ buildPythonApplication {
|
|||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin $out/lib
|
mkdir -p $out/bin $out/lib
|
||||||
cp ${./update.py} $out/bin/vim-plugins-updater
|
cp ${./update.py} $out/bin/vim-plugins-updater
|
||||||
cp ${./get-plugins.nix} $out/get-plugins.nix
|
cp ${./get-plugins.nix} $out/bin/get-plugins.nix
|
||||||
cp ${./nvim-treesitter/update.py} $out/lib/treesitter.py
|
|
||||||
cp ${../../../../../maintainers/scripts/pluginupdate.py} $out/lib/pluginupdate.py
|
|
||||||
|
|
||||||
# wrap python scripts
|
# wrap python scripts
|
||||||
makeWrapperArgs+=( --prefix PATH : "${lib.makeBinPath [
|
makeWrapperArgs+=( --prefix PATH : "${lib.makeBinPath [
|
||||||
nix nix-prefetch-git neovim nurl ]}" --prefix PYTHONPATH : "$out/lib" )
|
nix nix-prefetch-git neovim-unwrapped nurl ]}" --prefix PYTHONPATH : "${./.}:${../../../../../maintainers/scripts}" )
|
||||||
wrapPythonPrograms
|
wrapPythonPrograms
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
export PYTHONPATH=pkgs/applications/editors/vim/plugins:maintainers/scripts:$PYTHONPATH
|
||||||
|
'';
|
||||||
|
|
||||||
meta.mainProgram = "vim-plugins-updater";
|
meta.mainProgram = "vim-plugins-updater";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ def generate_pkg_nix(plug: LuaPlugin):
|
|||||||
"'version' and 'ref' will be ignored as the rockspec is hardcoded for package %s"
|
"'version' and 'ref' will be ignored as the rockspec is hardcoded for package %s"
|
||||||
% plug.name
|
% plug.name
|
||||||
)
|
)
|
||||||
log.warn(msg)
|
log.warning(msg)
|
||||||
|
|
||||||
log.debug("Updating from rockspec %s", plug.rockspec)
|
log.debug("Updating from rockspec %s", plug.rockspec)
|
||||||
cmd.append(plug.rockspec)
|
cmd.append(plug.rockspec)
|
||||||
|
Loading…
Reference in New Issue
Block a user