vimPlugins: added branch support for update.py script (#85102)
This commit is contained in:
parent
923dc61c9b
commit
4f648dfda8
|
@ -15,12 +15,14 @@ import json
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from functools import wraps
|
||||||
from multiprocessing.dummy import Pool
|
from multiprocessing.dummy import Pool
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional, Tuple, Union, Any, Callable
|
from typing import Dict, List, Optional, Tuple, Union, Any, Callable
|
||||||
|
@ -38,17 +40,12 @@ 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")
|
||||||
|
|
||||||
import time
|
|
||||||
from functools import wraps
|
|
||||||
|
|
||||||
|
|
||||||
def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: float = 2):
|
def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: float = 2):
|
||||||
"""Retry calling the decorated function using an exponential backoff.
|
"""Retry calling the decorated function using an exponential backoff.
|
||||||
|
|
||||||
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
|
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/
|
||||||
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
|
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry
|
||||||
(BSD licensed)
|
(BSD licensed)
|
||||||
|
|
||||||
:param ExceptionToCheck: the exception on which to retry
|
:param ExceptionToCheck: the exception on which to retry
|
||||||
:param tries: number of times to try (not retry) before giving up
|
:param tries: number of times to try (not retry) before giving up
|
||||||
:param delay: initial delay between retries in seconds
|
:param delay: initial delay between retries in seconds
|
||||||
|
@ -76,9 +73,12 @@ def retry(ExceptionToCheck: Any, tries: int = 4, delay: float = 3, backoff: floa
|
||||||
|
|
||||||
|
|
||||||
class Repo:
|
class Repo:
|
||||||
def __init__(self, owner: str, name: str, alias: Optional[str]) -> None:
|
def __init__(
|
||||||
|
self, owner: str, name: str, branch: str, alias: Optional[str]
|
||||||
|
) -> None:
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.branch = branch
|
||||||
self.alias = alias
|
self.alias = alias
|
||||||
self.redirect: Dict[str, str] = {}
|
self.redirect: Dict[str, str] = {}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class Repo:
|
||||||
def has_submodules(self) -> bool:
|
def has_submodules(self) -> bool:
|
||||||
try:
|
try:
|
||||||
urllib.request.urlopen(
|
urllib.request.urlopen(
|
||||||
self.url("blob/master/.gitmodules"), timeout=10
|
self.url(f"blob/{self.branch}/.gitmodules"), timeout=10
|
||||||
).close()
|
).close()
|
||||||
except urllib.error.HTTPError as e:
|
except urllib.error.HTTPError as e:
|
||||||
if e.code == 404:
|
if e.code == 404:
|
||||||
|
@ -103,7 +103,7 @@ class Repo:
|
||||||
|
|
||||||
@retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
|
@retry(urllib.error.URLError, tries=4, delay=3, backoff=2)
|
||||||
def latest_commit(self) -> Tuple[str, datetime]:
|
def latest_commit(self) -> Tuple[str, datetime]:
|
||||||
commit_url = self.url("commits/master.atom")
|
commit_url = self.url(f"commits/{self.branch}.atom")
|
||||||
with urllib.request.urlopen(commit_url, timeout=10) as req:
|
with urllib.request.urlopen(commit_url, timeout=10) as req:
|
||||||
self.check_for_redirect(commit_url, req)
|
self.check_for_redirect(commit_url, req)
|
||||||
xml = req.read()
|
xml = req.read()
|
||||||
|
@ -220,9 +220,13 @@ def get_current_plugins() -> List[Plugin]:
|
||||||
|
|
||||||
|
|
||||||
def prefetch_plugin(
|
def prefetch_plugin(
|
||||||
user: str, repo_name: str, alias: Optional[str], cache: "Optional[Cache]" = None
|
user: str,
|
||||||
|
repo_name: str,
|
||||||
|
branch: str,
|
||||||
|
alias: Optional[str],
|
||||||
|
cache: "Optional[Cache]" = None,
|
||||||
) -> Tuple[Plugin, Dict[str, str]]:
|
) -> Tuple[Plugin, Dict[str, str]]:
|
||||||
repo = Repo(user, repo_name, alias)
|
repo = Repo(user, repo_name, branch, alias)
|
||||||
commit, date = repo.latest_commit()
|
commit, date = repo.latest_commit()
|
||||||
has_submodules = repo.has_submodules()
|
has_submodules = repo.has_submodules()
|
||||||
cached_plugin = cache[commit] if cache else None
|
cached_plugin = cache[commit] if cache else None
|
||||||
|
@ -284,17 +288,20 @@ 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, Optional[str]]:
|
||||||
|
branch = "master"
|
||||||
|
alias = None
|
||||||
name, repo = line.split("/")
|
name, repo = line.split("/")
|
||||||
try:
|
if " as " in repo:
|
||||||
repo, alias = repo.split(" as ")
|
repo, alias = repo.split(" as ")
|
||||||
return (name, repo, alias.strip())
|
alias = alias.strip()
|
||||||
except ValueError:
|
if "@" in repo:
|
||||||
# no alias defined
|
repo, branch = repo.split("@")
|
||||||
return (name, repo.strip(), None)
|
|
||||||
|
return (name.strip(), repo.strip(), branch.strip(), alias)
|
||||||
|
|
||||||
|
|
||||||
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, Optional[str]]]:
|
||||||
plugins = []
|
plugins = []
|
||||||
with open(plugin_file) as f:
|
with open(plugin_file) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
@ -361,12 +368,12 @@ class Cache:
|
||||||
|
|
||||||
|
|
||||||
def prefetch(
|
def prefetch(
|
||||||
args: Tuple[str, str, str], cache: Cache
|
args: Tuple[str, str, str, Optional[str]], cache: Cache
|
||||||
) -> Tuple[str, str, Union[Exception, Plugin], dict]:
|
) -> Tuple[str, str, Union[Exception, Plugin], dict]:
|
||||||
assert len(args) == 3
|
assert len(args) == 4
|
||||||
owner, repo, alias = args
|
owner, repo, branch, alias = args
|
||||||
try:
|
try:
|
||||||
plugin, redirect = prefetch_plugin(owner, repo, alias, cache)
|
plugin, redirect = prefetch_plugin(owner, repo, branch, alias, cache)
|
||||||
cache[plugin.commit] = plugin
|
cache[plugin.commit] = plugin
|
||||||
return (owner, repo, plugin, redirect)
|
return (owner, repo, plugin, redirect)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -386,7 +393,6 @@ def generate_nix(plugins: List[Tuple[str, str, Plugin]], outfile: str):
|
||||||
f.write(
|
f.write(
|
||||||
"""
|
"""
|
||||||
{ lib, buildVimPluginFrom2Nix, fetchFromGitHub, overrides ? (self: super: {}) }:
|
{ lib, buildVimPluginFrom2Nix, fetchFromGitHub, overrides ? (self: super: {}) }:
|
||||||
|
|
||||||
let
|
let
|
||||||
packages = ( self:
|
packages = ( self:
|
||||||
{"""
|
{"""
|
||||||
|
|
Loading…
Reference in New Issue