vimPlugins: Add alias support to update.py

Plugins in `plugin-list` can now optionally specify an alias name, to
avoid naming collisions if plugins have the same repo name. For example,
specifying `author/common-plugin as author-common-plugin` will use
`author-common-plugin` as the package name in `generated.nix`.
This commit is contained in:
Galen Abell 2019-11-06 09:35:21 +01:00 committed by Jon
parent 873ffd8d29
commit 8eb8fa153e
1 changed files with 24 additions and 12 deletions

View File

@ -154,13 +154,13 @@ def get_current_plugins() -> List[Plugin]:
return plugins return plugins
def prefetch_plugin(user: str, repo_name: str, cache: "Cache") -> Plugin: def prefetch_plugin(user: str, repo_name: str, alias: str, cache: "Cache") -> Plugin:
repo = Repo(user, repo_name) repo = Repo(user, repo_name)
commit, date = repo.latest_commit() commit, date = repo.latest_commit()
has_submodules = repo.has_submodules() has_submodules = repo.has_submodules()
cached_plugin = cache[commit] cached_plugin = cache[commit]
if cached_plugin is not None: if cached_plugin is not None:
cached_plugin.name = repo_name cached_plugin.name = alias or repo_name
cached_plugin.date = date cached_plugin.date = date
return cached_plugin return cached_plugin
@ -170,7 +170,7 @@ def prefetch_plugin(user: str, repo_name: str, cache: "Cache") -> Plugin:
else: else:
sha256 = repo.prefetch_github(commit) sha256 = repo.prefetch_github(commit)
return Plugin(repo_name, commit, has_submodules, sha256, date=date) return Plugin(alias or repo_name, commit, has_submodules, sha256, date=date)
def print_download_error(plugin: str, ex: Exception): def print_download_error(plugin: str, ex: Exception):
@ -207,18 +207,30 @@ def check_results(
sys.exit(1) sys.exit(1)
def parse_plugin_line(line: str) -> Tuple[str, str, str]:
try:
name, repo = line.split('/')
try:
repo, alias = repo.split(' as ')
return (name, repo, alias.strip())
except ValueError:
# no alias defined
return (name, repo.strip(), None)
except ValueError:
return (None, None, None)
def load_plugin_spec() -> List[Tuple[str, str]]: def load_plugin_spec() -> List[Tuple[str, str]]:
plugin_file = ROOT.joinpath("vim-plugin-names") plugin_file = ROOT.joinpath("vim-plugin-names")
plugins = [] plugins = []
with open(plugin_file) as f: with open(plugin_file) as f:
for line in f: for line in f:
spec = line.strip() plugin = parse_plugin_line(line)
parts = spec.split("/") if not plugin[0]:
if len(parts) != 2: msg = f"Invalid repository {line}, must be in the format owner/repo[ as alias]"
msg = f"Invalid repository {spec}, must be in the format owner/repo"
print(msg, file=sys.stderr) print(msg, file=sys.stderr)
sys.exit(1) sys.exit(1)
plugins.append((parts[0], parts[1])) plugins.append(plugin)
return plugins return plugins
@ -276,12 +288,12 @@ class Cache:
def prefetch( def prefetch(
args: Tuple[str, str], cache: Cache args: Tuple[str, str, str], cache: Cache
) -> Tuple[str, str, Union[Exception, Plugin]]: ) -> Tuple[str, str, Union[Exception, Plugin]]:
assert len(args) == 2 assert len(args) == 3
owner, repo = args owner, repo, alias = args
try: try:
plugin = prefetch_plugin(owner, repo, cache) plugin = prefetch_plugin(owner, repo, alias, cache)
cache[plugin.commit] = plugin cache[plugin.commit] = plugin
return (owner, repo, plugin) return (owner, repo, plugin)
except Exception as e: except Exception as e: