···
1
-
# Used by pkgs/applications/editors/vim/plugins/update.py and pkgs/applications/editors/kakoune/plugins/update.py
1
+
# python library used to update plugins:
2
+
# - pkgs/applications/editors/vim/plugins/update.py
3
+
# - pkgs/applications/editors/kakoune/plugins/update.py
4
+
# - maintainers/scripts/update-luarocks-packages
# $ nix run nixpkgs.python3Packages.black -c black update.py
···
cmd = ["nix", "eval", "--extra-experimental-features",
"nix-command", "--impure", "--json", "--expr", expr]
318
-
log.debug("Running command %s", cmd)
321
+
log.debug("Running command %s", " ".join(cmd))
out = subprocess.check_output(cmd)
320
-
data = json.loads(out)
323
+
data = json.loads(out)
···
self.cache_file = cache_file or f"{name}-plugin-cache.json"
350
+
def add(self, args):
352
+
log.debug("called the 'add' command")
353
+
fetch_config = FetchConfig(args.proc, args.github_token)
355
+
for plugin_line in args.add_plugins:
356
+
log.debug("using plugin_line", plugin_line)
357
+
pdesc = PluginDesc.load_from_string(fetch_config, plugin_line)
358
+
log.debug("loaded as pdesc", pdesc)
360
+
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, append=append)
361
+
plugin, _ = prefetch_plugin(pdesc, )
362
+
autocommit = not args.no_commit
365
+
editor.nixpkgs_repo,
366
+
"{drv_name}: init at {version}".format(
367
+
drv_name=editor.get_drv_name(plugin.normalized_name),
368
+
version=plugin.version
370
+
[args.outfile, args.input_file],
373
+
# Expects arguments generated by 'update' subparser
374
+
def update(self, args ):
376
+
print("the update member function should be overriden in subclasses")
def get_current_plugins(self) -> List[Plugin]:
data = run_nix_expr(self.get_plugins)
for name, attr in data.items():
352
-
print("get_current_plugins: name %s" % name)
p = Plugin(name, attr["rev"], attr["submodules"], attr["sha256"])
···
return load_plugins_from_csv(config, plugin_file)
361
-
def generate_nix(self, plugins, outfile: str):
391
+
def generate_nix(self, _plugins, _outfile: str):
'''Returns nothing for now, writes directly to outfile'''
raise NotImplementedError()
···
return rewrite_input(*args, **kwargs)
398
-
parser = argparse.ArgumentParser(
428
+
common = argparse.ArgumentParser(
Updates nix derivations for {self.name} plugins.\n
By default from {self.default_in} to {self.default_out}"""
404
-
parser.add_argument(
406
-
dest="add_plugins",
409
-
help=f"Plugin to add to {self.attr_path} from Github in the form owner/repo",
411
-
parser.add_argument(
435
+
common.add_argument(
help="A list of plugins in the form owner/repo",
418
-
parser.add_argument(
442
+
common.add_argument(
default=self.default_out,
help="Filename to save generated nix code",
425
-
parser.add_argument(
449
+
common.add_argument(
···
help="Number of concurrent processes to spawn. Setting --github-token allows higher values.",
433
-
parser.add_argument(
457
+
common.add_argument(
···
help="""Allows to set --proc to higher values.
Uses GITHUB_API_TOKEN environment variables as the default value.""",
441
-
parser.add_argument(
465
+
common.add_argument(
"--no-commit", "-n", action="store_true", default=False,
help="Whether to autocommit changes"
445
-
parser.add_argument(
469
+
common.add_argument(
"--debug", "-d", choices=LOG_LEVELS.keys(),
default=logging.getLevelName(logging.WARN),
475
+
main = argparse.ArgumentParser(
478
+
Updates nix derivations for {self.name} plugins.\n
479
+
By default from {self.default_in} to {self.default_out}"""
483
+
subparsers = main.add_subparsers(dest="command", required=False)
484
+
padd = subparsers.add_parser(
486
+
description="Add new plugin",
489
+
padd.set_defaults(func=self.add)
494
+
help=f"Plugin to add to {self.attr_path} from Github in the form owner/repo",
497
+
pupdate = subparsers.add_parser(
499
+
description="Update all or a subset of existing plugins",
502
+
pupdate.set_defaults(func=self.update)
507
+
Convenience function
509
+
parser = self.create_parser()
510
+
args = parser.parse_args()
511
+
command = args.command or "update"
512
+
log.setLevel(LOG_LEVELS[args.debug])
513
+
log.info("Chose to run command: %s", command)
515
+
if not args.no_commit:
516
+
self.nixpkgs_repo = git.Repo(self.root, search_parent_directories=True)
518
+
getattr(self, command)(args)
···
def update_plugins(editor: Editor, args):
"""The main entry function of this module. All input arguments are grouped in the `Editor`."""
664
-
log.setLevel(LOG_LEVELS[args.debug])
log.info("Start updating plugins")
fetch_config = FetchConfig(args.proc, args.github_token)
update = editor.get_update(args.input_file, args.outfile, fetch_config)
···
[args.outfile, args.input_file, editor.deprecated],
687
-
for plugin_line in args.add_plugins:
688
-
pdesc = PluginDesc.load_from_string(fetch_config, plugin_line)
690
-
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, append=append)
692
-
plugin, _ = prefetch_plugin(pdesc, )
695
-
editor.nixpkgs_repo,
696
-
"{drv_name}: init at {version}".format(
697
-
drv_name=editor.get_drv_name(plugin.normalized_name),
698
-
version=plugin.version
700
-
[args.outfile, args.input_file],