Skip to content

Commit 6051433

Browse files
committed
Switch to invoke
1 parent 1672d02 commit 6051433

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

pip/_vendor/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Policy
1616

1717
* Any modifications made to libraries **MUST** be noted in
1818
``pip/_vendor/README.rst`` and **MUST** be automatically applied via
19-
``tasks/re-vendor.py``.
19+
``tasks/vendoring.py``.
2020

2121

2222
Rationale
@@ -108,9 +108,9 @@ Modifications
108108
Automatic Vendoring
109109
-------------------
110110

111-
Vendoring is automated via ``tasks/re-vendor.py`` from the content of
111+
Vendoring is automated via ``tasks/vendoring.py`` from the content of
112112
``pip/_vendor/vendor.txt``. Special cases adaptation MUST be reported in the
113-
``tasks/re-vendor.py`` file.
113+
``tasks/vendoring.py`` file. Launch it via ``invoke vendoring.update``.
114114

115115

116116
Debundling

tasks/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import invoke
22

33
from . import generate
4+
from . import vendoring
45

5-
ns = invoke.Collection(generate)
6+
ns = invoke.Collection(generate, vendoring)

tasks/generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55

66
@invoke.task
7-
def authors():
7+
def authors(ctx):
88
print("[generate.authors] Generating AUTHORS")
99

1010
# Get our list of authors
1111
print("[generate.authors] Collecting author names")
12-
r = invoke.run("git log --use-mailmap --format'=%aN <%aE>'", hide=True)
12+
r = ctx.run("git log --use-mailmap --format'=%aN <%aE>'", hide=True)
1313
authors = []
1414
seen_authors = set()
1515
for author in r.stdout.splitlines():

tasks/re-vendor.py renamed to tasks/vendoring.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
from pathlib import Path
44
import re
55
import shutil
6-
import subprocess
76

8-
import pip
7+
import invoke
98

9+
TASK_NAME = 'update'
1010

1111
FILE_WHITE_LIST = (
1212
'Makefile',
@@ -104,14 +104,21 @@ def remove_all(paths):
104104
path.unlink()
105105

106106

107-
def clean_vendor(vendor_dir):
107+
def log(msg):
108+
print('[vendoring.%s] %s' % (TASK_NAME, msg))
109+
110+
111+
def clean_vendor(ctx, vendor_dir):
108112
# Old _vendor cleanup
109113
remove_all(vendor_dir.glob('*.pyc'))
114+
log('Cleaning %s' % vendor_dir)
110115
for item in vendor_dir.iterdir():
111116
if item.is_dir():
112117
shutil.rmtree(str(item))
113118
elif item.name not in FILE_WHITE_LIST:
114119
item.unlink()
120+
else:
121+
log('Skipping %s' % item)
115122

116123

117124
def rewrite_imports(package_dir, vendored_libs):
@@ -156,13 +163,13 @@ def apply_special_cases(vendor_dir, special_cases):
156163
patched_file.write_text(text)
157164

158165

159-
def vendor(vendor_dir):
160-
pip.main([
161-
'install',
162-
'-t', str(vendor_dir),
163-
'-r', str(vendor_dir / 'vendor.txt'),
164-
'--no-compile',
165-
])
166+
def vendor(ctx, vendor_dir):
167+
log('Reinstalling vendored libraries')
168+
ctx.run(
169+
'pip install -t {0} -r {0}/vendor.txt --no-compile'.format(
170+
str(vendor_dir),
171+
)
172+
)
166173
remove_all(vendor_dir.glob('*.dist-info'))
167174
remove_all(vendor_dir.glob('*.egg-info'))
168175

@@ -179,27 +186,28 @@ def vendor(vendor_dir):
179186
vendored_libs.append(item.name)
180187
elif item.name not in FILE_WHITE_LIST:
181188
vendored_libs.append(item.name[:-3])
182-
print("Vendored lib: %s" % ", ".join(vendored_libs))
189+
log("Detected vendored libraries: %s" % ", ".join(vendored_libs))
183190

184191
# Global import rewrites
192+
log("Rewriting all imports related to vendored libs")
185193
for item in vendor_dir.iterdir():
186194
if item.is_dir():
187195
rewrite_imports(item, vendored_libs)
188196
elif item.name not in FILE_WHITE_LIST:
189197
rewrite_file_imports(item, vendored_libs)
190198

191199
# Special cases
200+
log("Dealing with special cases")
192201
apply_special_cases(vendor_dir, SPECIAL_CASES)
193202

194203

195-
def main():
196-
git_root = Path(subprocess.check_output(
197-
['git', 'rev-parse', '--show-toplevel']
198-
).decode().strip())
204+
@invoke.task(name=TASK_NAME)
205+
def main(ctx):
206+
git_root = Path(
207+
ctx.run('git rev-parse --show-toplevel', hide=True).stdout.strip()
208+
)
199209
vendor_dir = git_root / 'pip' / '_vendor'
200-
clean_vendor(vendor_dir)
201-
vendor(vendor_dir)
202-
203-
204-
if __name__ == '__main__':
205-
main()
210+
log('Using vendor dir: %s' % vendor_dir)
211+
clean_vendor(ctx, vendor_dir)
212+
vendor(ctx, vendor_dir)
213+
log('Revendoring complete')

0 commit comments

Comments
 (0)