This repository has been archived by the owner on Nov 12, 2021. It is now read-only.
/
update.py
75 lines (59 loc) · 2.02 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# coding: utf-8
"""Update already-vendored library by name."""
import sys
from pathlib import Path
from typing import Union
from .__main__ import DEFAULT_EXT_README
from ._utils import get_renovate_config
from .parse import parse_requirements
from .vendor import vendor
def update(listfile: Union[Path, str], package: str, cmd: bool, pre_releases: bool) -> None:
if not isinstance(listfile, Path):
listfile = Path(listfile)
package_lower = package.lower()
for req, error in parse_requirements(listfile):
if error:
print(str(error), file=sys.stderr)
continue
if req.name.lower() == package_lower:
break
else:
print(f'Package `{package}` not found.')
return
if not req.updatable:
print(f'Package `{package}` found, but can not be updated.')
return
requirement = req.as_update_requirement()
# Check Renovate constaints
root = listfile.parent.parent.resolve()
constraint = get_renovate_config(root).get(req.name.lower(), None)
if constraint:
requirement += str(constraint & f'>={req.version}')
req_str = f'"{requirement}"' if ' ' in requirement else requirement
listfile_str = str(listfile)
if cmd:
print(f'Vendor command for: `{req.package}`')
cmd_args = []
if pre_releases:
cmd_args.append('--pre')
if not listfile.samefile(DEFAULT_EXT_README):
cmd_args += [
'-f',
f'"{listfile_str}"' if ' ' in listfile_str else listfile_str,
]
cmd_args.append(req_str)
print(f"> mvt vendor {' '.join(cmd_args)}")
return
print(f'Running vendor command for: `{req.package}`')
print(f'mvt vendor {req_str}')
print('\n===========================================\n')
sys.stdout.flush()
vendor(
listfile=str(listfile),
package=requirement,
dependents=[],
py2=False,
py3=False,
py6=False,
pre_releases=pre_releases,
)