···
-
# Used by pkgs/applications/editors/vim/plugins/update.py and pkgs/applications/editors/kakoune/plugins/update.py
# $ nix run nixpkgs.python3Packages.black -c black update.py
···
cmd = ["nix", "eval", "--extra-experimental-features",
"nix-command", "--impure", "--json", "--expr", expr]
-
log.debug("Running command %s", cmd)
out = subprocess.check_output(cmd)
···
self.cache_file = cache_file or f"{name}-plugin-cache.json"
def get_current_plugins(self) -> List[Plugin]:
data = run_nix_expr(self.get_plugins)
for name, attr in data.items():
-
print("get_current_plugins: name %s" % name)
p = Plugin(name, attr["rev"], attr["submodules"], attr["sha256"])
···
return load_plugins_from_csv(config, plugin_file)
-
def generate_nix(self, plugins, outfile: str):
'''Returns nothing for now, writes directly to outfile'''
raise NotImplementedError()
···
return rewrite_input(*args, **kwargs)
-
parser = argparse.ArgumentParser(
Updates nix derivations for {self.name} plugins.\n
By default from {self.default_in} to {self.default_out}"""
-
help=f"Plugin to add to {self.attr_path} from Github in the form owner/repo",
help="A list of plugins in the form owner/repo",
default=self.default_out,
help="Filename to save generated nix code",
···
help="Number of concurrent processes to spawn. Setting --github-token allows higher values.",
···
help="""Allows to set --proc to higher values.
Uses GITHUB_API_TOKEN environment variables as the default value.""",
"--no-commit", "-n", action="store_true", default=False,
help="Whether to autocommit changes"
"--debug", "-d", choices=LOG_LEVELS.keys(),
default=logging.getLevelName(logging.WARN),
···
def update_plugins(editor: Editor, args):
"""The main entry function of this module. All input arguments are grouped in the `Editor`."""
-
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],
-
for plugin_line in args.add_plugins:
-
pdesc = PluginDesc.load_from_string(fetch_config, plugin_line)
-
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, append=append)
-
plugin, _ = prefetch_plugin(pdesc, )
-
"{drv_name}: init at {version}".format(
-
drv_name=editor.get_drv_name(plugin.normalized_name),
-
[args.outfile, args.input_file],
···
+
# python library used to update plugins:
+
# - pkgs/applications/editors/vim/plugins/update.py
+
# - pkgs/applications/editors/kakoune/plugins/update.py
+
# - 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]
+
log.debug("Running command %s", " ".join(cmd))
out = subprocess.check_output(cmd)
···
self.cache_file = cache_file or f"{name}-plugin-cache.json"
+
log.debug("called the 'add' command")
+
fetch_config = FetchConfig(args.proc, args.github_token)
+
for plugin_line in args.add_plugins:
+
log.debug("using plugin_line", plugin_line)
+
pdesc = PluginDesc.load_from_string(fetch_config, plugin_line)
+
log.debug("loaded as pdesc", pdesc)
+
editor.rewrite_input(fetch_config, args.input_file, editor.deprecated, append=append)
+
plugin, _ = prefetch_plugin(pdesc, )
+
autocommit = not args.no_commit
+
"{drv_name}: init at {version}".format(
+
drv_name=editor.get_drv_name(plugin.normalized_name),
+
[args.outfile, args.input_file],
+
# Expects arguments generated by 'update' subparser
+
def update(self, args ):
+
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():
p = Plugin(name, attr["rev"], attr["submodules"], attr["sha256"])
···
return load_plugins_from_csv(config, plugin_file)
+
def generate_nix(self, _plugins, _outfile: str):
'''Returns nothing for now, writes directly to outfile'''
raise NotImplementedError()
···
return rewrite_input(*args, **kwargs)
+
common = argparse.ArgumentParser(
Updates nix derivations for {self.name} plugins.\n
By default from {self.default_in} to {self.default_out}"""
help="A list of plugins in the form owner/repo",
default=self.default_out,
help="Filename to save generated nix code",
···
help="Number of concurrent processes to spawn. Setting --github-token allows higher values.",
···
help="""Allows to set --proc to higher values.
Uses GITHUB_API_TOKEN environment variables as the default value.""",
"--no-commit", "-n", action="store_true", default=False,
help="Whether to autocommit changes"
"--debug", "-d", choices=LOG_LEVELS.keys(),
default=logging.getLevelName(logging.WARN),
+
main = argparse.ArgumentParser(
+
Updates nix derivations for {self.name} plugins.\n
+
By default from {self.default_in} to {self.default_out}"""
+
subparsers = main.add_subparsers(dest="command", required=False)
+
padd = subparsers.add_parser(
+
description="Add new plugin",
+
padd.set_defaults(func=self.add)
+
help=f"Plugin to add to {self.attr_path} from Github in the form owner/repo",
+
pupdate = subparsers.add_parser(
+
description="Update all or a subset of existing plugins",
+
pupdate.set_defaults(func=self.update)
+
parser = self.create_parser()
+
args = parser.parse_args()
+
command = args.command or "update"
+
log.setLevel(LOG_LEVELS[args.debug])
+
log.info("Chose to run command: %s", command)
+
self.nixpkgs_repo = git.Repo(self.root, search_parent_directories=True)
+
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`."""
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],