summaryrefslogtreecommitdiff
path: root/pavement.py
diff options
context:
space:
mode:
authorAnderson Bravalheri <andersonbravalheri@gmail.com>2021-12-21 19:32:20 +0000
committerAnderson Bravalheri <andersonbravalheri@gmail.com>2021-12-21 19:32:20 +0000
commit26b0f460817b1eb40684491daf41cae868a53696 (patch)
tree4198b969cf106f2afd18b2f099dd499a21dc189d /pavement.py
parent390016f98244e8c11d6060c3aa27efbc36db8592 (diff)
downloadpython-setuptools-git-26b0f460817b1eb40684491daf41cae868a53696.tar.gz
Change vendoring script to preserve license files
As pointed out by #2950, it is probably a good idea to keep the license files for the vendored dependencies. This is done by changing the `pavement.py` tasks.
Diffstat (limited to 'pavement.py')
-rw-r--r--pavement.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/pavement.py b/pavement.py
index 81ff6f12..1cebad79 100644
--- a/pavement.py
+++ b/pavement.py
@@ -1,6 +1,8 @@
import re
import sys
import subprocess
+from itertools import chain
+from fnmatch import fnmatch
from paver.easy import task, path as Path
@@ -52,12 +54,42 @@ def install(vendor):
'-t', str(vendor),
]
subprocess.check_call(install_args)
+ move_licenses(vendor)
remove_all(vendor.glob('*.dist-info'))
remove_all(vendor.glob('*.egg-info'))
remove_all(vendor.glob('six.py'))
(vendor / '__init__.py').write_text('')
+def move_licenses(vendor):
+ license_patterns = ("*LICEN[CS]E*", "COPYING*", "NOTICE*", "AUTHORS*")
+ licenses = (
+ entry
+ for path in chain(vendor.glob("*.dist-info"), vendor.glob("*.egg-info"))
+ for entry in path.glob("*")
+ if any(fnmatch(str(entry), p) for p in license_patterns)
+ )
+ for file in licenses:
+ file.move(_find_license_dest(file, vendor))
+
+
+def _find_license_dest(license_file, vendor):
+ basename = license_file.basename()
+ pkg = license_file.dirname().replace(".dist-info", "").replace(".egg-info", "")
+ parts = pkg.split("-")
+ acc = []
+ for part in parts:
+ acc.append(part)
+ for option in ("_".join(acc), "-".join(acc), ".".join(acc)):
+ candidate = Path(option)
+ if candidate.isdir():
+ return candidate / basename
+ if Path(f"{candidate}.py").isfile():
+ return Path(f"{candidate}.{basename}")
+
+ raise FileNotFoundError(f"No destination found for {license_file}")
+
+
def update_pkg_resources():
vendor = Path('pkg_resources/_vendor')
install(vendor)