Skip to content

Commit c9907d2

Browse files
committed
[GR-46468] Fix patch license check
PullRequest: graalpython/2811
2 parents d50b2ff + 4b05f76 commit c9907d2

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
@@ -1876,15 +1876,20 @@ def _python_checkpatchfiles():
18761876
pypi_base_url = "https://pypi.org"
18771877
with open(listfilename, "r") as listfile:
18781878
content = listfile.read()
1879-
patchfile_pattern = re.compile(r"lib-graalpython/patches/([^/]+)/(sdist|whl)/(.*\.patch)")
1879+
patchfile_pattern = re.compile(r"lib-graalpython/patches/([^/]+)/.*?([^/]*\.patch)")
18801880
checked = {
1881+
# meson-python puts the whole license text in the field. It's MIT
1882+
'meson-python-0.12.patch',
1883+
'meson-python-0.13.patch',
18811884
# scipy puts the whole license text in the field, skip it. It's new BSD
18821885
'scipy-1.3.1.patch',
18831886
'scipy-1.4.1.patch',
18841887
'scipy-1.7.3.patch',
18851888
'scipy-1.8.1.patch',
18861889
'scipy-1.9.1.patch',
1890+
'scipy-1.9.3.patch',
18871891
'scipy-1.10.0.patch',
1892+
'scipy-1.10.1.patch',
18881893
# pandas puts the whole license text in the field. Its BSD-3-Clause
18891894
'pandas-1.4.3.patch',
18901895
'pandas-1.5.2.patch',
@@ -1893,24 +1898,38 @@ def _python_checkpatchfiles():
18931898
'setuptools-60.9.patch',
18941899
'setuptools-63.patch',
18951900
'setuptools-65.patch',
1896-
'wheel-0.33.patch',
1897-
'wheel-0.34.patch'
1901+
# Empty license field. It's MIT
1902+
'urllib3-2.patch',
1903+
# Empty license field. It's MIT
1904+
'wheel-pre-0.35.patch',
18981905
}
18991906
allowed_licenses = [
1900-
"MIT", "BSD", "BSD-3-Clause", "BSD 3-Clause License",
1901-
"BSD or Apache License, Version 2.0", "Apache License, Version 2.0",
1902-
"MIT license", "PSF", "BSD-3-Clause OR Apache-2.0", "Apache", "Apache License", "new BSD",
1903-
"(Apache-2.0 OR BSD-3-Clause) AND PSF-2.0", "Apache 2.0", "MPL-2.0", "BSD 3-Clause",
1907+
"MIT",
1908+
"BSD",
1909+
"BSD-3-Clause",
1910+
"Apache License, Version 2.0",
1911+
"PSF",
1912+
"Apache",
1913+
"new BSD",
1914+
"Apache-2.0",
1915+
"MPL-2.0",
19041916
"LGPL",
19051917
]
1918+
1919+
def as_license_regex(name):
1920+
subregex = re.escape(name).replace(r'\-', '[- ]')
1921+
return f'(?:{subregex}(?: license)?)'
1922+
1923+
allowed_licenses_regex = re.compile('|'.join(map(as_license_regex, allowed_licenses)), re.IGNORECASE)
1924+
19061925
for line in content.split("\n"):
19071926
if not line or os.stat(line).st_size == 0:
19081927
# empty files are just markers and do not need to be license checked
19091928
continue
19101929
match = patchfile_pattern.search(line)
19111930
if match:
19121931
package_name = match.group(1)
1913-
patch_name = match.group(3)
1932+
patch_name = match.group(2)
19141933
if patch_name in checked:
19151934
continue
19161935
checked.add(patch_name)
@@ -1919,12 +1938,15 @@ def _python_checkpatchfiles():
19191938
response = urllib_request.urlopen(package_url)
19201939
try:
19211940
data = json.loads(response.read())
1922-
data_license = data["info"]["license"]
1923-
if data_license not in allowed_licenses:
1924-
mx.abort(
1925-
f"The license for the original project of patch file {patch_name!r} is {data_license!r}. "
1926-
f"We cannot include a patch for it. Allowed licenses are: {allowed_licenses}"
1927-
)
1941+
license_field = data["info"]["license"]
1942+
license_field_no_parens = re.sub(r'[()]', '', license_field)
1943+
license_tokens = re.split(r' AND | OR ', license_field_no_parens)
1944+
for license_token in license_tokens:
1945+
if not allowed_licenses_regex.match(license_token):
1946+
mx.abort(
1947+
f"The license for the original project of patch file {patch_name!r} is {license_field!r}. "
1948+
f"We cannot include a patch for it. Allowed licenses are: {allowed_licenses}"
1949+
)
19281950
except Exception as e: # pylint: disable=broad-except;
19291951
mx.abort("Error getting %r.\n%r" % (package_url, e))
19301952
finally:

0 commit comments

Comments
 (0)