git.iko.soy/typeable/nixpkgs
on master help sign in
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`.

commit8eb8fa153e3ac796566fbd2077360c63918c74d3 authorGalen Abell <galen@galenabell.com> dateWed 6 Nov 2019, 09:35 (7 years ago) parent873ffd8
1 file changed+24−12
pkgs/misc/vim-plugins/update.py+24−12
pkgs/misc/vim-plugins/update.py+24−12
@@ -154,13 +154,13 @@ def get_current_plugins() -> List[Plugin]:
154154 return plugins
155155
156156
157−def prefetch_plugin(user: str, repo_name: str, cache: "Cache") -> Plugin:
157+def prefetch_plugin(user: str, repo_name: str, alias: str, cache: "Cache") -> Plugin:
158158 repo = Repo(user, repo_name)
159159 commit, date = repo.latest_commit()
160160 has_submodules = repo.has_submodules()
161161 cached_plugin = cache[commit]
162162 if cached_plugin is not None:
163− cached_plugin.name = repo_name
163+ cached_plugin.name = alias or repo_name
164164 cached_plugin.date = date
165165 return cached_plugin
166166
@@ -170,7 +170,7 @@ def prefetch_plugin(user: str, repo_name: str, cache: "Cache") -> Plugin:
170170 else:
171171 sha256 = repo.prefetch_github(commit)
172172
173− return Plugin(repo_name, commit, has_submodules, sha256, date=date)
173+ return Plugin(alias or repo_name, commit, has_submodules, sha256, date=date)
174174
175175
176176def print_download_error(plugin: str, ex: Exception):
@@ -207,18 +207,30 @@ def check_results(
207207 sys.exit(1)
208208
209209
210+def parse_plugin_line(line: str) -> Tuple[str, str, str]:
211+ try:
212+ name, repo = line.split('/')
213+ try:
214+ repo, alias = repo.split(' as ')
215+ return (name, repo, alias.strip())
216+ except ValueError:
217+ # no alias defined
218+ return (name, repo.strip(), None)
219+ except ValueError:
220+ return (None, None, None)
221+
222+
210223def load_plugin_spec() -> List[Tuple[str, str]]:
211224 plugin_file = ROOT.joinpath("vim-plugin-names")
212225 plugins = []
213226 with open(plugin_file) as f:
214227 for line in f:
215− spec = line.strip()
216− parts = spec.split("/")
217− if len(parts) != 2:
218− msg = f"Invalid repository {spec}, must be in the format owner/repo"
228+ plugin = parse_plugin_line(line)
229+ if not plugin[0]:
230+ msg = f"Invalid repository {line}, must be in the format owner/repo[ as alias]"
219231 print(msg, file=sys.stderr)
220232 sys.exit(1)
221− plugins.append((parts[0], parts[1]))
233+ plugins.append(plugin)
222234 return plugins
223235
224236
@@ -276,12 +288,12 @@ class Cache:
276288
277289
278290def prefetch(
279− args: Tuple[str, str], cache: Cache
291+ args: Tuple[str, str, str], cache: Cache
280292) -> Tuple[str, str, Union[Exception, Plugin]]:
281− assert len(args) == 2
282− owner, repo = args
293+ assert len(args) == 3
294+ owner, repo, alias = args
283295 try:
284− plugin = prefetch_plugin(owner, repo, cache)
296+ plugin = prefetch_plugin(owner, repo, alias, cache)
285297 cache[plugin.commit] = plugin
286298 return (owner, repo, plugin)
287299 except Exception as e: