Skip to content

Commit 35141cc

Browse files
committed
Fix patch license check
1 parent 01c68e3 commit 35141cc

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

mx.graalpython/mx_graalpython.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,15 +1866,20 @@ def _python_checkpatchfiles():
18661866
pypi_base_url = "https://pypi.org"
18671867
with open(listfilename, "r") as listfile:
18681868
content = listfile.read()
1869-
patchfile_pattern = re.compile(r"lib-graalpython/patches/([^/]+)/(sdist|whl)/(.*\.patch)")
1869+
patchfile_pattern = re.compile(r"lib-graalpython/patches/([^/]+)/.*?([^/]*\.patch)")
18701870
checked = {
1871+
# meson-python puts the whole license text in the field. It's MIT
1872+
'meson-python-0.12.patch',
1873+
'meson-python-0.13.patch',
18711874
# scipy puts the whole license text in the field, skip it. It's new BSD
18721875
'scipy-1.3.1.patch',
18731876
'scipy-1.4.1.patch',
18741877
'scipy-1.7.3.patch',
18751878
'scipy-1.8.1.patch',
18761879
'scipy-1.9.1.patch',
1880+
'scipy-1.9.3.patch',
18771881
'scipy-1.10.0.patch',
1882+
'scipy-1.10.1.patch',
18781883
# pandas puts the whole license text in the field. Its BSD-3-Clause
18791884
'pandas-1.4.3.patch',
18801885
'pandas-1.5.2.patch',
@@ -1883,24 +1888,38 @@ def _python_checkpatchfiles():
18831888
'setuptools-60.9.patch',
18841889
'setuptools-63.patch',
18851890
'setuptools-65.patch',
1886-
'wheel-0.33.patch',
1887-
'wheel-0.34.patch'
1891+
# Empty license field. It's MIT
1892+
'urllib3-2.patch',
1893+
# Empty license field. It's MIT
1894+
'wheel-pre-0.35.patch',
18881895
}
18891896
allowed_licenses = [
1890-
"MIT", "BSD", "BSD-3-Clause", "BSD 3-Clause License",
1891-
"BSD or Apache License, Version 2.0", "Apache License, Version 2.0",
1892-
"MIT license", "PSF", "BSD-3-Clause OR Apache-2.0", "Apache", "Apache License", "new BSD",
1893-
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0", "Apache 2.0", "MPL-2.0", "BSD 3-Clause",
1897+
"MIT",
1898+
"BSD",
1899+
"BSD-3-Clause",
1900+
"Apache License, Version 2.0",
1901+
"PSF",
1902+
"Apache",
1903+
"new BSD",
1904+
"Apache-2.0",
1905+
"MPL-2.0",
18941906
"LGPL",
18951907
]
1908+
1909+
def as_license_regex(name):
1910+
subregex = re.escape(name).replace(r'\-', '[- ]')
1911+
return f'(?:{subregex}(?: license)?)'
1912+
1913+
allowed_licenses_regex = re.compile('|'.join(map(as_license_regex, allowed_licenses)), re.IGNORECASE)
1914+
18961915
for line in content.split("\n"):
18971916
if not line or os.stat(line).st_size == 0:
18981917
# empty files are just markers and do not need to be license checked
18991918
continue
19001919
match = patchfile_pattern.search(line)
19011920
if match:
19021921
package_name = match.group(1)
1903-
patch_name = match.group(3)
1922+
patch_name = match.group(2)
19041923
if patch_name in checked:
19051924
continue
19061925
checked.add(patch_name)
@@ -1909,12 +1928,15 @@ def _python_checkpatchfiles():
19091928
response = urllib_request.urlopen(package_url)
19101929
try:
19111930
data = json.loads(response.read())
1912-
data_license = data["info"]["license"]
1913-
if data_license not in allowed_licenses:
1914-
mx.abort(
1915-
f"The license for the original project of patch file {patch_name!r} is {data_license!r}. "
1916-
f"We cannot include a patch for it. Allowed licenses are: {allowed_licenses}"
1917-
)
1931+
license_field = data["info"]["license"]
1932+
license_field_no_parens = re.sub(r'[()]', '', license_field)
1933+
license_tokens = re.split(r' AND | OR ', license_field_no_parens)
1934+
for license_token in license_tokens:
1935+
if not allowed_licenses_regex.match(license_token):
1936+
mx.abort(
1937+
f"The license for the original project of patch file {patch_name!r} is {license_field!r}. "
1938+
f"We cannot include a patch for it. Allowed licenses are: {allowed_licenses}"
1939+
)
19181940
except Exception as e: # pylint: disable=broad-except;
19191941
mx.abort("Error getting %r.\n%r" % (package_url, e))
19201942
finally:

0 commit comments

Comments
 (0)