vimPlugins: update.py --add <plugin> argument
- update.py's new --add argument replaces manual editing of vim-plugin-names for basic use cases.
This commit is contained in:
parent
042c3dc356
commit
f1ae95f6d3
|
@ -261,12 +261,7 @@ deoplete-fish = super.deoplete-fish.overrideAttrs(old: {
|
||||||
|
|
||||||
Sometimes plugins require an override that must be changed when the plugin is updated. This can cause issues when Vim plugins are auto-updated but the associated override isn't updated. For these plugins, the override should be written so that it specifies all information required to install the plugin, and running `./update.py` doesn't change the derivation for the plugin. Manually updating the override is required to update these types of plugins. An example of such a plugin is `LanguageClient-neovim`.
|
Sometimes plugins require an override that must be changed when the plugin is updated. This can cause issues when Vim plugins are auto-updated but the associated override isn't updated. For these plugins, the override should be written so that it specifies all information required to install the plugin, and running `./update.py` doesn't change the derivation for the plugin. Manually updating the override is required to update these types of plugins. An example of such a plugin is `LanguageClient-neovim`.
|
||||||
|
|
||||||
To add a new plugin:
|
To add a new plugin, run `./update.py --commit --add "[owner]/[name]"`.
|
||||||
|
|
||||||
1. run `./update.py --commit`,
|
|
||||||
2. add the new plugin to [vim-plugin-names](/pkgs/misc/vim-plugins/vim-plugin-names) and add overrides if required to [overrides.nix](/pkgs/misc/vim-plugins/overrides.nix),
|
|
||||||
3. run `./update.py` again and create a commit named "vimPlugins.[name]: init at [version]" (where `name` and `version` can be found in [generated.nix](/pkgs/misc/vim-plugins/generated.nix)), and
|
|
||||||
4. create a pull request.
|
|
||||||
|
|
||||||
## Important repositories
|
## Important repositories
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ NIXPKGS_PATH = ROOT.cwd().parents[2]
|
||||||
DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
|
DEFAULT_IN = ROOT.joinpath("vim-plugin-names")
|
||||||
DEFAULT_OUT = ROOT.joinpath("generated.nix")
|
DEFAULT_OUT = ROOT.joinpath("generated.nix")
|
||||||
DEPRECATED = ROOT.joinpath("deprecated.json")
|
DEPRECATED = ROOT.joinpath("deprecated.json")
|
||||||
|
OVERRIDES = ROOT.joinpath("overrides.nix")
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
@ -127,7 +128,7 @@ class Repo:
|
||||||
new_owner, new_name = (
|
new_owner, new_name = (
|
||||||
urllib.parse.urlsplit(response_url).path.strip("/").split("/")[:2]
|
urllib.parse.urlsplit(response_url).path.strip("/").split("/")[:2]
|
||||||
)
|
)
|
||||||
end_line = "\n" if self.alias is None else f" as {self.alias}\n"
|
end_line = "\n" if self.alias == "" else f" as {self.alias}\n"
|
||||||
plugin_line = "{owner}/{name}" + end_line
|
plugin_line = "{owner}/{name}" + end_line
|
||||||
|
|
||||||
old_plugin = plugin_line.format(owner=self.owner, name=self.name)
|
old_plugin = plugin_line.format(owner=self.owner, name=self.name)
|
||||||
|
@ -280,17 +281,17 @@ def check_results(
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def parse_plugin_line(line: str) -> Tuple[str, str, Optional[str]]:
|
def parse_plugin_line(line: str) -> Tuple[str, str, str]:
|
||||||
name, repo = line.split("/")
|
name, repo = line.split("/")
|
||||||
try:
|
try:
|
||||||
repo, alias = repo.split(" as ")
|
repo, alias = repo.split(" as ")
|
||||||
return (name, repo, alias.strip())
|
return (name, repo, alias.strip())
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# no alias defined
|
# no alias defined
|
||||||
return (name, repo.strip(), None)
|
return (name, repo.strip(), "")
|
||||||
|
|
||||||
|
|
||||||
def load_plugin_spec(plugin_file: str) -> List[Tuple[str, str, Optional[str]]]:
|
def load_plugin_spec(plugin_file: str) -> List[Tuple[str, str, str]]:
|
||||||
plugins = []
|
plugins = []
|
||||||
with open(plugin_file) as f:
|
with open(plugin_file) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
@ -416,10 +417,12 @@ in lib.fix' (lib.extends overrides packages)
|
||||||
print(f"updated {outfile}")
|
print(f"updated {outfile}")
|
||||||
|
|
||||||
|
|
||||||
def rewrite_input(input_file: Path, redirects: dict):
|
def rewrite_input(input_file: Path, redirects: dict = None, append: Tuple = ()):
|
||||||
with open(input_file, "r") as f:
|
with open(input_file, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
|
lines.extend(append)
|
||||||
|
|
||||||
if redirects:
|
if redirects:
|
||||||
lines = [redirects.get(line, line) for line in lines]
|
lines = [redirects.get(line, line) for line in lines]
|
||||||
|
|
||||||
|
@ -450,6 +453,14 @@ def parse_args():
|
||||||
f"By default from {DEFAULT_IN} to {DEFAULT_OUT}"
|
f"By default from {DEFAULT_IN} to {DEFAULT_OUT}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--add",
|
||||||
|
"-a",
|
||||||
|
dest="add_plugins",
|
||||||
|
default=[],
|
||||||
|
action="append",
|
||||||
|
help="Plugin to add to vimPlugins in the form owner/repo",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--input-names",
|
"--input-names",
|
||||||
"-i",
|
"-i",
|
||||||
|
@ -500,17 +511,11 @@ class NixpkgsRepo:
|
||||||
raise Exception("Please stash changes before updating.")
|
raise Exception("Please stash changes before updating.")
|
||||||
|
|
||||||
def commit(self, message: str, files: List[Path]) -> None:
|
def commit(self, message: str, files: List[Path]) -> None:
|
||||||
file_paths = [str(f.resolve()) for f in files]
|
files_staged = self.repo.index.add([str(f.resolve()) for f in files])
|
||||||
files_changed = False
|
|
||||||
for f in self.repo.index.diff(None):
|
|
||||||
if str(f) in file_paths:
|
|
||||||
files_changed = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if files_changed:
|
if files_staged:
|
||||||
print(f'committing to nixpkgs "vimPlugins: {message}"')
|
print(f'committing to nixpkgs "{message}"')
|
||||||
self.repo.index.add(file_paths)
|
self.repo.index.commit(message)
|
||||||
self.repo.index.commit(f"vimPlugins: {message}")
|
|
||||||
assert self.is_unexpectedly_dirty() is False
|
assert self.is_unexpectedly_dirty() is False
|
||||||
else:
|
else:
|
||||||
print("no changes in working tree to commit")
|
print("no changes in working tree to commit")
|
||||||
|
@ -538,6 +543,8 @@ def update_plugins(input_file: str, outfile: str, cache: Cache) -> Dict:
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
if args.add_plugins and not args.commit:
|
||||||
|
raise Exception("The --add argument requires setting the --commit flag.")
|
||||||
if args.commit:
|
if args.commit:
|
||||||
nixpkgs_repo = NixpkgsRepo(args.allow_dirty)
|
nixpkgs_repo = NixpkgsRepo(args.allow_dirty)
|
||||||
current_plugins = get_current_plugins()
|
current_plugins = get_current_plugins()
|
||||||
|
@ -545,15 +552,26 @@ def main() -> None:
|
||||||
redirects = {}
|
redirects = {}
|
||||||
|
|
||||||
redirects = update_plugins(args.input_file, args.outfile, cache)
|
redirects = update_plugins(args.input_file, args.outfile, cache)
|
||||||
|
|
||||||
rewrite_input(args.input_file, redirects)
|
rewrite_input(args.input_file, redirects)
|
||||||
|
|
||||||
if args.commit:
|
if args.commit:
|
||||||
nixpkgs_repo.commit("Update", [args.outfile])
|
nixpkgs_repo.commit("vimPlugins: Update", [args.outfile])
|
||||||
if redirects:
|
if redirects:
|
||||||
update_plugins(args.input_file, args.outfile, cache)
|
update_plugins(args.input_file, args.outfile, cache)
|
||||||
nixpkgs_repo.commit(
|
nixpkgs_repo.commit(
|
||||||
"Update redirects", [args.outfile, args.input_file, DEPRECATED]
|
"vimPlugins: Update redirects",
|
||||||
|
[args.outfile, args.input_file, DEPRECATED],
|
||||||
|
)
|
||||||
|
for plugin_line in args.add_plugins:
|
||||||
|
rewrite_input(args.input_file, append=(plugin_line + "\n",))
|
||||||
|
update_plugins(args.input_file, args.outfile, cache)
|
||||||
|
|
||||||
|
plugin, _ = prefetch_plugin(*parse_plugin_line(plugin_line), cache)
|
||||||
|
nixpkgs_repo.commit(
|
||||||
|
"vimPlugins.{name}: init at {version}".format(
|
||||||
|
name=plugin.normalized_name, version=plugin.version
|
||||||
|
),
|
||||||
|
[args.outfile, args.input_file, OVERRIDES],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user