forked from pypa/setuptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
62 lines (47 loc) · 1.4 KB
/
pavement.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
import re
from paver.easy import task, path as Path
import pip
def remove_all(paths):
for path in paths:
path.rmtree() if path.isdir() else path.remove()
@task
def update_vendored():
update_pkg_resources()
update_setuptools()
def rewrite_packaging(pkg_files, new_root):
"""
Rewrite imports in packaging to redirect to vendored copies.
"""
for file in pkg_files.glob('*.py'):
text = file.text()
text = re.sub(r' (pyparsing|six)', rf' {new_root}.\1', text)
file.write_text(text)
def clean(vendor):
"""
Remove all files out of the vendor directory except the meta
data (as pip uninstall doesn't support -t).
"""
remove_all(
path
for path in vendor.glob('*')
if path.basename() != 'vendored.txt'
)
def install(vendor):
clean(vendor)
install_args = [
'install',
'-r', str(vendor / 'vendored.txt'),
'-t', str(vendor),
]
pip.main(install_args)
remove_all(vendor.glob('*.dist-info'))
remove_all(vendor.glob('*.egg-info'))
(vendor / '__init__.py').write_text('')
def update_pkg_resources():
vendor = Path('pkg_resources/_vendor')
install(vendor)
rewrite_packaging(vendor / 'packaging', 'pkg_resources.extern')
def update_setuptools():
vendor = Path('setuptools/_vendor')
install(vendor)
rewrite_packaging(vendor / 'packaging', 'setuptools.extern')